* [PATCH -next] iio: buffer: Check the return value of kstrdup_const()
@ 2021-10-11 12:58 Wang Wensheng
2021-10-17 13:49 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: Wang Wensheng @ 2021-10-11 12:58 UTC (permalink / raw)
To: jic23, lars, alexandru.ardelean, linux-iio, linux-kernel; +Cc: rui.xiang
We should check the duplication of attr.name properly in
iio_buffer_wrap_attr() or a null-pointer-dereference would
occur on destroying the related sysfs file.
This issue is found by fault-injection.
BUG: kernel NULL pointer dereference, address: 0000000000000000
PGD 0 P4D 0
Oops: 0000 [#1] SMP PTI
RIP: 0010:strlen+0x0/0x20
Call Trace:
kernfs_name_hash+0x1c/0xb0
kernfs_find_ns+0xc6/0x160
kernfs_remove_by_name_ns+0x5c/0xb0
remove_files.isra.1+0x42/0x90
internal_create_group+0x42f/0x460
internal_create_groups+0x49/0xc0
device_add+0xb5b/0xbe0
? kobject_get+0x90/0xa0
cdev_device_add+0x2b/0x90
__iio_device_register+0xa56/0xb40
Fixes: 15097c7a1adc ("iio: buffer: wrap all buffer attributes into iio_dev_attr")
Reported-by: Hulk Robot<hulkci@huawei.com>
Signed-off-by: Wang Wensheng <wangwensheng4@huawei.com>
---
drivers/iio/industrialio-buffer.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index c648e9553edd..f4011c477bac 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -1312,6 +1312,8 @@ static struct attribute *iio_buffer_wrap_attr(struct iio_buffer *buffer,
iio_attr->buffer = buffer;
memcpy(&iio_attr->dev_attr, dattr, sizeof(iio_attr->dev_attr));
iio_attr->dev_attr.attr.name = kstrdup_const(attr->name, GFP_KERNEL);
+ if (!iio_attr->dev_attr.attr.name)
+ return NULL;
sysfs_attr_init(&iio_attr->dev_attr.attr);
list_add(&iio_attr->l, &buffer->buffer_attr_list);
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH -next] iio: buffer: Check the return value of kstrdup_const()
2021-10-11 12:58 [PATCH -next] iio: buffer: Check the return value of kstrdup_const() Wang Wensheng
@ 2021-10-17 13:49 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2021-10-17 13:49 UTC (permalink / raw)
To: Wang Wensheng
Cc: lars, alexandru.ardelean, linux-iio, linux-kernel, rui.xiang
On Mon, 11 Oct 2021 12:58:46 +0000
Wang Wensheng <wangwensheng4@huawei.com> wrote:
> We should check the duplication of attr.name properly in
> iio_buffer_wrap_attr() or a null-pointer-dereference would
> occur on destroying the related sysfs file.
> This issue is found by fault-injection.
>
> BUG: kernel NULL pointer dereference, address: 0000000000000000
> PGD 0 P4D 0
> Oops: 0000 [#1] SMP PTI
> RIP: 0010:strlen+0x0/0x20
> Call Trace:
> kernfs_name_hash+0x1c/0xb0
> kernfs_find_ns+0xc6/0x160
> kernfs_remove_by_name_ns+0x5c/0xb0
> remove_files.isra.1+0x42/0x90
> internal_create_group+0x42f/0x460
> internal_create_groups+0x49/0xc0
> device_add+0xb5b/0xbe0
> ? kobject_get+0x90/0xa0
> cdev_device_add+0x2b/0x90
> __iio_device_register+0xa56/0xb40
>
> Fixes: 15097c7a1adc ("iio: buffer: wrap all buffer attributes into iio_dev_attr")
> Reported-by: Hulk Robot<hulkci@huawei.com>
> Signed-off-by: Wang Wensheng <wangwensheng4@huawei.com>
This version seems to be a duplicate with the version Yang Yingliang
sent a few days later, but that version has the free of the iio_attr which
is missing here.
Thanks,
Jonathan
> ---
> drivers/iio/industrialio-buffer.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
> index c648e9553edd..f4011c477bac 100644
> --- a/drivers/iio/industrialio-buffer.c
> +++ b/drivers/iio/industrialio-buffer.c
> @@ -1312,6 +1312,8 @@ static struct attribute *iio_buffer_wrap_attr(struct iio_buffer *buffer,
> iio_attr->buffer = buffer;
> memcpy(&iio_attr->dev_attr, dattr, sizeof(iio_attr->dev_attr));
> iio_attr->dev_attr.attr.name = kstrdup_const(attr->name, GFP_KERNEL);
> + if (!iio_attr->dev_attr.attr.name)
> + return NULL;
> sysfs_attr_init(&iio_attr->dev_attr.attr);
>
> list_add(&iio_attr->l, &buffer->buffer_attr_list);
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-10-17 13:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-11 12:58 [PATCH -next] iio: buffer: Check the return value of kstrdup_const() Wang Wensheng
2021-10-17 13:49 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox