LVS
lvs-devel
Google
 
Web LinuxVirtualServer.org

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

To: Przemek Kitszel <przemyslaw.kitszel@xxxxxxxxx>
Subject: Re: [PATCH v2 11/14] networking: Update to register_net_sysctl_sz
Cc: mcgrof@xxxxxxxxxx, Catalin Marinas <catalin.marinas@xxxxxxx>, Iurii Zaikin <yzaikin@xxxxxxxxxx>, Jozsef Kadlecsik <kadlec@xxxxxxxxxxxxx>, Sven Schnelle <svens@xxxxxxxxxxxxx>, Marcelo Ricardo Leitner <marcelo.leitner@xxxxxxxxx>, Steffen Klassert <steffen.klassert@xxxxxxxxxxx>, Kees Cook <keescook@xxxxxxxxxxxx>, "D. Wythe" <alibuda@xxxxxxxxxxxxxxxxx>, mptcp@xxxxxxxxxxxxxxx, Jakub Kicinski <kuba@xxxxxxxxxx>, Vasily Gorbik <gor@xxxxxxxxxxxxx>, Paolo Abeni <pabeni@xxxxxxxxxx>, coreteam@xxxxxxxxxxxxx, Jan Karcher <jaka@xxxxxxxxxxxxx>, Alexander Aring <alex.aring@xxxxxxxxx>, Will Deacon <will@xxxxxxxxxx>, Stefan Schmidt <stefan@xxxxxxxxxxxxxxxxxx>, Matthieu Baerts <matthieu.baerts@xxxxxxxxxxxx>, bridge@xxxxxxxxxxxxxxxxxxxxxxxxxx, linux-arm-kernel@xxxxxxxxxxxxxxxxxxx, Joerg Reuter <jreuter@xxxxxxxx>, Julian Anastasov <ja@xxxxxx>, David Ahern <dsahern@xxxxxxxxxx>, netfilter-devel@xxxxxxxxxxxxxxx, Wen Gu <guwen@xxxxxxxxxxxxxxxxx>, linux-kernel@xxxxxxxxxxxxxxx, Santosh Shilimkar <santosh.shilimkar@xxxxxxxxxx>, linux-wpan@xxxxxxxxxxxxxxx, lvs-devel@xxxxxxxxxxxxxxx, Karsten Graul <kgraul@xxxxxxxxxxxxx>, Miquel Raynal <miquel.raynal@xxxxxxxxxxx>, Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>, linux-sctp@xxxxxxxxxxxxxxx, Tony Lu <tonylu@xxxxxxxxxxxxxxxxx>, Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx>, Ralf Baechle <ralf@xxxxxxxxxxxxxx>, Florian Westphal <fw@xxxxxxxxx>, willy@xxxxxxxxxxxxx, Heiko Carstens <hca@xxxxxxxxxxxxx>, "David S. Miller" <davem@xxxxxxxxxxxxx>, linux-rdma@xxxxxxxxxxxxxxx, Roopa Prabhu <roopa@xxxxxxxxxx>, Alexander Gordeev <agordeev@xxxxxxxxxxxxx>, Simon Horman <horms@xxxxxxxxxxxx>, Mat Martineau <martineau@xxxxxxxxxx>, josh@xxxxxxxxxxxxxxxx, Christian Borntraeger <borntraeger@xxxxxxxxxxxxx>, Eric Dumazet <edumazet@xxxxxxxxxx>, linux-hams@xxxxxxxxxxxxxxx, Wenjia Zhang <wenjia@xxxxxxxxxxxxx>, linux-fsdevel@xxxxxxxxxxxxxxx, linux-s390@xxxxxxxxxxxxxxx, Xin Long <lucien.xin@xxxxxxxxx>, Nikolay Aleksandrov <razor@xxxxxxxxxxxxx>, netdev@xxxxxxxxxxxxxxx, rds-devel@xxxxxxxxxxxxxx
From: Joel Granados <joel.granados@xxxxxxxxx>
Date: Tue, 8 Aug 2023 16:24:11 +0200
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

<Prev in Thread] Current Thread [Next in Thread>