Эх сурвалжийг харах

iio: Return -ENODEV for file operations if the device has been unregistered

If the IIO device has been unregistered return -ENODEV for any further file
operations like read() and ioctl(). This avoids userspace being able to grab new
references to the device.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Lars-Peter Clausen 12 жил өмнө
parent
commit
f18e7a068a

+ 6 - 0
drivers/iio/industrialio-buffer.c

@@ -48,6 +48,9 @@ ssize_t iio_buffer_read_first_n_outer(struct file *filp, char __user *buf,
 	struct iio_dev *indio_dev = filp->private_data;
 	struct iio_dev *indio_dev = filp->private_data;
 	struct iio_buffer *rb = indio_dev->buffer;
 	struct iio_buffer *rb = indio_dev->buffer;
 
 
+	if (!indio_dev->info)
+		return -ENODEV;
+
 	if (!rb || !rb->access->read_first_n)
 	if (!rb || !rb->access->read_first_n)
 		return -EINVAL;
 		return -EINVAL;
 	return rb->access->read_first_n(rb, n, buf);
 	return rb->access->read_first_n(rb, n, buf);
@@ -62,6 +65,9 @@ unsigned int iio_buffer_poll(struct file *filp,
 	struct iio_dev *indio_dev = filp->private_data;
 	struct iio_dev *indio_dev = filp->private_data;
 	struct iio_buffer *rb = indio_dev->buffer;
 	struct iio_buffer *rb = indio_dev->buffer;
 
 
+	if (!indio_dev->info)
+		return -ENODEV;
+
 	poll_wait(filp, &rb->pollq, wait);
 	poll_wait(filp, &rb->pollq, wait);
 	if (rb->stufftoread)
 	if (rb->stufftoread)
 		return POLLIN | POLLRDNORM;
 		return POLLIN | POLLRDNORM;

+ 3 - 0
drivers/iio/industrialio-core.c

@@ -1040,6 +1040,9 @@ static long iio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 	int __user *ip = (int __user *)arg;
 	int __user *ip = (int __user *)arg;
 	int fd;
 	int fd;
 
 
+	if (!indio_dev->info)
+		return -ENODEV;
+
 	if (cmd == IIO_GET_EVENT_FD_IOCTL) {
 	if (cmd == IIO_GET_EVENT_FD_IOCTL) {
 		fd = iio_event_getfd(indio_dev);
 		fd = iio_event_getfd(indio_dev);
 		if (copy_to_user(ip, &fd, sizeof(fd)))
 		if (copy_to_user(ip, &fd, sizeof(fd)))

+ 6 - 0
drivers/iio/industrialio-event.c

@@ -76,6 +76,9 @@ static unsigned int iio_event_poll(struct file *filep,
 	struct iio_event_interface *ev_int = indio_dev->event_interface;
 	struct iio_event_interface *ev_int = indio_dev->event_interface;
 	unsigned int events = 0;
 	unsigned int events = 0;
 
 
+	if (!indio_dev->info)
+		return -ENODEV;
+
 	poll_wait(filep, &ev_int->wait, wait);
 	poll_wait(filep, &ev_int->wait, wait);
 
 
 	spin_lock_irq(&ev_int->wait.lock);
 	spin_lock_irq(&ev_int->wait.lock);
@@ -96,6 +99,9 @@ static ssize_t iio_event_chrdev_read(struct file *filep,
 	unsigned int copied;
 	unsigned int copied;
 	int ret;
 	int ret;
 
 
+	if (!indio_dev->info)
+		return -ENODEV;
+
 	if (count < sizeof(struct iio_event_data))
 	if (count < sizeof(struct iio_event_data))
 		return -EINVAL;
 		return -EINVAL;