lkml.org 
[lkml]   [2018]   [Oct]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] Change judgment len position
From
Date
On Wed, 2018-10-24 at 18:32 +0200, Willy Tarreau wrote:
> On Wed, Oct 24, 2018 at 09:23:19AM -0700, Joe Perches wrote:
> > On Wed, 2018-10-24 at 17:57 +0200, Willy Tarreau wrote:
> > > On Wed, Oct 24, 2018 at 11:47:29PM +0800, Wang Hai wrote:
> > > > To determine whether len is less than zero, it should be put before
> > > > the function min_t, because the return value of min_t is not likely
> > > > to be less than zero.
> > >
> > > Huh? First, the <0 test is made on "len", not "min_t", so it still
> > > is signed. Second, you're in fact completely removing the test here,
> > > look :
> > >
> > > > struct net *net = sock_net(sk);
> > > > int val, len;
> > > >
> > > > + len = min_t(unsigned int, len, sizeof(int));
> > > > +
> > >
> > > len is used uninitialized here, so the result is undefined.
> > >
> > > > if (get_user(len, optlen))
> > > > return -EFAULT;
> > >
> > > Then it gets overridden by get_user()
> > >
> > > > - len = min_t(unsigned int, len, sizeof(int));
> > > > -
> > >
> > > Then its positive values are not bounded anymore since you moved the test.
> >
> > Not quite.
> >
> > Problem here is negative values are tested as
> > large positive values and limited to 4
> >
> > ie:
> > ien len = -1,
> > len = min_t(unsigned int, len, sizeof(int));
> >
> > len is now 4
> >
> > > > if (len < 0)
> > > > return -EINVAL;
> >
> > So this test len < 0 could be moved up above min_t
>
> It could indeed, or we could also have min_t() done on an int instead
> of an unsigned int and this would avoid the need to shuffle the code
> around and open a huge hole like this one.

I think if the point is to test for negative numbers,
it's clearer to do that before using min_t.and it's
probably clearer not to use min_t at all.

if (get_user(len, optlen))
return -EFAULT;

if (len < 0)
return -EINVAL;

if (len > sizeof(int))
len = sizeof(int);



\
 
 \ /
  Last update: 2018-10-24 18:54    [W:0.047 / U:3.304 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site