Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Nikolas Koesling" <nikolas@koesling.info>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH v7] HID: pulsar: add driver for Pulsar gaming mice
Date: Wed, 02 Sep 2026 16:33:24 +0000	[thread overview]
Message-ID: <20260902163325.130181F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260902161350.22233-1-nikolas@koesling.info>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] The driver leaks uninitialized kernel stack memory to userspace and allows a deterministic kernel crash because `battery_get_property` returns `1` without initializing the property value.
--

commit 6987787f50bcfdb5c82e17e354bba7b71293f806
Author: Nikolas Koesling <nikolas@koesling.info>

HID: pulsar: add driver for Pulsar gaming mice

Add a HID driver for Pulsar wireless gaming mice (X2 V2, X2H, X2A,
Xlite V3). The driver exposes battery level, voltage, and charging
status through the power supply framework.

[ ... ]
> diff --git a/drivers/hid/hid-pulsar.c b/drivers/hid/hid-pulsar.c
> new file mode 100644
> index 0000000000000..a6ff6e436d407
> --- /dev/null
> +++ b/drivers/hid/hid-pulsar.c
[ ... ]
> +static int read_power(struct pulsar_data *drvdata)
> +{
[ ... ]
> +	if (need_status) {
> +		ret = read_status(drvdata);
> +		if (ret < 0) {
[ ... ]
> +			goto unlock;
> +		}
> +
> +		battery->last_status = now;
> +
> +		if (!ret) {
> +			battery->available = false;
> +			battery->refresh = false;
> +			goto unlock;
> +		}
> +
> +		/* device just became available, force power read */
> +		if (!battery->available)
> +			need_power = true;
> +	}
> +
> +	if (!need_power)
> +		goto unlock;
[ ... ]
> +unlock:
> +	up_write(&drvdata->lock_bat);
> +	return ret;
> +}

[Severity: Critical]
When read_status() succeeds and the device is available, it returns 1. If 
need_power is false (e.g., between 5 and 60 seconds after a previous read), 
read_power() jumps to unlock and returns this 1.

Does this unintentionally return 1 on success instead of 0?

> +
> +static int battery_get_property(struct power_supply *psy,
> +				enum power_supply_property psp,
> +				union power_supply_propval *val)
> +{
> +	struct pulsar_data *drvdata;
> +	int ret;
> +
> +	drvdata = power_supply_get_drvdata(psy);
> +
> +	ret = read_power(drvdata);
> +	if (ret)
> +		return ret;

[Severity: Critical]
Will this leak uninitialized kernel stack memory or cause a kernel crash?

If read_power() returns 1 as described above, this branch returns 1 
immediately, bypassing the switch statement that initializes the property 
value. 

The power supply core (e.g., in power_supply_format_property) only considers 
strictly negative values as errors. It treats 1 as success and will proceed 
to read the uninitialized union value. For integer properties, this leaks 
stack memory to userspace. For string properties like 
POWER_SUPPLY_PROP_MODEL_NAME, it dereferences the garbage stack pointer in 
val->strval, which can cause a direct kernel panic.

> +
> +	down_read(&drvdata->lock_bat);
> +
> +	switch (psp) {
[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260902161350.22233-1-nikolas@koesling.info?part=1

  reply	other threads:[~2026-09-02 16:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-02 16:13 [PATCH v7] HID: pulsar: add driver for Pulsar gaming mice Nikolas Koesling
2026-09-02 16:33 ` sashiko-bot [this message]
2026-09-03 18:01   ` Nikolas Koesling

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=20260902163325.130181F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=nikolas@koesling.info \
    --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