Re: [PATCH v2 11/14] networking: Update to register_net_sysctl_sz

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Aug 08, 2023 at 01:20:36PM +0200, Przemek Kitszel wrote:
> On 7/31/23 09:17, Joel Granados wrote:
> > Move from register_net_sysctl to register_net_sysctl_sz for all the
> > networking related files. Do this while making sure to mirror the NULL
> > assignments with a table_size of zero for the unprivileged users.
> > 
...
> >   	const char *dev_name_source;
> >   	char neigh_path[ sizeof("net//neigh/") + IFNAMSIZ + IFNAMSIZ ];
> >   	char *p_name;
> > +	size_t neigh_vars_size;
> >   	t = kmemdup(&neigh_sysctl_template, sizeof(*t), GFP_KERNEL_ACCOUNT);
> >   	if (!t)
> > @@ -3790,11 +3791,13 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
> >   		t->neigh_vars[i].extra2 = p;
> >   	}
> > +	neigh_vars_size = ARRAY_SIZE(t->neigh_vars);
> >   	if (dev) {
> >   		dev_name_source = dev->name;
> >   		/* Terminate the table early */
> >   		memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
> >   		       sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
> > +		neigh_vars_size = NEIGH_VAR_BASE_REACHABLE_TIME_MS;
> 
> %NEIGH_VAR_BASE_REACHABLE_TIME_MS is last usable index here, and since those
> are 0 based, size is one more, %NEIGH_VAR_GC_INTERVAL.
> (spelling it "NEIGH_VAR_BASE_REACHABLE_TIME_MS+1" would be perhaps better?)
This is a very good catch. Thx for this!! I'll correct here and double
check all the other places where I'm trying to replace the memset with a
enumeration element. Just to make sure that I don't have an "off by one"
like the one here.

> 
> >   	} else {
> >   		struct neigh_table *tbl = p->tbl;
> >   		dev_name_source = "default";
> > @@ -3841,8 +3844,9 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
> >   	snprintf(neigh_path, sizeof(neigh_path), "net/%s/neigh/%s",
> >   		p_name, dev_name_source);
> > -	t->sysctl_header =
> > -		register_net_sysctl(neigh_parms_net(p), neigh_path, t->neigh_vars);
> > +	t->sysctl_header = register_net_sysctl_sz(neigh_parms_net(p),
> > +						  neigh_path, t->neigh_vars,
> > +						  neigh_vars_size);
> >   	if (!t->sysctl_header)
> >   		goto free;
> > diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
> > index 782273bb93c2..03f1edb948d7 100644

...

> >   {
> >   	struct ctl_table *table;
> > +	size_t table_size = ARRAY_SIZE(xfrm_table);
> >   	__xfrm_sysctl_init(net);
> > @@ -56,10 +57,13 @@ int __net_init xfrm_sysctl_init(struct net *net)
> >   	table[3].data = &net->xfrm.sysctl_acq_expires;
> >   	/* Don't export sysctls to unprivileged users */
> > -	if (net->user_ns != &init_user_ns)
> > +	if (net->user_ns != &init_user_ns) {
> >   		table[0].procname = NULL;
> 
> do we still have to set procname to NULL, even if passed size is 0?
> (same thing for all earlier occurences)
Yes, we still need to set the procname to NULL in this patchest!. We are
introducing the ARRAY_SIZE but not actually using it (not yet). Keeping
the "procname == NULL" stopping criteria allows us to keep the current
behavior while we introduce the size in the background. We will start
using the patchset in the upcoming patchsets.

> 
> > +		table_size = 0;
> > +	}
> > -	net->xfrm.sysctl_hdr = register_net_sysctl(net, "net/core", table);
> > +	net->xfrm.sysctl_hdr = register_net_sysctl_sz(net, "net/core", table,
> > +						      table_size);
> >   	if (!net->xfrm.sysctl_hdr)
> >   		goto out_register;
> >   	return 0;
> 
> overall this patch looks sane, and whole series looks very promissing,
> thanks

Thx for the feedback

Best

-- 

Joel Granados

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux Filesystem Devel]     [Linux NFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]     [X.Org]

  Powered by Linux