Skip to contentSkip to conversation

iio: core: check 'info' value before registering the device

PATCH In review Andi Shyti 2 participants 2 messages Dec 2, 2018 – Dec 8, 2018 IIO

lore
Share & tools
lore

Andi Shyti

author
#0 lore raw

PATCH 1/1 iio: core: check 'info' value before registering the device

When the 'info' structure inside indio_dev is left uninitialized, a segmentation fault occurs.

Check the 'info' value before using it and if it is equal to NULL, return with -EINVAL.

---
 drivers/iio/industrialio-core.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/iio/industrialio-core.c +3 -0
index a062cfddc5af..4f5cd9f60870 100644
@@ -1671,6 +1671,9 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod)
 	if (ret < 0)
 		return ret;
 
+	if (!indio_dev->info)
+		return -EINVAL;
+
 	/* configure elements for the chrdev */
 	indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), indio_dev->id);
 
Signature · 1 line
2.20.0.rc1
maintainer
#1 lore raw
Quoted 7 lines · On Sun, 2 Dec 2018 20:30:31 +0200 Andi Shyti <[email protected]> wrote:

When the 'info' structure inside indio_dev is left uninitialized, a segmentation fault occurs.

Check the 'info' value before using it and if it is equal to NULL, return with -EINVAL.

Hmm. It would be an impressive level of bug if that one got through in a driver but paranoia does no harm I suppose.

Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it.

Thanks,

Jonathan

Quoted 18 lines
---
 drivers/iio/industrialio-core.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/iio/industrialio-core.c +3 -0
index a062cfddc5af..4f5cd9f60870 100644
@@ -1671,6 +1671,9 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod)
 	if (ret < 0)
 		return ret;
 
+	if (!indio_dev->info)
+		return -EINVAL;
+
 	/* configure elements for the chrdev */
 	indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), indio_dev->id);