Re: [PATCH] kernel/sysctl.c: fix out of bounds access in fs.file-max

From: Matteo Croce
Date: Thu Apr 04 2019 - 10:49:42 EST


On Thu, Apr 4, 2019 at 4:09 PM Christian Brauner <christian@xxxxxxxxxx> wrote:
>
> On Wed, Apr 03, 2019 at 07:08:47PM +0200, Matteo Croce wrote:
> > On Wed, Apr 3, 2019 at 6:40 PM Matteo Croce <mcroce@xxxxxxxxxx> wrote:
> > >
> > > On Wed, Apr 3, 2019 at 5:51 PM Matthew Wilcox <willy@xxxxxxxxxxxxx> wrote:
> > > >
> > > > On Wed, Apr 03, 2019 at 05:24:26PM +0200, Matteo Croce wrote:
> > > > > On Wed, Apr 3, 2019 at 4:02 PM Christian Brauner <christian@xxxxxxxxxx> wrote:
> > > > > > Yeah, maybe but it still feels cleaner and more obvious to just add:
> > > > > >
> > > > > > static long long_zero;
> > > > > >
> > > > > > given that most callers actually seem to want an (unsigned) int.
> > > > > >
> > > > > > I don't have a strong opinion though so if others feel that it's just a
> > > > > > waste of space consider it acked.
> > > > > >
> > > > >
> > > > > Well, given that the value is zero, in this expectional case we could
> > > > > avoid duplicating the symbol and save 4 bytes.
> > > > > What the maintainers think?
> > > >
> > > > If we care about saving four bytes, we could just pass the address of
> > > > ZERO_PAGE(0).
> > >
> > > That would work, work too, maybe it's a bit overkill.
> > > int zero is always there and it's static, so enlarging it to long
> > > should be a straightforward fix.
> > > Obviously we can't do it for other numbers, but we can alias it just
> > > for the zero case..
> > >
> > > Regards,
> > >
> > > --
> > > Matteo Croce
> > > per aspera ad upstream
> >
> > Anyway, I'm fine with both solutions, as I have other patches in the
>
> I think Matthew's idea gets us best of both worlds so I'd suggest to use
> it and resend the patch. You likely want to Cc stable@xxxxxxxxxxxxxxx
> since the original patch this fixes got backported by Greg quite a bit
> since this was a rather long-standing issue. Please also Cc Andrew this
> time since he's likely going to pick it up.
>
> Thanks for the patch!
> Christian

So you mean using page_address(ZERO_PAGE(0)) ?
The idea is nice, but since struct ctl_table kern_table is declared as
global variable, how can I assign it to the structure?
GCC complains about 'initializer element is not constant', and
ZERO_PAGE(0)->virtual only works if WANT_PAGE_VIRTUAL.

Anyway, I'm preparing a treewide patch to move all "zero", "one" and
"int_max" to three single, const variables in fs/proc/proc_sysctl.c
as there are 200+ occourrences of them, so I'd rather keep this simple
to have it easily backported to stable.

--
Matteo Croce
per aspera ad upstream