Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Dmitry Torokhov" <dmitry.torokhov@gmail.com>
Cc: linux-input@vger.kernel.org
Subject: Re: [PATCH v3 06/18] HID: logitech-hidpp: manage G920 range sysfs attribute via dev_groups
Date: Fri, 20 Nov 2026 09:00:25 +0000	[thread overview]
Message-ID: <sashiko-outbox-224807@kernel.org> (raw)
In-Reply-To: <20261120-hid-logitech-hidpp-next-v3-6-ba39242d4336@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] HID: logitech-hidpp: use-after-free of hidpp and g920 in
  hidpp_ff_destroy()
--

commit 747c5a1e9f12f8c0a286b46681fccb7f3876f83a
Author: Dmitry Torokhov <dmitry.torokhov@gmail.com>

HID: logitech-hidpp: manage G920 range sysfs attribute via dev_groups

This commit replaces manual creation and removal of the G920 range sysfs
attribute with a driver dev_groups attribute group using an is_visible
callback.

> diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
> index 58f7cf84b9951..1376d5bc3fbbb 100644
> --- a/drivers/hid/hid-logitech-hidpp.c
> +++ b/drivers/hid/hid-logitech-hidpp.c
> @@ -2752,16 +2752,47 @@ static ssize_t hidpp_ff_range_store(struct device *dev, struct device_attribute
>  
>  static DEVICE_ATTR(range, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH, hidpp_ff_range_show, hidpp_ff_range_store);
>  
> +static struct attribute *g920_range_attrs[] = {
> +	&dev_attr_range.attr,
> +	NULL
> +};
> +
> +static umode_t g920_range_attr_is_visible(struct kobject *kobj,
> +					  struct attribute *attr, int idx)
> +{
> +	struct device *dev = kobj_to_dev(kobj);
> +	struct hid_device *hdev = to_hid_device(dev);
> +	struct hidpp_device *hidpp = hid_get_drvdata(hdev);
> +	struct g920_data *g920;
> +
> +	if (!hidpp || !(hidpp->quirks & HIDPP_QUIRK_CLASS_G920))
> +		return 0;
> +
> +	g920 = hidpp->private_data;
> +	if (!g920 || !g920->ff)
> +		return 0;
> +
> +	return attr->mode;
> +}
> +
> +static const struct attribute_group g920_range_group = {
> +	.attrs = g920_range_attrs,
> +	.is_visible = g920_range_attr_is_visible,
> +};
> +
> +static const struct attribute_group *hidpp_dev_groups[] = {
> +	&g920_range_group,
> +	NULL
> +};
> +
>  static void hidpp_ff_destroy(struct ff_device *ff)
>  {
>  	struct hidpp_ff_private_data *data = ff->private;
>  	struct hidpp_device *hidpp = data->hidpp;
> -	struct hid_device *hid = hidpp->hid_dev;
>  	struct g920_data *g920 = hidpp->private_data;
>  
> -	hid_info(hid, "Unloading HID++ force feedback.\n");
> +	hid_info(hidpp->hid_dev, "Unloading HID++ force feedback.\n");
>  
> -	device_remove_file(&hid->dev, &dev_attr_range);
>  	destroy_workqueue(data->wq);
>  	g920->ff = NULL;
>  }

[Severity: High]
Can hidpp_ff_destroy() cause a use-after-free of hidpp and g920 when an
open event handle outlives driver unbind or disconnect?

Both hidpp (allocated with devm_kzalloc_obj() in hidpp_probe()) and g920
(allocated with devm_kmemdup() in g920_get_config()) belong to hdev's
driver devres group.  If userspace holds an open file descriptor to the
input device across disconnect, input_unregister_device() deletes the
device without releasing it, and hid_device_remove() immediately calls
devres_release_group(), freeing hidpp and g920.

When the last open handle is closed later, input_dev_release() ->
input_ff_destroy() -> hidpp_ff_destroy() reads hidpp->private_data and
hidpp->hid_dev from the freed hidpp struct and writes g920->ff = NULL into
the freed g920 struct.  A later patch in this series, commit "HID:
logitech-hidpp: execute G920 range sysfs store synchronously", removes the
g920->ff assignment, but hidpp_ff_destroy() still dereferences the freed
data->hidpp and hidpp->hid_dev in hid_info().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261120-hid-logitech-hidpp-next-v3-0-ba39242d4336@gmail.com?part=6

  reply	other threads:[~2026-11-20  9:00 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  8:43 [PATCH v3 00/18] HID: logitech-hidpp: G920 force-feedback rework and driver cleanups Dmitry Torokhov
2026-11-20  8:43 ` [PATCH v3 01/18] HID: logitech-hidpp: keep connect work disabled until hid_connect() completes Dmitry Torokhov
2026-11-20  8:43 ` [PATCH v3 02/18] HID: logitech-hidpp: preserve transport error codes in __hidpp_send_report() Dmitry Torokhov
2026-11-20  8:49   ` sashiko-bot
2026-11-20  8:43 ` [PATCH v3 03/18] HID: logitech-hidpp: return negative error codes from hidpp_send_message_sync() Dmitry Torokhov
2026-11-20  8:43 ` [PATCH v3 04/18] HID: logitech-hidpp: rework G920 force-feedback initialization Dmitry Torokhov
2026-11-20  8:43 ` [PATCH v3 05/18] HID: logitech-hidpp: use sysfs_emit() in hidpp_ff_range_show() Dmitry Torokhov
2026-11-20  8:43 ` [PATCH v3 06/18] HID: logitech-hidpp: manage G920 range sysfs attribute via dev_groups Dmitry Torokhov
2026-11-20  9:00   ` sashiko-bot [this message]
2026-11-20  8:43 ` [PATCH v3 07/18] HID: logitech-hidpp: execute G920 range sysfs store synchronously Dmitry Torokhov
2026-11-20  8:43 ` [PATCH v3 08/18] HID: logitech-hidpp: index G920 force-feedback slots by effect ID Dmitry Torokhov
2026-11-20  8:44 ` [PATCH v3 09/18] HID: logitech-hidpp: execute G920 effect upload and erase synchronously Dmitry Torokhov
2026-11-20  8:44 ` [PATCH v3 10/18] HID: logitech-hidpp: clean up G920 force-feedback helpers Dmitry Torokhov
2026-11-20  8:44 ` [PATCH v3 11/18] HID: logitech-hidpp: use unaligned accessors for multi-byte values Dmitry Torokhov
2026-11-20  8:44 ` [PATCH v3 12/18] HID: logitech-hidpp: store device serial as a byte array Dmitry Torokhov
2026-11-20  8:44 ` [PATCH v3 13/18] HID: logitech-hidpp: use guard() for send_mutex Dmitry Torokhov
2026-11-20  8:44 ` [PATCH v3 14/18] HID: logitech-hidpp: use __free(kfree) for temporary allocations Dmitry Torokhov
2026-11-20  8:44 ` [PATCH v3 15/18] HID: logitech-hidpp: use alloc_ordered_workqueue() for FF queue Dmitry Torokhov
2026-11-20  8:44 ` [PATCH v3 16/18] HID: logitech-hidpp: manage send_mutex with devm_mutex_init() Dmitry Torokhov
2026-11-20  8:44 ` [PATCH v3 17/18] HID: logitech-hidpp: manage ps_attribute_group with devm_device_add_group() Dmitry Torokhov
2026-11-20  8:44 ` [PATCH v3 18/18] HID: logitech-hidpp: remove unused kfifo and clean up minor helpers Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-224807@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox