iio: core: check 'info' value before registering the device
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.
Signed-off-by Andi Shyti <[email protected]>
--- drivers/iio/industrialio-core.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/iio/industrialio-core.c +3 -0
@@ -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
Jonathan Cameron
maintainerQuoted 7 lines · On Sun, 2 Dec 2018 20:30:31 +0200 Andi Shyti <[email protected]> wrote:
When the 'info' structure inside
indio_devis left uninitialized, a segmentation fault occurs.Check the 'info' value before using it and if it is equal to NULL, return with
-EINVAL.Signed-off-by Andi Shyti <[email protected]>
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@@ -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);