All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Vicki Pfau" <vi@endrift.com>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH v5 05/12] Input: xbox_gip - Add battery support
Date: Wed, 02 Sep 2026 01:20:38 +0000	[thread overview]
Message-ID: <20260902012038.DDBBA1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260902010237.865772-6-vi@endrift.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Devres actions on `input->dev` are delayed until userspace drops all references, causing the power supply to outlive the `attachment` structure and resulting in a Use-After-Free.
- [High] Manually unregistering a devm-managed power supply and freeing its name on an error path leads to a double-unregister and UAF when devres cleanup executes.
--

commit 7a0e19630adf51b35545780bfe01529fdc2adba8
Author: Vicki Pfau <vi@endrift.com>

Input: xbox_gip - Add battery support

This commit adds battery support to the xbox_gip driver by exposing the
controller's battery information as a power_supply device.

> diff --git a/drivers/input/joystick/gip/gip-core.c b/drivers/input/joystick/gip/gip-core.c
> --- a/drivers/input/joystick/gip/gip-core.c
> +++ b/drivers/input/joystick/gip/gip-core.c
[ ... ]
> @@ -1199,6 +1206,106 @@ static int gip_guide_led_probe(struct gip_attachment *attachment, struct device
[ ... ]
> +static int gip_battery_create(struct gip_attachment *attachment, struct device *dev)
> +{
> +	struct power_supply_config supply_config = { .drv_data = attachment, };
> +	int rc;
[ ... ]
> +	attachment->battery = devm_power_supply_register(dev,
> +		&attachment->battery_desc, &supply_config);
> +	if (IS_ERR(attachment->battery)) {
> +		rc = PTR_ERR(attachment->battery);
> +		goto err_out;
> +	}
> +
> +	rc = power_supply_powers(attachment->battery, dev);
> +	if (rc < 0) {
> +		power_supply_unregister(attachment->battery);
> +		goto err_out;
> +	}

[Severity: High]
Because attachment->battery was allocated using devm_power_supply_register(),
a devres action is already queued to unregister it. If power_supply_powers()
fails and we manually call power_supply_unregister() here, will devres
attempt to unregister it again later when the input device is cleaned up,
leading to a double-free?

[ ... ]
> @@ -1494,6 +1604,8 @@ static void gip_free_devices(struct gip_attachment *attachment)
>  
>  	rcu_assign_pointer(attachment->input, NULL);
>  	rcu_assign_pointer(attachment->hdev, NULL);
> +	/* The following are freed by devres */
> +	attachment->battery = NULL;
>  	synchronize_rcu();

[Severity: High]
The battery was registered with devm using the input device (input->dev).
Since input device devres actions are delayed until userspace drops all
evdev file descriptor references, does setting attachment->battery to NULL
here leave the power supply active after the driver disconnects?

If a user reads the sysfs attributes for the power supply after the device
is unplugged, could gip_battery_get_property() attempt to access the freed
attachment structure?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260902010237.865772-1-vi@endrift.com?part=5

  reply	other threads:[~2026-09-02  1:20 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-02  1:02 [PATCH v5 00/12] Input: xbox_gip - Add new driver for Xbox GIP Vicki Pfau
2026-09-02  1:02 ` [PATCH v5 01/12] " Vicki Pfau
2026-09-02  1:28   ` sashiko-bot
2026-09-02  1:02 ` [PATCH v5 02/12] Input: xpad - Remove Xbox One support Vicki Pfau
2026-09-02  1:02 ` [PATCH v5 03/12] Input: xbox_gip - Add controllable LED support Vicki Pfau
2026-09-02  1:20   ` sashiko-bot
2026-09-02  1:02 ` [PATCH v5 04/12] Input: xbox_gip - Add HID relaying Vicki Pfau
2026-09-02  1:22   ` sashiko-bot
2026-09-02  1:02 ` [PATCH v5 05/12] Input: xbox_gip - Add battery support Vicki Pfau
2026-09-02  1:20   ` sashiko-bot [this message]
2026-09-02  1:02 ` [PATCH v5 06/12] Input: xbox_gip - Allow sending fragmented and ACME messages Vicki Pfau
2026-09-02  1:19   ` sashiko-bot
2026-09-02  1:02 ` [PATCH v5 07/12] Input: xbox_gip - Add security implementation from xone Vicki Pfau
2026-09-02  1:20   ` sashiko-bot
2026-09-02  1:02 ` [PATCH v5 08/12] Input: xbox_gip - Add arcade stick support Vicki Pfau
2026-09-02  1:24   ` sashiko-bot
2026-09-02  1:02 ` [PATCH v5 09/12] Input: xbox_gip - Add support for PDP guitar controllers Vicki Pfau
2026-09-02  1:02 ` [PATCH v5 10/12] Input: Add ABS_CLUTCH, HANDBRAKE, and SHIFTER Vicki Pfau
2026-09-02  1:23   ` sashiko-bot
2026-09-02  1:02 ` [PATCH v5 11/12] HID: Map more automobile simulation inputs Vicki Pfau
2026-09-02  1:02 ` [PATCH v5 12/12] Input: xbox_gip - Add wheel support Vicki Pfau
2026-09-02  1:33   ` 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=20260902012038.DDBBA1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vi@endrift.com \
    /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.