Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Denis Benato" <denis.benato@linux.dev>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v8 12/12] HID: asus: add support for btn remapping
Date: Tue, 22 Sep 2026 23:16:24 +0000	[thread overview]
Message-ID: <20260922231624.600451F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260922230205.6847-13-denis.benato@linux.dev>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] HID: asus: use-after-free of button_entries during teardown and error paths
--

commit d969019ebea0db9a650c70e2413a3a0ba90ade15
Author: Denis Benato <denis.benato@linux.dev>

HID: asus: add support for btn remapping

This commit adds support for button remapping on ROG Ally devices. It
introduces sysfs attributes to configure valid remap targets and automatically
refreshes the software cache when the gamepad mode changes.

> diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c
> --- a/drivers/hid/hid-asus.c
> +++ b/drivers/hid/hid-asus.c
[ ... ]
> @@ -1131,6 +1470,33 @@ static ssize_t gamepad_mode_store(struct device *dev, struct device_attribute *a
[ ... ]
> +	if (cfg->button_entries) {
> +		for (i = 0; i < ALLY_BTN_MAX; i++) {
> +			sysfs_notify(&dev->kobj, cfg->button_entries[i].group.name,
> +				     "remap");
> +			sysfs_notify(&dev->kobj, cfg->button_entries[i].group.name,
> +				     "macro");
> +		}
> +	}
[ ... ]
> @@ -2883,12 +3860,22 @@ static void ally_remove_button_attributes(struct hid_device *hdev, struct ally_c
[ ... ]
>  	kfree(entries);
>  
> -	cfg->button_entries = NULL;
> +	/*
> +	 * Unpublish the pointers under the lock, so that a sysfs callback
> +	 * which is still holding config_mutex observes the teardown
> +	 * instead of freed memory.
> +	 */
> +	scoped_guard(mutex, &cfg->config_mutex) {
> +		cfg->button_entries = NULL;
> +	}
>  }

[Severity: High]
Can this result in a use-after-free when sysfs callbacks run concurrently?

Here entries (which corresponds to cfg->button_entries) is freed via
kfree(entries) before the pointer is actually set to NULL under
config_mutex. If a concurrent sysfs write to gamepad_mode_store() acquires
config_mutex right after this kfree() but before the scoped_guard executes, 
it will see a non-NULL cfg->button_entries and dereference freed memory when 
accessing cfg->button_entries[i].group.name.

Should cfg->button_entries be set to NULL inside the lock before entries is
freed?

[ ... ]
> @@ -2861,6 +3833,11 @@ static int ally_create_button_attributes(struct hid_device *hdev,
[ ... ]
>  err_cleanup:
>  	while (--i >= 0)
>  		sysfs_remove_group(&hdev->dev.kobj, &entries[i].group);
>  
> +	for (i = 0; i < ALLY_BTN_MAX; i++) {
> +		kfree(entries[i].remap_attr);
> +		kfree(entries[i].macro_attr);
> +	}
> +
>  	kfree(entries);
>  
>  	cfg->button_entries = NULL;

[Severity: High]
Is there a similar race condition on this error path?

If ally_create_button_attributes() fails and takes this error path,
cfg->button_entries is set to NULL without holding config_mutex, and after
entries has already been freed. This seems to expose the same use-after-free
window to any concurrent sysfs accesses.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260922230205.6847-1-denis.benato@linux.dev?part=12

      reply	other threads:[~2026-09-22 23:16 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22 23:01 [PATCH v8 00/12] HID: asus: add support for ROG Ally handhelds Denis Benato
2026-09-22 23:01 ` [PATCH v8 01/12] HID: asus: reinitialize the device after exiting a sleep state Denis Benato
2026-09-22 23:01 ` [PATCH v8 02/12] HID: asus: add support for ROG Ally handhelds Denis Benato
2026-09-22 23:01 ` [PATCH v8 03/12] HID: asus: add gamepad configuration Denis Benato
2026-09-22 23:01 ` [PATCH v8 04/12] HID: asus: add vibration strength configuration Denis Benato
2026-09-22 23:01 ` [PATCH v8 05/12] HID: asus: add joysticks inner and outer range configuration Denis Benato
2026-09-22 23:01 ` [PATCH v8 06/12] HID: asus: add triggers " Denis Benato
2026-09-22 23:02 ` [PATCH v8 07/12] HID: asus: add joysticks anti-deadzone configuration Denis Benato
2026-09-22 23:02 ` [PATCH v8 08/12] HID: asus: add support for response curve Denis Benato
2026-09-22 23:02 ` [PATCH v8 09/12] HID: asus: add support to force feedback Denis Benato
2026-09-22 23:15   ` sashiko-bot
2026-09-22 23:02 ` [PATCH v8 10/12] HID: asus: add support for gamepad mode Denis Benato
2026-09-22 23:02 ` [PATCH v8 11/12] HID: asus: add support for turbo buttons Denis Benato
2026-09-22 23:02 ` [PATCH v8 12/12] HID: asus: add support for btn remapping Denis Benato
2026-09-22 23:16   ` sashiko-bot [this message]

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=20260922231624.600451F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=denis.benato@linux.dev \
    --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