All cases do the same check as first step, so merge it before the switch
and before grapping exclusive locks.
OK mvs
-/* $OpenBSD: in.c,v 1.180 2023/04/15 13:24:47 kn Exp $ */
+/* $OpenBSD: in.c,v 1.181 2023/04/18 22:20:16 kn Exp $ */
/* $NetBSD: in.c,v 1.26 1996/02/13 23:41:39 christos Exp $ */
/*
goto err;
}
+ if (!privileged) {
+ error = EPERM;
+ goto err;
+ }
+
switch (cmd) {
case SIOCSIFDSTADDR:
- if (!privileged) {
- error = EPERM;
- break;
- }
-
if ((ifp->if_flags & IFF_POINTOPOINT) == 0) {
error = EINVAL;
break;
break;
case SIOCSIFBRDADDR:
- if (!privileged) {
- error = EPERM;
- break;
- }
-
if ((ifp->if_flags & IFF_BROADCAST) == 0) {
error = EINVAL;
break;
break;
case SIOCSIFNETMASK:
- if (!privileged) {
- error = EPERM;
- break;
- }
-
if (ifr->ifr_addr.sa_len < 8) {
error = EINVAL;
break;
return (error);
}
+ if (!privileged)
+ return (EPERM);
+
KERNEL_LOCK();
NET_LOCK();
case SIOCAIFADDR: {
int needinit = 0;
- if (!privileged) {
- error = EPERM;
- break;
- }
-
if (ifra->ifra_mask.sin_len) {
if (ifra->ifra_mask.sin_len < 8) {
error = EINVAL;
break;
}
case SIOCDIFADDR:
- if (!privileged) {
- error = EPERM;
- break;
- }
-
if (ia == NULL) {
error = EADDRNOTAVAIL;
break;