Skip to content

Commit

Permalink
staging: comedi: check s->async for poll(), read() and write()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: stable <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
ian-abbott authored and gregkh committed Feb 5, 2013
1 parent 4a79f73 commit cc400e1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions drivers/staging/comedi/comedi_fops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1839,15 +1839,15 @@ static unsigned int comedi_poll(struct file *file, poll_table *wait)
}

s = comedi_read_subdevice(info);
if (s) {
if (s && s->async) {
poll_wait(file, &s->async->wait_head, wait);
if (!s->busy || !comedi_is_subdevice_running(s) ||
comedi_buf_read_n_available(s->async) > 0)
mask |= POLLIN | POLLRDNORM;
}

s = comedi_write_subdevice(info);
if (s) {
if (s && s->async) {
unsigned int bps = bytes_per_sample(s->async->subdevice);

poll_wait(file, &s->async->wait_head, wait);
Expand Down Expand Up @@ -1882,7 +1882,7 @@ static ssize_t comedi_write(struct file *file, const char __user *buf,
}

s = comedi_write_subdevice(info);
if (!s)
if (!s || !s->async)
return -EIO;

async = s->async;
Expand Down Expand Up @@ -1977,7 +1977,7 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
}

s = comedi_read_subdevice(info);
if (!s)
if (!s || !s->async)
return -EIO;

async = s->async;
Expand Down

0 comments on commit cc400e1

Please sign in to comment.