Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Esben Haabendal" <esben@geanix.com>
Cc: conor+dt@kernel.org, robh@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v6 8/9] iio: accel: mma8452: Fix use-after-free bug in error error path
Date: Tue, 25 Aug 2026 08:41:30 +0000	[thread overview]
Message-ID: <20260825084130.89DBB1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260825-mma8452-open-drain-v6-8-9b252804ee80@geanix.com>

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

Pre-existing issues:
- [High] The device is left in ACTIVE mode on probe failure paths, potentially draining power and asserting interrupts indefinitely.
- [High] The driver leaks the PM runtime usage count on multiple error paths when I2C reads/writes fail after acquiring a runtime PM reference.
- [High] In `mma8452_runtime_suspend()`, if disabling the second regulator fails, the first regulator remains disabled but the PM state is left as RPM_ACTIVE.
- [High] Time-of-check to time-of-use (TOCTOU) race condition during read-modify-write of I2C event configuration registers.
--

--- Patch [8]: [PATCH v6 8/9] iio: accel: mma8452: Fix use-after-free bug in error error path ---
commit bad43bbf94c93f7ecf6436d8c780a1207e0288f4
Author: Esben Haabendal <esben@geanix.com>

iio: accel: mma8452: Fix use-after-free bug in error error path

This commit fixes a use-after-free in the mma8452_probe error path.
By adding a runtime_suspend label, it ensures the runtime PM disable step
happens before the IRQ is freed, avoiding callbacks with a freed device.

> diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
> index 9ae2c3e605761..4a1eb196589ab 100644
> --- a/drivers/iio/accel/mma8452.c
> +++ b/drivers/iio/accel/mma8452.c
> @@ -1743,7 +1743,7 @@ static int mma8452_probe(struct i2c_client *client)
>  
>  	ret = iio_device_register(indio_dev);
>  	if (ret < 0)
> -		goto free_irq;
> +		goto runtime_suspend;
>  
>  	ret = mma8452_set_freefall_mode(data, false);

[Severity: High]
This isn't a bug introduced by this patch, but is there a data race in
mma8452_set_freefall_mode() called here?

It looks like mma8452_set_freefall_mode() reads the configuration register
locklessly before modifying it:

mma8452_set_freefall_mode() {
	...
	val = i2c_smbus_read_byte_data(data->client, MMA8452_FF_MT_CFG);
	...
	return mma8452_change_config(data, MMA8452_FF_MT_CFG, val);
}

Since mma8452_change_config() only acquires data->lock during the write,
could concurrent modifications via sysfs overwrite and discard each other's
changes? A similar pattern appears to exist in mma8452_write_event_config().

>  	if (ret < 0)

[ ... ]

> @@ -1754,6 +1754,10 @@ static int mma8452_probe(struct i2c_client *client)
>  unregister_device:
>  	iio_device_unregister(indio_dev);
>  
> +runtime_suspend:
> +	pm_runtime_disable(dev);
> +	pm_runtime_set_suspended(dev);
> +

[Severity: High]
This is a pre-existing issue, but does this error path skip placing the
hardware back into standby mode?

If mma8452_probe() fails and jumps to this runtime_suspend label, the
software resources are disabled, but the device might be left in ACTIVE
mode. Could this result in the device indefinitely asserting a shared
interrupt line if it was previously activated, since the IRQ handler is freed
shortly after?

Should there be a call to mma8452_standby() in this error path?

>  free_irq:
>  	if (client->irq)
>  		free_irq(client->irq, indio_dev);

[Severity: High]
This is a pre-existing issue, but does mma8452_read() leak a runtime PM
usage count on I2C errors?

If mma8452_set_runtime_pm_state(..., true) succeeds, but the subsequent I2C
block read fails:

mma8452_read() {
	...
	ret = i2c_smbus_read_i2c_block_data(data->client, MMA8452_OUT_X,
					    3 * sizeof(__be16), (u8 *)buf);
	if (ret < 0)
		return ret;
	...
}

The function returns immediately without rolling back the PM reference.
I noticed similar early returns in mma8452_write_event_config() and
mma8452_data_rdy_trigger_set_state() that might leave the device permanently
active.

[Severity: High]
This is also a pre-existing issue, but is the regulator state left unbalanced
if runtime suspend fails?

In mma8452_runtime_suspend():

mma8452_runtime_suspend() {
	...
	regulator_disable(data->vddio_reg);

	ret = regulator_disable(data->vdd_reg);
	if (ret) {
		dev_err(dev, "failed to disable VDD regulator\n");
		return ret;
	}
	...
}

If disabling vdd_reg fails, the function returns an error without
re-enabling vddio_reg. Since the PM core keeps the device in RPM_ACTIVE
on failure, won't subsequent suspend attempts call
regulator_disable(data->vddio_reg) again and underflow the enable count?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260825-mma8452-open-drain-v6-0-9b252804ee80@geanix.com?part=8

  reply	other threads:[~2026-08-25  8:41 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-25  8:27 [PATCH v6 0/9] io: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
2026-08-25  8:27 ` [PATCH v6 1/9] dt-bindings: iio: accel: mma8452: Add drive-open-drain Esben Haabendal
2026-08-25  8:27 ` [PATCH v6 2/9] iio: accel: mma8452: Optimize struct mma8452_data member orders Esben Haabendal
2026-08-25  8:38   ` sashiko-bot
2026-08-25  8:27 ` [PATCH v6 3/9] iio: accel: mma8452: Only apply trigger type when not set by firmware Esben Haabendal
2026-08-25  8:43   ` sashiko-bot
2026-08-25  8:27 ` [PATCH v6 4/9] iio: accel: mma8452: Support interrupt sharing Esben Haabendal
2026-08-25  8:42   ` sashiko-bot
2026-08-25 11:39     ` Esben Haabendal
2026-08-25  8:27 ` [PATCH v6 5/9] iio: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
2026-08-25  8:42   ` sashiko-bot
2026-08-25 13:26     ` Esben Haabendal
2026-08-25  8:27 ` [PATCH v6 6/9] iio: accel: mma8452: Reuse existing dev pointer in mma8452_probe() Esben Haabendal
2026-08-25  8:38   ` sashiko-bot
2026-08-25 11:15     ` Esben Haabendal
2026-08-26  7:27   ` Andy Shevchenko
2026-08-25  8:27 ` [PATCH v6 7/9] iio: accel: mma8452: Drop unneeded lock acquire on read Esben Haabendal
2026-08-25  8:45   ` sashiko-bot
2026-08-25 10:17   ` Joshua Crofts
2026-08-25 13:35     ` Esben Haabendal
2026-08-25 13:44       ` Joshua Crofts
2026-08-25 14:06         ` Esben Haabendal
2026-08-25  8:27 ` [PATCH v6 8/9] iio: accel: mma8452: Fix use-after-free bug in error error path Esben Haabendal
2026-08-25  8:41   ` sashiko-bot [this message]
2026-08-25  8:27 ` [PATCH v6 9/9] iio: accel: mma8452: Use proper error code when missing device model Esben Haabendal
2026-08-25  8:40   ` sashiko-bot
2026-08-25 10:23   ` Joshua Crofts
2026-08-25 11:00     ` Esben Haabendal

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=20260825084130.89DBB1F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=esben@geanix.com \
    --cc=robh@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