On Mon, Apr 17, 2023 at 02:36:57AM +0300, Vitaliy Makkoveev wrote: > It seems rt_setsource() needs some attention, but sysctl_source() could > be called with shared netlock just now.
I think rtable_setsource() is not MP safe. It is documented as [K] kernel lock. But that is not true and makes no sense. It should be exclusive netlock. in_pcbselsrc() calls rtable_getsource() with netlock. We should rename source to ar_source so we can grep for its users. > Index: sys/net/rtsock.c > =================================================================== > RCS file: /cvs/src/sys/net/rtsock.c,v > retrieving revision 1.359 > diff -u -p -r1.359 rtsock.c > --- sys/net/rtsock.c 22 Jan 2023 12:05:44 -0000 1.359 > +++ sys/net/rtsock.c 16 Apr 2023 23:14:11 -0000 > @@ -2201,7 +2201,7 @@ sysctl_rtable(int *name, u_int namelen, > tableid = w.w_arg; > if (!rtable_exists(tableid)) > return (ENOENT); > - NET_LOCK(); > + NET_LOCK_SHARED(); > for (i = 1; i <= AF_MAX; i++) { > if (af != 0 && af != i) > continue; > @@ -2212,7 +2212,7 @@ sysctl_rtable(int *name, u_int namelen, > if (error) > break; > } > - NET_UNLOCK(); > + NET_UNLOCK_SHARED(); > break; > } > free(w.w_tmem, M_RTABLE, w.w_tmemsize);