From 920715aa193c50705f643ccf834974c8933fb2bb Mon Sep 17 00:00:00 2001 From: mvs Date: Thu, 18 Jan 2024 08:48:32 +0000 Subject: [PATCH] Use solock() instead of netlock within fill_file(). This makes all socket types protected. The netlock is still used while fill_file() called through *table.inpt_queue walkthroughs, but this is the inet sockets case. ok bluhm --- sys/kern/kern_sysctl.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index 8fcf58a7a07..784ffae3fcb 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sysctl.c,v 1.422 2024/01/15 15:47:37 mvs Exp $ */ +/* $OpenBSD: kern_sysctl.c,v 1.423 2024/01/18 08:48:32 mvs Exp $ */ /* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */ /*- @@ -1283,13 +1283,8 @@ fill_file(struct kinfo_file *kf, struct file *fp, struct filedesc *fdp, if (so == NULL) { so = (struct socket *)fp->f_data; /* if so is passed as parameter it is already locked */ - switch (so->so_proto->pr_domain->dom_family) { - case AF_INET: - case AF_INET6: - NET_LOCK(); - locked = 1; - break; - } + solock(so); + locked = 1; } kf->so_type = so->so_type; @@ -1312,14 +1307,14 @@ fill_file(struct kinfo_file *kf, struct file *fp, struct filedesc *fdp, kf->so_splicelen = -1; if (so->so_pcb == NULL) { if (locked) - NET_UNLOCK(); + sounlock(so); break; } switch (kf->so_family) { case AF_INET: { struct inpcb *inpcb = so->so_pcb; - NET_ASSERT_LOCKED(); + soassertlocked(so); if (show_pointers) kf->inp_ppcb = PTRTOINT64(inpcb->inp_ppcb); kf->inp_lport = inpcb->inp_lport; @@ -1341,7 +1336,7 @@ fill_file(struct kinfo_file *kf, struct file *fp, struct filedesc *fdp, case AF_INET6: { struct inpcb *inpcb = so->so_pcb; - NET_ASSERT_LOCKED(); + soassertlocked(so); if (show_pointers) kf->inp_ppcb = PTRTOINT64(inpcb->inp_ppcb); kf->inp_lport = inpcb->inp_lport; @@ -1388,7 +1383,7 @@ fill_file(struct kinfo_file *kf, struct file *fp, struct filedesc *fdp, } } if (locked) - NET_UNLOCK(); + sounlock(so); break; } -- 2.20.1