[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200520013949.GV11244@42.do-not-panic.com>
Date: Wed, 20 May 2020 01:39:49 +0000
From: Luis Chamberlain <mcgrof@...nel.org>
To: Xiaoming Ni <nixiaoming@...wei.com>
Cc: Tetsuo Handa <penguin-kernel@...ove.sakura.ne.jp>,
keescook@...omium.org, yzaikin@...gle.com, adobriyan@...il.com,
mingo@...nel.org, gpiccoli@...onical.com, rdna@...com,
patrick.bellasi@....com, sfr@...b.auug.org.au,
akpm@...ux-foundation.org, mhocko@...e.com, vbabka@...e.cz,
tglx@...utronix.de, peterz@...radead.org,
Jisheng.Zhang@...aptics.com, khlebnikov@...dex-team.ru,
bigeasy@...utronix.de, pmladek@...e.com,
linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org,
wangle6@...wei.com, alex.huangjianhui@...wei.com
Subject: Re: [PATCH v4 2/4] sysctl: Move some boundary constants form
sysctl.c to sysctl_vals
On Wed, May 20, 2020 at 09:14:08AM +0800, Xiaoming Ni wrote:
> On 2020/5/19 12:44, Tetsuo Handa wrote:
> > On 2020/05/19 12:31, Xiaoming Ni wrote:
> > > Some boundary (.extra1 .extra2) constants (E.g: neg_one two) in
> > > sysctl.c are used in multiple features. Move these variables to
> > > sysctl_vals to avoid adding duplicate variables when cleaning up
> > > sysctls table.
> > >
> > > Signed-off-by: Xiaoming Ni <nixiaoming@...wei.com>
> > > Reviewed-by: Kees Cook <keescook@...omium.org>
> >
> > I feel that it is use of
> >
> > void *extra1;
> > void *extra2;
> >
> > in "struct ctl_table" that requires constant values indirection.
> > Can't we get rid of sysctl_vals using some "union" like below?
> >
> > struct ctl_table {
> > const char *procname; /* Text ID for /proc/sys, or zero */
> > void *data;
> > int maxlen;
> > umode_t mode;
> > struct ctl_table *child; /* Deprecated */
> > proc_handler *proc_handler; /* Callback for text formatting */
> > struct ctl_table_poll *poll;
> > union {
> > void *min_max_ptr[2];
> > int min_max_int[2];
> > long min_max_long[2];
> > };
> > } __randomize_layout;
> >
> > .
> >
>
> net/decnet/dn_dev.c:
> static void dn_dev_sysctl_register(struct net_device *dev, struct
> dn_dev_parms *parms)
> {
> struct dn_dev_sysctl_table *t;
> int i;
>
> char path[sizeof("net/decnet/conf/") + IFNAMSIZ];
>
> t = kmemdup(&dn_dev_sysctl, sizeof(*t), GFP_KERNEL);
> if (t == NULL)
> return;
>
> for(i = 0; i < ARRAY_SIZE(t->dn_dev_vars) - 1; i++) {
> long offset = (long)t->dn_dev_vars[i].data;
> t->dn_dev_vars[i].data = ((char *)parms) + offset;
> }
>
> snprintf(path, sizeof(path), "net/decnet/conf/%s",
> dev? dev->name : parms->name);
>
> t->dn_dev_vars[0].extra1 = (void *)dev;
>
> t->sysctl_header = register_net_sysctl(&init_net, path, t->dn_dev_vars);
> if (t->sysctl_header == NULL)
> kfree(t);
> else
> parms->sysctl = t;
> }
>
> A small amount of code is not used as a boundary value when using extra1.
> This scenario may not be suitable for renaming to min_max_ptr.
>
> Should we add const to extra1 extra2 ?
>
> --- a/include/linux/sysctl.h
> +++ b/include/linux/sysctl.h
> @@ -124,8 +124,8 @@ struct ctl_table {
> struct ctl_table *child; /* Deprecated */
> proc_handler *proc_handler; /* Callback for text formatting */
> struct ctl_table_poll *poll;
> - void *extra1;
> - void *extra2;
> + const void *extra1;
> + const void *extra2;
> } __randomize_layout;
Do that, compile an allyesconfig and it'll fail, but if you fix the
callers so that they use a const, then yes. That would cover only your
architecture. It is unclear if we ever used non-const for this on purpose.
Luis
Powered by blists - more mailing lists