aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Abbott2013-02-27 04:56:19 -0600
committerGreg Kroah-Hartman2013-03-03 16:09:07 -0600
commit6c80ee53f3737993f693bf2a3b4b3e4bbde9b51f (patch)
tree49e800bee8145e169ff2342cce132316fed3e0dc
parent544da4403b05e874e134919db7124def003ef7cf (diff)
downloadkernel-common-6c80ee53f3737993f693bf2a3b4b3e4bbde9b51f.tar.gz
kernel-common-6c80ee53f3737993f693bf2a3b4b3e4bbde9b51f.tar.xz
kernel-common-6c80ee53f3737993f693bf2a3b4b3e4bbde9b51f.zip
staging: comedi: check s->async for poll(), read() and write()
commit cc400e185c07c15a42d2635995f422de5b94b696 upstream. Some low-level comedi drivers (incorrectly) point `dev->read_subdev` or `dev->write_subdev` to a subdevice that does not support asynchronous commands. Comedi's poll(), read() and write() file operation handlers assume these subdevices do support asynchronous commands. In particular, they assume `s->async` is valid (where `s` points to the read or write subdevice), which it won't be if it has been set incorrectly. This can lead to a NULL pointer dereference. Check `s->async` is non-NULL in `comedi_poll()`, `comedi_read()` and `comedi_write()` to avoid the bug. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/staging/comedi/comedi_fops.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
index 4b9d8f00328..ee33cba59a4 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -1577,7 +1577,7 @@ static unsigned int comedi_poll(struct file *file, poll_table * wait)
1577 1577
1578 mask = 0; 1578 mask = 0;
1579 read_subdev = comedi_get_read_subdevice(dev_file_info); 1579 read_subdev = comedi_get_read_subdevice(dev_file_info);
1580 if (read_subdev) { 1580 if (read_subdev && read_subdev->async) {
1581 poll_wait(file, &read_subdev->async->wait_head, wait); 1581 poll_wait(file, &read_subdev->async->wait_head, wait);
1582 if (!read_subdev->busy 1582 if (!read_subdev->busy
1583 || comedi_buf_read_n_available(read_subdev->async) > 0 1583 || comedi_buf_read_n_available(read_subdev->async) > 0
@@ -1587,7 +1587,7 @@ static unsigned int comedi_poll(struct file *file, poll_table * wait)
1587 } 1587 }
1588 } 1588 }
1589 write_subdev = comedi_get_write_subdevice(dev_file_info); 1589 write_subdev = comedi_get_write_subdevice(dev_file_info);
1590 if (write_subdev) { 1590 if (write_subdev && write_subdev->async) {
1591 poll_wait(file, &write_subdev->async->wait_head, wait); 1591 poll_wait(file, &write_subdev->async->wait_head, wait);
1592 comedi_buf_write_alloc(write_subdev->async, 1592 comedi_buf_write_alloc(write_subdev->async,
1593 write_subdev->async->prealloc_bufsz); 1593 write_subdev->async->prealloc_bufsz);
@@ -1629,7 +1629,7 @@ static ssize_t comedi_write(struct file *file, const char __user *buf,
1629 } 1629 }
1630 1630
1631 s = comedi_get_write_subdevice(dev_file_info); 1631 s = comedi_get_write_subdevice(dev_file_info);
1632 if (s == NULL) { 1632 if (s == NULL || s->async == NULL) {
1633 retval = -EIO; 1633 retval = -EIO;
1634 goto done; 1634 goto done;
1635 } 1635 }
@@ -1740,7 +1740,7 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
1740 } 1740 }
1741 1741
1742 s = comedi_get_read_subdevice(dev_file_info); 1742 s = comedi_get_read_subdevice(dev_file_info);
1743 if (s == NULL) { 1743 if (s == NULL || s->async == NULL) {
1744 retval = -EIO; 1744 retval = -EIO;
1745 goto done; 1745 goto done;
1746 } 1746 }