iio: core: do not create debugfs when has no dev name
PATCH 1/1 iio: core: do not create debugfs when has no dev name
I got a null-ptr-deref report when doing fault injection test:
BUG: kernel NULL pointer dereference, address: 0000000000000000 PGD 0 P4D 0 Oops: 0000 [#1] SMP KASAN PTI RIP: 0010:strlen+0x0/0x20 Call Trace: start_creating+0x199/0x2f0 debugfs_create_dir+0x25/0x430 __iio_device_register+0x4da/0x1b40 [industrialio] __devm_iio_device_register+0x22/0x80 [industrialio] max1027_probe+0x639/0x860 [max1027] spi_probe+0x183/0x210 really_probe+0x285/0xc30
If dev_set_name() fails, the dev_name() is null, add check for device name before creating debugfs.
Reported-by Hulk Robot <[email protected]>
Fixes e553f182d55b ("staging: iio: core: Introduce debugfs support...")
Signed-off-by Yang Yingliang <[email protected]>
--- drivers/iio/industrialio-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/industrialio-core.c +1 -1
@@ -466,7 +466,7 @@ static void iio_device_register_debugfs(struct iio_dev *indio_dev)if (indio_dev->info->debugfs_reg_access ==NULL )return ; -if (!iio_debugfs_dentry) +if (!iio_debugfs_dentry || !dev_name (&indio_dev->dev))return ; iio_dev_opaque =to_iio_dev_opaque (indio_dev);
Signature · 1 line
2.25.1
Quoted 15 lines · Yang Yingliang
I got a null-ptr-deref report when doing fault injection test:
BUG: kernel NULL pointer dereference, address: 0000000000000000 PGD 0 P4D 0 Oops: 0000 [#1] SMP KASAN PTI RIP: 0010:strlen+0x0/0x20 Call Trace: start_creating+0x199/0x2f0 debugfs_create_dir+0x25/0x430 __iio_device_register+0x4da/0x1b40 [industrialio] __devm_iio_device_register+0x22/0x80 [industrialio] max1027_probe+0x639/0x860 [max1027] spi_probe+0x183/0x210 really_probe+0x285/0xc30
Quoted 2 lines
If
dev_set_name()fails, thedev_name()is null, add check for device name before creating debugfs.
If dev_set_name() fails, shouldn't we better return an error in iio_device_alloc()? Otherwise the device has no name and will show up as <null> in sysfs.
Quoted 21 lines
Reported-by Hulk Robot <[email protected]>Fixes e553f182d55b ("staging: iio: core: Introduce debugfs support...")Signed-off-by Yang Yingliang <[email protected]>--- drivers/iio/industrialio-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/industrialio-core.c +1
-1@@ -466,7 +466,7 @@ static void iio_device_register_debugfs(struct iio_dev *indio_dev)if (indio_dev->info->debugfs_reg_access ==NULL )return ; -if (!iio_debugfs_dentry) +if (!iio_debugfs_dentry || !dev_name (&indio_dev->dev))return ; iio_dev_opaque =to_iio_dev_opaque (indio_dev);