457c715
Bugzilla: 1033593
457c715
Upstream-status: 3.13
457c715
457c715
From b4789b8e6be3151a955ade74872822f30e8cd914 Mon Sep 17 00:00:00 2001
457c715
From: Mahesh Rajashekhara <Mahesh.Rajashekhara@pmcs.com>
457c715
Date: Thu, 31 Oct 2013 14:01:02 +0530
457c715
Subject: [PATCH] aacraid: prevent invalid pointer dereference
457c715
457c715
It appears that driver runs into a problem here if fibsize is too small
457c715
because we allocate user_srbcmd with fibsize size only but later we
457c715
access it until user_srbcmd->sg.count to copy it over to srbcmd.
457c715
457c715
It is not correct to test (fibsize < sizeof(*user_srbcmd)) because this
457c715
structure already includes one sg element and this is not needed for
457c715
commands without data.  So, we would recommend to add the following
457c715
(instead of test for fibsize == 0).
457c715
457c715
Signed-off-by: Mahesh Rajashekhara <Mahesh.Rajashekhara@pmcs.com>
457c715
Reported-by: Nico Golde <nico@ngolde.de>
457c715
Reported-by: Fabian Yamaguchi <fabs@goesec.de>
457c715
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
457c715
---
457c715
 drivers/scsi/aacraid/commctrl.c | 3 ++-
457c715
 1 file changed, 2 insertions(+), 1 deletion(-)
457c715
457c715
diff --git a/drivers/scsi/aacraid/commctrl.c b/drivers/scsi/aacraid/commctrl.c
457c715
index d85ac1a..fbcd48d 100644
457c715
--- a/drivers/scsi/aacraid/commctrl.c
457c715
+++ b/drivers/scsi/aacraid/commctrl.c
457c715
@@ -511,7 +511,8 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
457c715
 		goto cleanup;
457c715
 	}
457c715
 
457c715
-	if (fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr))) {
457c715
+	if ((fibsize < (sizeof(struct user_aac_srb) - sizeof(struct user_sgentry))) ||
457c715
+	    (fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)))) {
457c715
 		rcode = -EINVAL;
457c715
 		goto cleanup;
457c715
 	}
457c715
-- 
457c715
1.8.3.1
457c715