Commit e384a411 authored by Dan Carpenter's avatar Dan Carpenter Committed by Greg Kroah-Hartman

Staging: comedi: integer overflow in do_insnlist_ioctl()

There is an integer overflow here that could cause memory corruption
on 32 bit systems.

insnlist.n_insns could be a very high value size calculation for
kmalloc() could overflow resulting in a smaller "insns" than
expected.  In the for (i = 0; i < insnlist.n_insns; i++) {... loop
we would read past the end of the buffer, possibly corrupting memory
as well.
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 6a9ce6b6
...@@ -670,6 +670,11 @@ static int do_insnlist_ioctl(struct comedi_device *dev, ...@@ -670,6 +670,11 @@ static int do_insnlist_ioctl(struct comedi_device *dev,
goto error; goto error;
} }
if (sizeof(struct comedi_insn) * insnlist.n_insns < insnlist.n_insns) {
ret = -EINVAL;
goto error;
}
insns = insns =
kmalloc(sizeof(struct comedi_insn) * insnlist.n_insns, GFP_KERNEL); kmalloc(sizeof(struct comedi_insn) * insnlist.n_insns, GFP_KERNEL);
if (!insns) { if (!insns) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment