Skip to content

Commit

Permalink
aio: check for multiplication overflow in do_io_submit
Browse files Browse the repository at this point in the history
Tavis Ormandy pointed out that do_io_submit does not do proper bounds
checking on the passed-in iocb array:

       if (unlikely(nr < 0))
               return -EINVAL;

       if (unlikely(!access_ok(VERIFY_READ, iocbpp, (nr*sizeof(iocbpp)))))
               return -EFAULT;                      ^^^^^^^^^^^^^^^^^^

The attached patch checks for overflow, and if it is detected, the
number of iocbs submitted is scaled down to a number that will fit in
the long.  This is an ok thing to do, as sys_io_submit is documented as
returning the number of iocbs submitted, so callers should handle a
return value of less than the 'nr' argument passed in.

Reported-by: Tavis Ormandy <[email protected]>
Signed-off-by: Jeff Moyer <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
JeffMoyer authored and torvalds committed Sep 15, 2010
1 parent bfa88ea commit 75e1c70
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fs/aio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,9 @@ long do_io_submit(aio_context_t ctx_id, long nr,
if (unlikely(nr < 0))
return -EINVAL;

if (unlikely(nr > LONG_MAX/sizeof(*iocbpp)))
nr = LONG_MAX/sizeof(*iocbpp);

if (unlikely(!access_ok(VERIFY_READ, iocbpp, (nr*sizeof(*iocbpp)))))
return -EFAULT;

Expand Down

0 comments on commit 75e1c70

Please sign in to comment.