aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/mpt2sas/mpt2sas_ctl.c
diff options
context:
space:
mode:
authorDan Rosenberg <drosenberg@vsecurity.com>2011-04-05 12:45:59 -0400
committerJames Bottomley <James.Bottomley@suse.de>2011-04-24 12:01:59 -0400
commita1f74ae82d133ebb2aabb19d181944b4e83e9960 (patch)
tree88f1834f08d0a5def17889a40855f72bd8bd3927 /drivers/scsi/mpt2sas/mpt2sas_ctl.c
parent686c4cbb10fc0e75b29b097290b4f7fc3f010b9e (diff)
[SCSI] mpt2sas: prevent heap overflows and unchecked reads
At two points in handling device ioctls via /dev/mpt2ctl, user-supplied length values are used to copy data from userspace into heap buffers without bounds checking, allowing controllable heap corruption and subsequently privilege escalation. Additionally, user-supplied values are used to determine the size of a copy_to_user() as well as the offset into the buffer to be read, with no bounds checking, allowing users to read arbitrary kernel memory. Signed-off-by: Dan Rosenberg <drosenberg@vsecurity.com> Cc: stable@kernel.org Acked-by: Eric Moore <eric.moore@lsi.com> Signed-off-by: James Bottomley <James.Bottomley@suse.de>
Diffstat (limited to 'drivers/scsi/mpt2sas/mpt2sas_ctl.c')
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_ctl.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/drivers/scsi/mpt2sas/mpt2sas_ctl.c b/drivers/scsi/mpt2sas/mpt2sas_ctl.c
index 1c6d2b405eef..d72f1f2b1392 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_ctl.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_ctl.c
@@ -688,6 +688,13 @@ _ctl_do_mpt_command(struct MPT2SAS_ADAPTER *ioc,
688 goto out; 688 goto out;
689 } 689 }
690 690
691 /* Check for overflow and wraparound */
692 if (karg.data_sge_offset * 4 > ioc->request_sz ||
693 karg.data_sge_offset > (UINT_MAX / 4)) {
694 ret = -EINVAL;
695 goto out;
696 }
697
691 /* copy in request message frame from user */ 698 /* copy in request message frame from user */
692 if (copy_from_user(mpi_request, mf, karg.data_sge_offset*4)) { 699 if (copy_from_user(mpi_request, mf, karg.data_sge_offset*4)) {
693 printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, __LINE__, 700 printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, __LINE__,
@@ -1963,7 +1970,7 @@ _ctl_diag_read_buffer(void __user *arg, enum block_state state)
1963 Mpi2DiagBufferPostReply_t *mpi_reply; 1970 Mpi2DiagBufferPostReply_t *mpi_reply;
1964 int rc, i; 1971 int rc, i;
1965 u8 buffer_type; 1972 u8 buffer_type;
1966 unsigned long timeleft; 1973 unsigned long timeleft, request_size, copy_size;
1967 u16 smid; 1974 u16 smid;
1968 u16 ioc_status; 1975 u16 ioc_status;
1969 u8 issue_reset = 0; 1976 u8 issue_reset = 0;
@@ -1999,6 +2006,8 @@ _ctl_diag_read_buffer(void __user *arg, enum block_state state)
1999 return -ENOMEM; 2006 return -ENOMEM;
2000 } 2007 }
2001 2008
2009 request_size = ioc->diag_buffer_sz[buffer_type];
2010
2002 if ((karg.starting_offset % 4) || (karg.bytes_to_read % 4)) { 2011 if ((karg.starting_offset % 4) || (karg.bytes_to_read % 4)) {
2003 printk(MPT2SAS_ERR_FMT "%s: either the starting_offset " 2012 printk(MPT2SAS_ERR_FMT "%s: either the starting_offset "
2004 "or bytes_to_read are not 4 byte aligned\n", ioc->name, 2013 "or bytes_to_read are not 4 byte aligned\n", ioc->name,
@@ -2006,13 +2015,23 @@ _ctl_diag_read_buffer(void __user *arg, enum block_state state)
2006 return -EINVAL; 2015 return -EINVAL;
2007 } 2016 }
2008 2017
2018 if (karg.starting_offset > request_size)
2019 return -EINVAL;
2020
2009 diag_data = (void *)(request_data + karg.starting_offset); 2021 diag_data = (void *)(request_data + karg.starting_offset);
2010 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: diag_buffer(%p), " 2022 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: diag_buffer(%p), "
2011 "offset(%d), sz(%d)\n", ioc->name, __func__, 2023 "offset(%d), sz(%d)\n", ioc->name, __func__,
2012 diag_data, karg.starting_offset, karg.bytes_to_read)); 2024 diag_data, karg.starting_offset, karg.bytes_to_read));
2013 2025
2026 /* Truncate data on requests that are too large */
2027 if ((diag_data + karg.bytes_to_read < diag_data) ||
2028 (diag_data + karg.bytes_to_read > request_data + request_size))
2029 copy_size = request_size - karg.starting_offset;
2030 else
2031 copy_size = karg.bytes_to_read;
2032
2014 if (copy_to_user((void __user *)uarg->diagnostic_data, 2033 if (copy_to_user((void __user *)uarg->diagnostic_data,
2015 diag_data, karg.bytes_to_read)) { 2034 diag_data, copy_size)) {
2016 printk(MPT2SAS_ERR_FMT "%s: Unable to write " 2035 printk(MPT2SAS_ERR_FMT "%s: Unable to write "
2017 "mpt_diag_read_buffer_t data @ %p\n", ioc->name, 2036 "mpt_diag_read_buffer_t data @ %p\n", ioc->name,
2018 __func__, diag_data); 2037 __func__, diag_data);