Skip to content

Commit

Permalink
Staging: comedi: integer overflow in do_insnlist_ioctl()
Browse files Browse the repository at this point in the history
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: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Dan Carpenter authored and gregkh committed Nov 27, 2011
1 parent 6a9ce6b commit e384a41
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions drivers/staging/comedi/comedi_fops.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,11 @@ static int do_insnlist_ioctl(struct comedi_device *dev,
goto error;
}

if (sizeof(struct comedi_insn) * insnlist.n_insns < insnlist.n_insns) {
ret = -EINVAL;
goto error;
}

insns =
kmalloc(sizeof(struct comedi_insn) * insnlist.n_insns, GFP_KERNEL);
if (!insns) {
Expand Down

0 comments on commit e384a41

Please sign in to comment.