* [PATCH] [SCSI] bfa: integer overflow in debugfs
@ 2017-10-04 7:50 Dan Carpenter
2017-10-17 2:36 ` Martin K. Petersen
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2017-10-04 7:50 UTC (permalink / raw)
To: Anil Gurumurthy, Jing Huang
Cc: Sudarsana Kalluru, James E.J. Bottomley, Martin K. Petersen,
linux-scsi, kernel-janitors
We could allocate less memory than intended because we do:
bfad->regdata = kzalloc(len << 2, GFP_KERNEL);
The shift can overflow leading to a crash. This is debugfs code so the
impact is very small. I fixed the network version of this in March with
commit 13e2d5187f6b ("bna: integer overflow bug in debugfs").
Fixes: ab2a9ba189e8 ("[SCSI] bfa: add debugfs support")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/drivers/scsi/bfa/bfad_debugfs.c b/drivers/scsi/bfa/bfad_debugfs.c
index 8dcd8c70c7ee..05f523971348 100644
--- a/drivers/scsi/bfa/bfad_debugfs.c
+++ b/drivers/scsi/bfa/bfad_debugfs.c
@@ -255,7 +255,8 @@ bfad_debugfs_write_regrd(struct file *file, const char __user *buf,
struct bfad_s *bfad = port->bfad;
struct bfa_s *bfa = &bfad->bfa;
struct bfa_ioc_s *ioc = &bfa->ioc;
- int addr, len, rc, i;
+ int addr, rc, i;
+ u32 len;
u32 *regbuf;
void __iomem *rb, *reg_addr;
unsigned long flags;
@@ -266,7 +267,7 @@ bfad_debugfs_write_regrd(struct file *file, const char __user *buf,
return PTR_ERR(kern_buf);
rc = sscanf(kern_buf, "%x:%x", &addr, &len);
- if (rc < 2) {
+ if (rc < 2 || len > (UINT_MAX >> 2)) {
printk(KERN_INFO
"bfad[%d]: %s failed to read user buf\n",
bfad->inst_no, __func__);
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] [SCSI] bfa: integer overflow in debugfs
2017-10-04 7:50 [PATCH] [SCSI] bfa: integer overflow in debugfs Dan Carpenter
@ 2017-10-17 2:36 ` Martin K. Petersen
0 siblings, 0 replies; 2+ messages in thread
From: Martin K. Petersen @ 2017-10-17 2:36 UTC (permalink / raw)
To: Dan Carpenter
Cc: Anil Gurumurthy, Jing Huang, Sudarsana Kalluru,
James E.J. Bottomley, Martin K. Petersen, linux-scsi,
kernel-janitors
Dan,
> We could allocate less memory than intended because we do:
>
> bfad->regdata = kzalloc(len << 2, GFP_KERNEL);
>
> The shift can overflow leading to a crash. This is debugfs code so the
> impact is very small. I fixed the network version of this in March with
> commit 13e2d5187f6b ("bna: integer overflow bug in debugfs").
Applied to 4.15/scsi-queue. Thanks!
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-10-17 2:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-04 7:50 [PATCH] [SCSI] bfa: integer overflow in debugfs Dan Carpenter
2017-10-17 2:36 ` Martin K. Petersen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).