aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Abbott <abbotti@mev.co.uk>2014-10-08 11:09:14 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-10-19 22:56:17 -0400
commit6cab7a37f5c048bb2a768f24b0ec748b052fda09 (patch)
tree739e8ac9cfa938de3d2e67608151f0a57b5c5d74
parentf114040e3ea6e07372334ade75d1ee0775c355e1 (diff)
staging: comedi: (regression) channel list must be set for COMEDI_CMD ioctl
`do_cmd_ioctl()`, the handler for the `COMEDI_CMD` ioctl can incorrectly call the Comedi subdevice's `do_cmd()` handler with a NULL channel list pointer. This is a regression as the `do_cmd()` handler has never been expected to deal with that, leading to a kernel OOPS when it tries to dereference it. A NULL channel list pointer is allowed for the `COMEDI_CMDTEST` ioctl, handled by `do_cmdtest_ioctl()` and the subdevice's `do_cmdtest()` handler, but not for the `COMEDI_CMD` ioctl and its handlers. Both `do_cmd_ioctl()` and `do_cmdtest_ioctl()` call `__comedi_get_user_chanlist()` to copy the channel list from user memory into dynamically allocated kernel memory and check it for consistency. That function currently returns 0 if the `user_chanlist` parameter (pointing to the channel list in user memory) is NULL. That's fine for `do_cmdtest_ioctl()`, but `do_cmd_ioctl()` incorrectly assumes the kernel copy of the channel list has been set-up correctly. Fix it by not allowing the `user_chanlist` parameter to be NULL in `__comedi_get_user_chanlist()`, and only calling it from `do_cmdtest_ioctl()` if the parameter is non-NULL. Thanks to Bernd Porr for reporting the bug via an initial patch sent privately. Fixes: c6cd0eefb27b ("staging: comedi: comedi_fops: introduce __comedi_get_user_chanlist()") Reported-by: Bernd Porr <mail@berndporr.me.uk> Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com> Cc: Bernd Porr <mail@berndporr.me.uk> Cc: <stable@vger.kernel.org> # 3.15.y 3.16.y 3.17.y Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/staging/comedi/comedi_fops.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
index 495969f46e76..a9b7fe52d380 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -1462,10 +1462,6 @@ static int __comedi_get_user_chanlist(struct comedi_device *dev,
1462 unsigned int *chanlist; 1462 unsigned int *chanlist;
1463 int ret; 1463 int ret;
1464 1464
1465 /* user_chanlist could be NULL for do_cmdtest ioctls */
1466 if (!user_chanlist)
1467 return 0;
1468
1469 chanlist = memdup_user(user_chanlist, 1465 chanlist = memdup_user(user_chanlist,
1470 cmd->chanlist_len * sizeof(unsigned int)); 1466 cmd->chanlist_len * sizeof(unsigned int));
1471 if (IS_ERR(chanlist)) 1467 if (IS_ERR(chanlist))
@@ -1609,10 +1605,13 @@ static int do_cmdtest_ioctl(struct comedi_device *dev,
1609 1605
1610 s = &dev->subdevices[cmd.subdev]; 1606 s = &dev->subdevices[cmd.subdev];
1611 1607
1612 /* load channel/gain list */ 1608 /* user_chanlist can be NULL for COMEDI_CMDTEST ioctl */
1613 ret = __comedi_get_user_chanlist(dev, s, user_chanlist, &cmd); 1609 if (user_chanlist) {
1614 if (ret) 1610 /* load channel/gain list */
1615 return ret; 1611 ret = __comedi_get_user_chanlist(dev, s, user_chanlist, &cmd);
1612 if (ret)
1613 return ret;
1614 }
1616 1615
1617 ret = s->do_cmdtest(dev, s, &cmd); 1616 ret = s->do_cmdtest(dev, s, &cmd);
1618 1617