From be2d4851d91713d246e7be24815062010ffa9479 Mon Sep 17 00:00:00 2001 From: kn Date: Tue, 8 Nov 2022 11:25:01 +0000 Subject: [PATCH] Push kernel lock down into ifioctl() This is a mechanical diff without semantical changes, locking ioctls individually inside ifioctl() rather than all of them around it. This allows us to unlock ioctls one by one. OK mpi --- sys/kern/sys_socket.c | 4 +--- sys/net/if.c | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/sys/kern/sys_socket.c b/sys/kern/sys_socket.c index e49f2910b6e..b07119b71cd 100644 --- a/sys/kern/sys_socket.c +++ b/sys/kern/sys_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sys_socket.c,v 1.54 2022/09/02 13:12:31 mvs Exp $ */ +/* $OpenBSD: sys_socket.c,v 1.55 2022/11/08 11:25:01 kn Exp $ */ /* $NetBSD: sys_socket.c,v 1.13 1995/08/12 23:59:09 mycroft Exp $ */ /* @@ -129,9 +129,7 @@ soo_ioctl(struct file *fp, u_long cmd, caddr_t data, struct proc *p) * different entry since a socket's unnecessary */ if (IOCGROUP(cmd) == 'i') { - KERNEL_LOCK(); error = ifioctl(so, cmd, data, p); - KERNEL_UNLOCK(); return (error); } if (IOCGROUP(cmd) == 'r') diff --git a/sys/net/if.c b/sys/net/if.c index 2aaab472ab9..28529df236b 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.665 2022/09/08 10:22:06 kn Exp $ */ +/* $OpenBSD: if.c,v 1.666 2022/11/08 11:25:01 kn Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -1942,19 +1942,25 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p) case SIOCIFCREATE: if ((error = suser(p)) != 0) return (error); + KERNEL_LOCK(); error = if_clone_create(ifr->ifr_name, 0); + KERNEL_UNLOCK(); return (error); case SIOCIFDESTROY: if ((error = suser(p)) != 0) return (error); + KERNEL_LOCK(); error = if_clone_destroy(ifr->ifr_name); + KERNEL_UNLOCK(); return (error); case SIOCSIFGATTR: if ((error = suser(p)) != 0) return (error); + KERNEL_LOCK(); NET_LOCK(); error = if_setgroupattribs(data); NET_UNLOCK(); + KERNEL_UNLOCK(); return (error); case SIOCGIFCONF: case SIOCIFGCLONERS: @@ -1973,12 +1979,19 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p) case SIOCGIFRDOMAIN: case SIOCGIFGROUP: case SIOCGIFLLPRIO: - return (ifioctl_get(cmd, data)); + KERNEL_LOCK(); + error = ifioctl_get(cmd, data); + KERNEL_UNLOCK(); + return (error); } + KERNEL_LOCK(); + ifp = if_unit(ifr->ifr_name); - if (ifp == NULL) + if (ifp == NULL) { + KERNEL_UNLOCK(); return (ENXIO); + } oif_flags = ifp->if_flags; oif_xflags = ifp->if_xflags; @@ -2397,6 +2410,8 @@ forceup: if (((oif_flags ^ ifp->if_flags) & IFF_UP) != 0) getmicrotime(&ifp->if_lastchange); + KERNEL_UNLOCK(); + if_put(ifp); return (error); -- 2.20.1