Re: [PATCH v5] sysctl: simplify the min/max boundary check
From: Joel Granados
Date: Thu Feb 27 2025 - 09:24:27 EST
On Thu, Jan 30, 2025 at 10:32:14PM +0800, Wen Yang wrote:
>
>
> On 2025/1/28 01:51, Eric W. Biederman wrote:
> > Joel Granados <joel.granados@xxxxxxxxxx> writes:
> >
...
> > that use extra1 or extra2 for something besides min and max. Then
> > remove extra1 and extra2. At the end it is simpler and requires the
> > same or a little less space.
> >
> > That was and remains my suggestion.
> >
>
> Thanks for your valuable suggestions. We will continue to move forward along
> it and need your more guidance.
>
> But there are also a few codes that do take the extra{1, 2} as pointers, for
> example:
>
> int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
> proc_handler *handler)
> {
> ...
> for (i = 0; i < NEIGH_VAR_GC_INTERVAL; i++) {
> t->neigh_vars[i].data += (long) p;
> t->neigh_vars[i].extra1 = dev;
> t->neigh_vars[i].extra2 = p;
> }
> ...
> }
>
> static void neigh_proc_update(const struct ctl_table *ctl, int write)
> {
> struct net_device *dev = ctl->extra1;
> struct neigh_parms *p = ctl->extra2;
> struct net *net = neigh_parms_net(p);
> int index = (int *) ctl->data - p->data;
> ...
> }
>
>
> So could we modify it in this way to make it compatible with these two
> situations:
>
> @@ -137,8 +137,16 @@ struct ctl_table {
> umode_t mode;
> proc_handler *proc_handler; /* Callback for text formatting */
> struct ctl_table_poll *poll;
> - void *extra1;
> - void *extra2;
> + union {
> + struct {
> + void *extra1;
> + void *extra2;
> + };
> + struct {
> + unsigned long min;
> + unsigned long max;
> + };
> + };
> } __randomize_layout;
I'm still not convinced that a union is the best way out of this. I have
postponed reviewing this for several weeks, but I'm slowly coming back
to it.
Thx for your suggestion
Best
--
Joel Granados