Index | Thread | Search

From:
Alexander Bluhm <alexander.bluhm@gmx.net>
Subject:
Re: fill_file(): use solock() instead of netlock
To:
Vitaliy Makkoveev <mvs@openbsd.org>
Cc:
tech@openbsd.org
Date:
Wed, 17 Jan 2024 20:48:14 +0100

Download raw body.

Thread
On Wed, Jan 17, 2024 at 12:58:28PM +0300, Vitaliy Makkoveev wrote:
> 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@

> Index: sys/kern/kern_sysctl.c
> ===================================================================
> RCS file: /cvs/src/sys/kern/kern_sysctl.c,v
> retrieving revision 1.422
> diff -u -p -r1.422 kern_sysctl.c
> --- sys/kern/kern_sysctl.c	15 Jan 2024 15:47:37 -0000	1.422
> +++ sys/kern/kern_sysctl.c	17 Jan 2024 09:47:49 -0000
> @@ -1283,13 +1283,8 @@ fill_file(struct kinfo_file *kf, struct 
>  		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 
>  			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 
>  		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 
>  		    }
>  		}
>  		if (locked)
> -			NET_UNLOCK();
> +			sounlock(so);
>  		break;
>  	    }
>