* [PATCH v3 1/2] HID: sensor: custom: Fix use-after-free in enable_sensor [not found] <20260707071545.3087073-1-haoxiang_li2024@163.com> @ 2026-07-07 7:15 ` Haoxiang Li 2026-07-08 17:58 ` srinivas pandruvada 2026-08-14 13:57 ` Jiri Kosina 2026-07-07 7:15 ` [PATCH v3 2/2] HID: sensor: custom: Fix field sysfs group cleanup on failure Haoxiang Li 1 sibling, 2 replies; 5+ messages in thread From: Haoxiang Li @ 2026-07-07 7:15 UTC (permalink / raw) To: jikos, jic23, srinivas.pandruvada, bentiss Cc: linux-input, linux-iio, linux-kernel, Haoxiang Li, Sashiko AI Review, stable enable_sensor_store() can call set_power_report_state(), which dereferences sensor_inst->power_state and sensor_inst->report_state. These pointers refer to entries in sensor_inst->fields. Create the field attributes before exposing the enable_sensor sysfs attribute, so enable_sensor cannot be accessed before the state it depends on has been initialized. On remove, delete enable_sensor before freeing the field attributes, so a concurrent sysfs write cannot dereference freed memory through power_state or report_state. Reported-by: Sashiko AI Review <sashiko-bot@kernel.org> Link: https://sashiko.dev/#/patchset/20260623021950.1736413-1-haoxiang_li2024@163.com?part=1 Fixes: 4a7de0519df5 ("HID: sensor: Custom and Generic sensor support") Cc: stable@vger.kernel.org Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com> --- drivers/hid/hid-sensor-custom.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid-sensor-custom.c index afffea894021..6b0da2e0e1c9 100644 --- a/drivers/hid/hid-sensor-custom.c +++ b/drivers/hid/hid-sensor-custom.c @@ -1005,26 +1005,26 @@ static int hid_sensor_custom_probe(struct platform_device *pdev) return ret; } - ret = sysfs_create_group(&sensor_inst->pdev->dev.kobj, - &enable_sensor_attr_group); + ret = hid_sensor_custom_add_attributes(sensor_inst); if (ret) goto err_remove_callback; - ret = hid_sensor_custom_add_attributes(sensor_inst); + ret = sysfs_create_group(&sensor_inst->pdev->dev.kobj, + &enable_sensor_attr_group); if (ret) - goto err_remove_group; + goto err_remove_attributes; ret = hid_sensor_custom_dev_if_add(sensor_inst); if (ret) - goto err_remove_attributes; + goto err_remove_group; return 0; -err_remove_attributes: - hid_sensor_custom_remove_attributes(sensor_inst); err_remove_group: sysfs_remove_group(&sensor_inst->pdev->dev.kobj, &enable_sensor_attr_group); +err_remove_attributes: + hid_sensor_custom_remove_attributes(sensor_inst); err_remove_callback: sensor_hub_remove_callback(hsdev, hsdev->usage); @@ -1042,9 +1042,10 @@ static void hid_sensor_custom_remove(struct platform_device *pdev) } hid_sensor_custom_dev_if_remove(sensor_inst); - hid_sensor_custom_remove_attributes(sensor_inst); + /* Remove enable_sensor first as it uses fields via power_state/report_state. */ sysfs_remove_group(&sensor_inst->pdev->dev.kobj, &enable_sensor_attr_group); + hid_sensor_custom_remove_attributes(sensor_inst); sensor_hub_remove_callback(hsdev, hsdev->usage); } -- 2.25.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/2] HID: sensor: custom: Fix use-after-free in enable_sensor 2026-07-07 7:15 ` [PATCH v3 1/2] HID: sensor: custom: Fix use-after-free in enable_sensor Haoxiang Li @ 2026-07-08 17:58 ` srinivas pandruvada 2026-08-14 13:57 ` Jiri Kosina 1 sibling, 0 replies; 5+ messages in thread From: srinivas pandruvada @ 2026-07-08 17:58 UTC (permalink / raw) To: Haoxiang Li, jikos, jic23, bentiss Cc: linux-input, linux-iio, linux-kernel, Sashiko AI Review, stable On Tue, 2026-07-07 at 15:15 +0800, Haoxiang Li wrote: > enable_sensor_store() can call set_power_report_state(), which > dereferences sensor_inst->power_state and sensor_inst->report_state. > These pointers refer to entries in sensor_inst->fields. > > Create the field attributes before exposing the enable_sensor sysfs > attribute, so enable_sensor cannot be accessed before the state it > depends on has been initialized. > > On remove, delete enable_sensor before freeing the field attributes, > so a concurrent sysfs write cannot dereference freed memory through > power_state or report_state. > > Reported-by: Sashiko AI Review <sashiko-bot@kernel.org> > Link: > https://sashiko.dev/#/patchset/20260623021950.1736413-1-haoxiang_li2024@163.com?part=1 > Fixes: 4a7de0519df5 ("HID: sensor: Custom and Generic sensor > support") > Cc: stable@vger.kernel.org > Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com> Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> > --- > drivers/hid/hid-sensor-custom.c | 17 +++++++++-------- > 1 file changed, 9 insertions(+), 8 deletions(-) > > diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid- > sensor-custom.c > index afffea894021..6b0da2e0e1c9 100644 > --- a/drivers/hid/hid-sensor-custom.c > +++ b/drivers/hid/hid-sensor-custom.c > @@ -1005,26 +1005,26 @@ static int hid_sensor_custom_probe(struct > platform_device *pdev) > return ret; > } > > - ret = sysfs_create_group(&sensor_inst->pdev->dev.kobj, > - &enable_sensor_attr_group); > + ret = hid_sensor_custom_add_attributes(sensor_inst); > if (ret) > goto err_remove_callback; > > - ret = hid_sensor_custom_add_attributes(sensor_inst); > + ret = sysfs_create_group(&sensor_inst->pdev->dev.kobj, > + &enable_sensor_attr_group); > if (ret) > - goto err_remove_group; > + goto err_remove_attributes; > > ret = hid_sensor_custom_dev_if_add(sensor_inst); > if (ret) > - goto err_remove_attributes; > + goto err_remove_group; > > return 0; > > -err_remove_attributes: > - hid_sensor_custom_remove_attributes(sensor_inst); > err_remove_group: > sysfs_remove_group(&sensor_inst->pdev->dev.kobj, > &enable_sensor_attr_group); > +err_remove_attributes: > + hid_sensor_custom_remove_attributes(sensor_inst); > err_remove_callback: > sensor_hub_remove_callback(hsdev, hsdev->usage); > > @@ -1042,9 +1042,10 @@ static void hid_sensor_custom_remove(struct > platform_device *pdev) > } > > hid_sensor_custom_dev_if_remove(sensor_inst); > - hid_sensor_custom_remove_attributes(sensor_inst); > + /* Remove enable_sensor first as it uses fields via > power_state/report_state. */ > sysfs_remove_group(&sensor_inst->pdev->dev.kobj, > &enable_sensor_attr_group); > + hid_sensor_custom_remove_attributes(sensor_inst); > sensor_hub_remove_callback(hsdev, hsdev->usage); > } > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 1/2] HID: sensor: custom: Fix use-after-free in enable_sensor 2026-07-07 7:15 ` [PATCH v3 1/2] HID: sensor: custom: Fix use-after-free in enable_sensor Haoxiang Li 2026-07-08 17:58 ` srinivas pandruvada @ 2026-08-14 13:57 ` Jiri Kosina 1 sibling, 0 replies; 5+ messages in thread From: Jiri Kosina @ 2026-08-14 13:57 UTC (permalink / raw) To: Haoxiang Li Cc: jic23, srinivas.pandruvada, bentiss, linux-input, linux-iio, linux-kernel, Sashiko AI Review, stable On Tue, 7 Jul 2026, Haoxiang Li wrote: > enable_sensor_store() can call set_power_report_state(), which > dereferences sensor_inst->power_state and sensor_inst->report_state. > These pointers refer to entries in sensor_inst->fields. > > Create the field attributes before exposing the enable_sensor sysfs > attribute, so enable_sensor cannot be accessed before the state it > depends on has been initialized. > > On remove, delete enable_sensor before freeing the field attributes, > so a concurrent sysfs write cannot dereference freed memory through > power_state or report_state. > > Reported-by: Sashiko AI Review <sashiko-bot@kernel.org> > Link: https://sashiko.dev/#/patchset/20260623021950.1736413-1-haoxiang_li2024@163.com?part=1 > Fixes: 4a7de0519df5 ("HID: sensor: Custom and Generic sensor support") > Cc: stable@vger.kernel.org > Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com> Applied, thanks. -- Jiri Kosina SUSE Labs ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3 2/2] HID: sensor: custom: Fix field sysfs group cleanup on failure [not found] <20260707071545.3087073-1-haoxiang_li2024@163.com> 2026-07-07 7:15 ` [PATCH v3 1/2] HID: sensor: custom: Fix use-after-free in enable_sensor Haoxiang Li @ 2026-07-07 7:15 ` Haoxiang Li 2026-07-08 17:58 ` srinivas pandruvada 1 sibling, 1 reply; 5+ messages in thread From: Haoxiang Li @ 2026-07-07 7:15 UTC (permalink / raw) To: jikos, jic23, srinivas.pandruvada, bentiss Cc: linux-input, linux-iio, linux-kernel, Haoxiang Li, stable hid_sensor_custom_add_attributes() creates one sysfs group for each custom sensor field. If sysfs_create_group() fails after some groups have already been created, the function returns the error without removing the previously created groups. Add a local unwind path to remove the groups that were already created. With enable_sensor exposed only after the field attributes are ready, this path can free sensor_inst->fields without leaving enable_sensor able to access pointers into that array. Fixes: 4a7de0519df5 ("HID: sensor: Custom and Generic sensor support") Cc: stable@vger.kernel.org Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com> --- drivers/hid/hid-sensor-custom.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid-sensor-custom.c index 6b0da2e0e1c9..c2b425afd951 100644 --- a/drivers/hid/hid-sensor-custom.c +++ b/drivers/hid/hid-sensor-custom.c @@ -609,7 +609,7 @@ static int hid_sensor_custom_add_attributes(struct hid_sensor_custom &sensor_inst->fields[i]. hid_custom_attribute_group); if (ret) - break; + goto err_remove_groups; /* For power or report field store indexes */ if (sensor_inst->fields[i].attribute.attrib_id == @@ -621,6 +621,13 @@ static int hid_sensor_custom_add_attributes(struct hid_sensor_custom } return ret; + +err_remove_groups: + while (--i >= 0) + sysfs_remove_group(&sensor_inst->pdev->dev.kobj, + &sensor_inst->fields[i].hid_custom_attribute_group); + kfree(sensor_inst->fields); + return ret; } static void hid_sensor_custom_remove_attributes(struct hid_sensor_custom * -- 2.25.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3 2/2] HID: sensor: custom: Fix field sysfs group cleanup on failure 2026-07-07 7:15 ` [PATCH v3 2/2] HID: sensor: custom: Fix field sysfs group cleanup on failure Haoxiang Li @ 2026-07-08 17:58 ` srinivas pandruvada 0 siblings, 0 replies; 5+ messages in thread From: srinivas pandruvada @ 2026-07-08 17:58 UTC (permalink / raw) To: Haoxiang Li, jikos, jic23, bentiss Cc: linux-input, linux-iio, linux-kernel, stable On Tue, 2026-07-07 at 15:15 +0800, Haoxiang Li wrote: > hid_sensor_custom_add_attributes() creates one sysfs group for each > custom sensor field. If sysfs_create_group() fails after some groups > have already been created, the function returns the error without > removing the previously created groups. > > Add a local unwind path to remove the groups that were already > created. > With enable_sensor exposed only after the field attributes are ready, > this path can free sensor_inst->fields without leaving enable_sensor > able to access pointers into that array. > > Fixes: 4a7de0519df5 ("HID: sensor: Custom and Generic sensor > support") > Cc: stable@vger.kernel.org > Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com> Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> > --- > drivers/hid/hid-sensor-custom.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid- > sensor-custom.c > index 6b0da2e0e1c9..c2b425afd951 100644 > --- a/drivers/hid/hid-sensor-custom.c > +++ b/drivers/hid/hid-sensor-custom.c > @@ -609,7 +609,7 @@ static int > hid_sensor_custom_add_attributes(struct hid_sensor_custom > &sensor_inst->fields[i]. > > hid_custom_attribute_group); > if (ret) > - break; > + goto err_remove_groups; > > /* For power or report field store indexes */ > if (sensor_inst->fields[i].attribute.attrib_id == > @@ -621,6 +621,13 @@ static int > hid_sensor_custom_add_attributes(struct hid_sensor_custom > } > > return ret; > + > +err_remove_groups: > + while (--i >= 0) > + sysfs_remove_group(&sensor_inst->pdev->dev.kobj, > + &sensor_inst- > >fields[i].hid_custom_attribute_group); > + kfree(sensor_inst->fields); > + return ret; > } > > static void hid_sensor_custom_remove_attributes(struct > hid_sensor_custom * ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-08-14 13:57 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20260707071545.3087073-1-haoxiang_li2024@163.com>
2026-07-07 7:15 ` [PATCH v3 1/2] HID: sensor: custom: Fix use-after-free in enable_sensor Haoxiang Li
2026-07-08 17:58 ` srinivas pandruvada
2026-08-14 13:57 ` Jiri Kosina
2026-07-07 7:15 ` [PATCH v3 2/2] HID: sensor: custom: Fix field sysfs group cleanup on failure Haoxiang Li
2026-07-08 17:58 ` srinivas pandruvada
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox