[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20160615084031.GA5447@1wt.eu>
Date: Wed, 15 Jun 2016 10:40:31 +0200
From: Willy Tarreau <w@....eu>
To: Dave Young <dyoung@...hat.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
Heinrich Schuchardt <xypron.glpk@....de>,
Arnaldo Carvalho de Melo <acme@...hat.com>,
Kees Cook <keescook@...omium.org>,
Don Zickus <dzickus@...hat.com>,
Al Viro <viro@...iv.linux.org.uk>,
Hugh Dickins <hughd@...gle.com>,
Thomas Gleixner <tglx@...utronix.de>,
Daniel Cashman <dcashman@...gle.com>,
Alexei Starovoitov <ast@...mgrid.com>,
"Eric W. Biederman" <ebiederm@...ssion.com>,
Ilya Dryomov <idryomov@...il.com>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/1] kernel/sysctl.c: avoid overflow
On Wed, Jun 15, 2016 at 04:33:32PM +0800, Dave Young wrote:
> On 06/14/16 at 10:41pm, Willy Tarreau wrote:
> > On Tue, Jun 14, 2016 at 01:19:06PM -0700, Andrew Morton wrote:
> > > On Sat, 11 Jun 2016 03:33:08 +0200 Heinrich Schuchardt <xypron.glpk@....de> wrote:
> > >
> > > > An undetected overflow may occur in do_proc_dointvec_minmax_conv_param.
> > > >
> > > > ...
> > > >
> > > > --- a/kernel/sysctl.c
> > > > +++ b/kernel/sysctl.c
> > > > @@ -2313,7 +2313,17 @@ static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
> > > > {
> > > > struct do_proc_dointvec_minmax_conv_param *param = data;
> > > > if (write) {
> > > > - int val = *negp ? -*lvalp : *lvalp;
> > > > + int val;
> > > > +
> > > > + if (*negp) {
> > > > + if (*lvalp > (unsigned long) INT_MAX + 1)
> > > > + return -EINVAL;
> > > > + val = -*lvalp;
> > > > + } else {
> > > > + if (*lvalp > (unsigned long) INT_MAX)
> > > > + return -EINVAL;
> > > > + val = *lvalp;
> > > > + }
> > > > if ((param->min && *param->min > val) ||
> > > > (param->max && *param->max < val))
> > > > return -EINVAL;
> > >
> > > hm.
> > >
> > > What happens if someone does
> > >
> > > echo -1 > /proc/foo
> > >
> > > expecting to get 0xffffffff? That's a reasonable shorthand, and if we
> > > change that to spit out EINVAL then people's stuff may break.
> >
> > I'd go even further, I don't see anymore how it becomes possible
> > to actually *write* 0xffffffff at all! This function is used by
> > proc_dointvec_minmax() which is used with extra1=&zero and extra2
> > not set with some unsigned ints to allow the full range to be
> > configured (eg: dirty_expire_interval is the first I found by a
> > quick random look).
>
> sysctl_writes_strict use extra1 = -1 and extra2 = 1
>
> But I do not get why -1 does not work, 1 < (unsigned long) INT_MAX + 1
> so val = -1, it is still right?
-1 should indeed work but 0xffffffff will definitely not.
Willy
Powered by blists - more mailing lists