lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Tue, 8 Aug 2023 16:24:11 +0200
From:   Joel Granados <joel.granados@...il.com>
To:     Przemek Kitszel <przemyslaw.kitszel@...el.com>
Cc:     mcgrof@...nel.org, Catalin Marinas <catalin.marinas@....com>,
        Iurii Zaikin <yzaikin@...gle.com>,
        Jozsef Kadlecsik <kadlec@...filter.org>,
        Sven Schnelle <svens@...ux.ibm.com>,
        Marcelo Ricardo Leitner <marcelo.leitner@...il.com>,
        Steffen Klassert <steffen.klassert@...unet.com>,
        Kees Cook <keescook@...omium.org>,
        "D. Wythe" <alibuda@...ux.alibaba.com>, mptcp@...ts.linux.dev,
        Jakub Kicinski <kuba@...nel.org>,
        Vasily Gorbik <gor@...ux.ibm.com>,
        Paolo Abeni <pabeni@...hat.com>, coreteam@...filter.org,
        Jan Karcher <jaka@...ux.ibm.com>,
        Alexander Aring <alex.aring@...il.com>,
        Will Deacon <will@...nel.org>,
        Stefan Schmidt <stefan@...enfreihafen.org>,
        Matthieu Baerts <matthieu.baerts@...sares.net>,
        bridge@...ts.linux-foundation.org,
        linux-arm-kernel@...ts.infradead.org,
        Joerg Reuter <jreuter@...na.de>, Julian Anastasov <ja@....bg>,
        David Ahern <dsahern@...nel.org>,
        netfilter-devel@...r.kernel.org, Wen Gu <guwen@...ux.alibaba.com>,
        linux-kernel@...r.kernel.org,
        Santosh Shilimkar <santosh.shilimkar@...cle.com>,
        linux-wpan@...r.kernel.org, lvs-devel@...r.kernel.org,
        Karsten Graul <kgraul@...ux.ibm.com>,
        Miquel Raynal <miquel.raynal@...tlin.com>,
        Herbert Xu <herbert@...dor.apana.org.au>,
        linux-sctp@...r.kernel.org, Tony Lu <tonylu@...ux.alibaba.com>,
        Pablo Neira Ayuso <pablo@...filter.org>,
        Ralf Baechle <ralf@...ux-mips.org>,
        Florian Westphal <fw@...len.de>, willy@...radead.org,
        Heiko Carstens <hca@...ux.ibm.com>,
        "David S. Miller" <davem@...emloft.net>,
        linux-rdma@...r.kernel.org, Roopa Prabhu <roopa@...dia.com>,
        Alexander Gordeev <agordeev@...ux.ibm.com>,
        Simon Horman <horms@...ge.net.au>,
        Mat Martineau <martineau@...nel.org>, josh@...htriplett.org,
        Christian Borntraeger <borntraeger@...ux.ibm.com>,
        Eric Dumazet <edumazet@...gle.com>, linux-hams@...r.kernel.org,
        Wenjia Zhang <wenjia@...ux.ibm.com>,
        linux-fsdevel@...r.kernel.org, linux-s390@...r.kernel.org,
        Xin Long <lucien.xin@...il.com>,
        Nikolay Aleksandrov <razor@...ckwall.org>,
        netdev@...r.kernel.org, rds-devel@....oracle.com
Subject: Re: [PATCH v2 11/14] networking: Update to register_net_sysctl_sz

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

Download attachment "signature.asc" of type "application/pgp-signature" (660 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ