mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-18 10:35:55 +00:00
Relocate permissions checking code in in_control() to before the body
of the implementation of ioctls. This makes the mapping of ioctls to specific privileges more explicit, and also simplifies the implementation by reducing the use of FALLTHROUGH handling in switch. While this is not intended to be a functional change, it does mean that certain privilege checks are now performed earlier, so EPERM might be returned in preference to EADDRNOTAVAIL for management ioctls that could have failed for both reasons. MFC after: 3 weeks
This commit is contained in:
parent
6a5f0fd39d
commit
cf7b18f15e
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=191456
@ -279,6 +279,31 @@ in_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp,
|
||||
if (ifp == NULL)
|
||||
return (EADDRNOTAVAIL);
|
||||
|
||||
/*
|
||||
* Security checks before we get involved in any work.
|
||||
*/
|
||||
switch (cmd) {
|
||||
case SIOCAIFADDR:
|
||||
case SIOCSIFADDR:
|
||||
case SIOCSIFBRDADDR:
|
||||
case SIOCSIFNETMASK:
|
||||
case SIOCSIFDSTADDR:
|
||||
if (td != NULL) {
|
||||
error = priv_check(td, PRIV_NET_ADDIFADDR);
|
||||
if (error)
|
||||
return (error);
|
||||
}
|
||||
break;
|
||||
|
||||
case SIOCDIFADDR:
|
||||
if (td != NULL) {
|
||||
error = priv_check(td, PRIV_NET_DELIFADDR);
|
||||
if (error)
|
||||
return (error);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find address for this interface, if it exists.
|
||||
*
|
||||
@ -334,13 +359,6 @@ in_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp,
|
||||
case SIOCSIFADDR:
|
||||
case SIOCSIFNETMASK:
|
||||
case SIOCSIFDSTADDR:
|
||||
if (td != NULL) {
|
||||
error = priv_check(td, (cmd == SIOCDIFADDR) ?
|
||||
PRIV_NET_DELIFADDR : PRIV_NET_ADDIFADDR);
|
||||
if (error)
|
||||
return (error);
|
||||
}
|
||||
|
||||
if (ia == NULL) {
|
||||
ia = (struct in_ifaddr *)
|
||||
malloc(sizeof *ia, M_IFADDR, M_WAITOK | M_ZERO);
|
||||
@ -376,13 +394,6 @@ in_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp,
|
||||
break;
|
||||
|
||||
case SIOCSIFBRDADDR:
|
||||
if (td != NULL) {
|
||||
error = priv_check(td, PRIV_NET_ADDIFADDR);
|
||||
if (error)
|
||||
return (error);
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
|
||||
case SIOCGIFADDR:
|
||||
case SIOCGIFNETMASK:
|
||||
case SIOCGIFDSTADDR:
|
||||
|
Loading…
Reference in New Issue
Block a user