All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Denis Benato" <denis.benato@linux.dev>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH v4 12/13] HID: asus: add support for turbo buttons
Date: Mon, 31 Aug 2026 00:14:37 +0000	[thread overview]
Message-ID: <20260831001437.EE05B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260830234320.114356-13-denis.benato@linux.dev>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [High] Use-After-Free of turbo button sysfs entries during driver unbind.
- [Low] Memory leak of devm-allocated `entries` array on sysfs creation error path.

Pre-existing issues:
- [High] Missing assignment of newly created configuration to the global shared state.
--

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

HID: asus: add support for turbo buttons

ROG ally devices supports a feature called turbo buttons that allows
the user to quickly toggle button state by keeping a button pressed,
therefore allow userspace to configure the feature by exposing
relevant sysfs attributes.

> diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c
> index 9ed6c605df888..7fc04d29de8de 100644
> --- a/drivers/hid/hid-asus.c
> +++ b/drivers/hid/hid-asus.c

[ ... ]

> @@ -2684,6 +3118,8 @@ static struct ally_config *ally_config_create(struct hid_device *hdev, struct al
>  
>  	return cfg;
>  ally_config_create_sysfs_err:
> +	if (cfg->button_entries)
> +		ally_remove_button_attributes(hdev, cfg);
>  ally_config_create_err:
>  	devm_kfree(&hdev->dev, cfg);
>  	return ERR_PTR(ret);

[Severity: Low]
Does this code leak the entries array if sysfs creation fails?

In ally_create_button_attributes(), the entries array is allocated using
devm_kcalloc(). If sysfs_create_group() fails, the error path sets
cfg->button_entries = NULL.

When returning here, cfg->button_entries is NULL, so
ally_remove_button_attributes() is skipped. The cfg structure is freed
manually to save memory, but the devm-allocated entries array is abandoned.

Since asus_probe() might ignore probe failures from the Ally extension,
the devres group remains alive, causing this memory to stay allocated until
the device is unbound. Could the entries array be freed directly on this
error path?

[ ... ]

> @@ -2701,6 +3137,9 @@ static void ally_config_remove(struct hid_device *hdev, struct ally_config *cfg)
>  	if (!cfg || !cfg->initialized)
>  		return;
>  
> +	if (cfg->button_entries)
> +		ally_remove_button_attributes(hdev, cfg);
> +
>  	for (i = 0; i < ARRAY_SIZE(ally_attr_groups); i++)
>  		sysfs_remove_group(&hdev->dev.kobj, &ally_attr_groups[i]);
>  }

[Severity: High]
This is a pre-existing issue, but it appears the newly created configuration
in hid_asus_ally_probe() is never assigned to the global shared state.

In hid_asus_ally_probe():

    ally_cfg = ally_config_create(hdev, &ally_drvdata);
    if (IS_ERR(ally_cfg)) {
    ...
    spin_lock_irqsave(&ally_data_lock, flags);
    ally_drvdata.cfg_hdev = hdev;
    // ally_drvdata.config is not set to ally_cfg
    spin_unlock_irqrestore(&ally_data_lock, flags);

Because ally->config is never set, subsequent config lookups fail, and
the cfg parameter passed to ally_config_remove() is always NULL.

[Severity: High]
Can the unbind path cause a use-after-free regression here?

Because cfg is always NULL (due to the pre-existing issue mentioned above),
the early return in ally_config_remove() is taken, and
ally_remove_button_attributes() is skipped during unbind.

Since sysfs_create_group() is used to manually create the sysfs attributes,
they are not tied to devres. However, their backing memory (the entries
array) is allocated with devm_kcalloc() and will be freed by devres.

This leaves the sysfs files active after the memory is freed. If a user
reads one of these leftover sysfs files after device unplug (e.g., in
btn_turbo_period_show()), it dereferences the freed memory, causing a
use-after-free.

Could the missing configuration assignment be fixed so cleanup occurs
correctly, or could the sysfs group lifecycles be tied to devres as well?

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

  reply	other threads:[~2026-08-31  0:14 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-30 23:43 [PATCH v4 00/13] HID: asus: add support for ROG Ally handhelds Denis Benato
2026-08-30 23:43 ` [PATCH v4 01/13] HID: asus: do not send keyboard init reports to touchpads Denis Benato
2026-08-30 23:43 ` [PATCH v4 02/13] HID: asus: reinitialize the device after exiting a sleep state Denis Benato
2026-08-30 23:43 ` [PATCH v4 03/13] HID: asus: add support for ROG Ally handhelds Denis Benato
2026-08-30 23:56   ` sashiko-bot
2026-08-30 23:43 ` [PATCH v4 04/13] HID: asus: add gamepad configuration Denis Benato
2026-08-30 23:53   ` sashiko-bot
2026-08-30 23:43 ` [PATCH v4 05/13] HID: asus: add vibration strength configuration Denis Benato
2026-08-30 23:43 ` [PATCH v4 06/13] HID: asus: add joysticks inner and outer range configuration Denis Benato
2026-08-31  0:05   ` sashiko-bot
2026-08-30 23:43 ` [PATCH v4 07/13] HID: asus: add triggers " Denis Benato
2026-08-30 23:58   ` sashiko-bot
2026-08-30 23:43 ` [PATCH v4 08/13] HID: asus: add joysticks anti-deadzone configuration Denis Benato
2026-08-30 23:57   ` sashiko-bot
2026-08-30 23:43 ` [PATCH v4 09/13] HID: asus: add support for response curve Denis Benato
2026-08-31  0:03   ` sashiko-bot
2026-08-30 23:43 ` [PATCH v4 10/13] HID: asus: add support to force feedback Denis Benato
2026-08-31  0:02   ` sashiko-bot
2026-08-30 23:43 ` [PATCH v4 11/13] HID: asus: add support for gamepad mode Denis Benato
2026-08-31  0:05   ` sashiko-bot
2026-08-30 23:43 ` [PATCH v4 12/13] HID: asus: add support for turbo buttons Denis Benato
2026-08-31  0:14   ` sashiko-bot [this message]
2026-08-30 23:43 ` [PATCH v4 13/13] HID: asus: add support for btn remapping Denis Benato
2026-08-31  0:08   ` sashiko-bot

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=20260831001437.EE05B1F000E9@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.