diff mbox

mptfusion: Add bounds check in mptctl_hp_targetinfo()

Message ID 20180125142727.GA23945@mwanda (mailing list archive)
State Accepted
Headers show

Commit Message

Dan Carpenter Jan. 25, 2018, 2:27 p.m. UTC
My static checker complains about an out of bounds read:

    drivers/message/fusion/mptctl.c:2786 mptctl_hp_targetinfo()
    error: buffer overflow 'hd->sel_timeout' 255 <= u32max.

It's true that we probably should have a bounds check here.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Comments

Johannes Thumshirn Jan. 29, 2018, 2:57 p.m. UTC | #1
Looks good,
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Martin K. Petersen Jan. 31, 2018, 2:32 a.m. UTC | #2
Dan,

> My static checker complains about an out of bounds read:
>
>     drivers/message/fusion/mptctl.c:2786 mptctl_hp_targetinfo()
>     error: buffer overflow 'hd->sel_timeout' 255 <= u32max.
>
> It's true that we probably should have a bounds check here.

Applied to 4.16/scsi-fixes, thanks!
diff mbox

Patch

diff --git a/drivers/message/fusion/mptctl.c b/drivers/message/fusion/mptctl.c
index 8d12017b9893..4470630dd545 100644
--- a/drivers/message/fusion/mptctl.c
+++ b/drivers/message/fusion/mptctl.c
@@ -2687,6 +2687,8 @@  mptctl_hp_targetinfo(unsigned long arg)
 				__FILE__, __LINE__, iocnum);
 		return -ENODEV;
 	}
+	if (karg.hdr.id >= MPT_MAX_FC_DEVICES)
+		return -EINVAL;
 	dctlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mptctl_hp_targetinfo called.\n",
 	    ioc->name));