svn commit: r230583 - head/sys/kern

Gleb Smirnoff glebius at FreeBSD.org
Thu Jan 26 15:36:43 UTC 2012


  Bruce,

On Thu, Jan 26, 2012 at 11:53:57PM +1100, Bruce Evans wrote:
B> > Log:
B> >  Although aio_nbytes is size_t, later is is signed to
B> >  casted types: to ssize_t in filesystem code and to
B> >  int in buf code, thus supplying a negative argument
B> >  leads to kernel panic later.
B> 
B> And supplying a large positive argument leads to undefined
B> behaviour later in the buf case.
B> 
B> > To fix that check user
B> >  supplied argument in the beginning of syscall.
B> 
B> Now, supplying a large positive argument gives implementation-
B> defined behaviour immediately.  Sometimes the implementation-
B> defined behaviour is to have no effect immediately and allow
B> a panic later.
B> 
B> > Modified: head/sys/kern/vfs_aio.c
B> > ==============================================================================
B> > --- head/sys/kern/vfs_aio.c	Thu Jan 26 11:15:12 2012	(r230582)
B> > +++ head/sys/kern/vfs_aio.c	Thu Jan 26 11:59:48 2012	(r230583)
B> > @@ -1552,6 +1552,12 @@ aio_aqueue(struct thread *td, struct aio
B> > 		return (error);
B> > 	}
B> >
B> > +	/* XXX: aio_nbytes is later casted to signed types. */
B> > +	if ((int)aiocbe->uaiocb.aio_nbytes < 0) {
B> 
B> This should avoid implementation-defined behaviour by checking if
B> 
B>  	(uncast)aiocbe->uaiocb.aio_nbytes > INT_MAX.
B> 
B> It isn't clear what the effects of the implementation-defined behaviour
B> are even when you know what it is.  It certainly results in the
B> check passing values that exceed INT_MAX.  For example, with 32-bit
B> int and 64-bit size_t, and everything 2's complement, and no perverse
B> implementation-defined behaviour like "the result of converting to
B> int when the argment exceeds INT_MAX is always 42", then
B> (int)0x10000000 is 0.

Is the attached patch okay?

-- 
Totus tuus, Glebius.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vfs_aio.c.diff
Type: text/x-diff
Size: 378 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/svn-src-head/attachments/20120126/2fd83c61/vfs_aio.c.bin


More information about the svn-src-head mailing list