Kyle McMartin 159f2c
From be18992d0630149403bfae5882601cf01a7d4eea Mon Sep 17 00:00:00 2001
Kyle McMartin 278c1a
From: Jeff Moyer <jmoyer@redhat.com>
Kyle McMartin 278c1a
Date: Fri, 10 Sep 2010 14:16:00 -0700
Kyle McMartin 159f2c
Subject: [PATCH 4/4] aio: check for multiplication overflow in do_io_submit
Kyle McMartin 278c1a
MIME-Version: 1.0
Kyle McMartin 159f2c
Content-Type: text/plain; charset=UTF-8
Kyle McMartin 278c1a
Content-Transfer-Encoding: 8bit
Kyle McMartin 278c1a
Kyle McMartin 278c1a
Tavis Ormandy pointed out that do_io_submit does not do proper bounds
Kyle McMartin 278c1a
checking on the passed-in iocb array:
Kyle McMartin 278c1a
Kyle McMartin 159f2c
       if (unlikely(nr < 0))
Kyle McMartin 159f2c
               return -EINVAL;
Kyle McMartin 278c1a
Kyle McMartin 159f2c
       if (unlikely(!access_ok(VERIFY_READ, iocbpp, (nr*sizeof(iocbpp)))))
Kyle McMartin 159f2c
               return -EFAULT;                      ^^^^^^^^^^^^^^^^^^
Kyle McMartin 278c1a
Kyle McMartin 278c1a
The attached patch checks for overflow, and if it is detected, the
Kyle McMartin 278c1a
number of iocbs submitted is scaled down to a number that will fit in
Kyle McMartin 159f2c
the long.  This is an ok thing to do, as sys_io_submit is documented as
Kyle McMartin 278c1a
returning the number of iocbs submitted, so callers should handle a
Kyle McMartin 278c1a
return value of less than the 'nr' argument passed in.
Kyle McMartin 278c1a
Kyle McMartin 278c1a
Reported-by: Tavis Ormandy <taviso@cmpxchg8b.com>
Kyle McMartin 278c1a
Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
Kyle McMartin 278c1a
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Kyle McMartin 278c1a
---
Kyle McMartin 278c1a
 fs/aio.c |    3 +++
Kyle McMartin 278c1a
 1 files changed, 3 insertions(+), 0 deletions(-)
Kyle McMartin 278c1a
Kyle McMartin 278c1a
diff --git a/fs/aio.c b/fs/aio.c
Kyle McMartin 159f2c
index 02a2c93..b84a769 100644
Kyle McMartin 278c1a
--- a/fs/aio.c
Kyle McMartin 278c1a
+++ b/fs/aio.c
Kyle McMartin 159f2c
@@ -1639,6 +1639,9 @@ SYSCALL_DEFINE3(io_submit, aio_context_t, ctx_id, long, nr,
Kyle McMartin 278c1a
 	if (unlikely(nr < 0))
Kyle McMartin 278c1a
 		return -EINVAL;
Kyle McMartin 278c1a
 
Kyle McMartin 278c1a
+	if (unlikely(nr > LONG_MAX/sizeof(*iocbpp)))
Kyle McMartin 278c1a
+		nr = LONG_MAX/sizeof(*iocbpp);
Kyle McMartin 278c1a
+
Kyle McMartin 278c1a
 	if (unlikely(!access_ok(VERIFY_READ, iocbpp, (nr*sizeof(*iocbpp)))))
Kyle McMartin 278c1a
 		return -EFAULT;
Kyle McMartin 278c1a
 
Kyle McMartin 278c1a
-- 
Kyle McMartin 278c1a
1.7.2.3
Kyle McMartin 278c1a