On Wed, May 17, 2023 at 01:08:52PM +0300, Vitaliy Makkoveev wrote:
> Also read-only access to netlock protected data.
>
Regardless on sysctl(2) unlocking backout, the netlock around
mrt_sysctl_vif() could be relaxed to shared netlock.
> Index: sys/netinet/ip_input.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet/ip_input.c,v
> retrieving revision 1.384
> diff -u -p -r1.384 ip_input.c
> --- sys/netinet/ip_input.c 16 May 2023 19:36:00 -0000 1.384
> +++ sys/netinet/ip_input.c 17 May 2023 10:06:49 -0000
> @@ -1719,10 +1719,7 @@ ip_sysctl(int *name, u_int namelen, void
> case IPCTL_MRTVIF:
> if (newp)
> return (EPERM);
> - NET_LOCK();
> - error = mrt_sysctl_vif(oldp, oldlenp);
> - NET_UNLOCK();
> - return (error);
> + return (mrt_sysctl_vif(oldp, oldlenp));
> #else
> case IPCTL_MRTPROTO:
> case IPCTL_MRTSTATS:
> Index: sys/netinet/ip_mroute.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet/ip_mroute.c,v
> retrieving revision 1.138
> diff -u -p -r1.138 ip_mroute.c
> --- sys/netinet/ip_mroute.c 19 Apr 2023 20:03:51 -0000 1.138
> +++ sys/netinet/ip_mroute.c 17 May 2023 10:06:49 -0000
> @@ -356,6 +356,8 @@ mrt_sysctl_vif(void *oldp, size_t *oldle
> given = *oldlenp;
> needed = 0;
> memset(&vinfo, 0, sizeof vinfo);
> +
> + NET_LOCK_SHARED();
> TAILQ_FOREACH(ifp, &ifnetlist, if_list) {
> if ((vifp = (struct vif *)ifp->if_mcast) == NULL)
> continue;
> @@ -375,11 +377,15 @@ mrt_sysctl_vif(void *oldp, size_t *oldle
> int error;
>
> error = copyout(&vinfo, where, sizeof(vinfo));
> - if (error)
> + if (error) {
> + NET_UNLOCK_SHARED();
> return (error);
> + }
> where += sizeof(vinfo);
> }
> }
> + NET_UNLOCK_SHARED();
> +
> if (where) {
> *oldlenp = needed;
> if (given < needed)
>