Skip to content

Commit

Permalink
Staging: bcm: Fix an invalid dereference to a kmalloc in IOCTL_BCM_BU…
Browse files Browse the repository at this point in the history
…LK_WRM

Variable IoBuffer.InputLength is chosen from userspace,
and can therefore be less than the intended size. In this
case,the memory from the kmalloc call is eventually cast
to a PBULKWRM_BUFFER. If the IoBuffer.InputLength does not
meet the minimum size of PBULKWRM_BUFFER, then we will get
a kernel Oops. To resolve this issue, this patch verifies
IoBuffer.InputLength meets the minimum size before invoking
the kmalloc call.

Signed-off-by: Kevin McKinney <klmckinney1@gmail.com>
Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Kevin McKinney authored and Greg Kroah-Hartman committed Dec 22, 2011
1 parent b72a7c8 commit 221fd75
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/staging/bcm/Bcmchar.c
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,9 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
return -EFAULT;

/* FIXME: restrict length */
if (IoBuffer.InputLength < sizeof(ULONG) * 2)
return -EINVAL;

pvBuffer = kmalloc(IoBuffer.InputLength, GFP_KERNEL);
if (!pvBuffer)
return -ENOMEM;
Expand Down

0 comments on commit 221fd75

Please sign in to comment.