From: Joshua Crofts <joshua.crofts1@gmail.com>
To: Dingisoul <dingiso.kernel@gmail.com>
Cc: andy@kernel.org, dlechner@baylibre.com, jic23@kernel.org,
linusw@kernel.org, linux-iio@vger.kernel.org, nuno.sa@analog.com
Subject: Re: [BUG] iio: gyro: mpu3050: use-after-free via trigger left on iio_trigger_list after unbind
Date: Tue, 13 Oct 2026 13:30:19 +0200 [thread overview]
Message-ID: <20261013133019.000033e1@gmail.com> (raw)
In-Reply-To: <20261012200904.1853361-1-dingiso.kernel@gmail.com>
On Mon, 12 Oct 2026 16:09:04 -0400
Dingisoul <dingiso.kernel@gmail.com> wrote:
> Hi Joshua, Sashiko,
>
> Sashiko's concern is really about not being able to tell whether the
> trigger was ever actually registered before calling
> iio_trigger_unregister(). There's a precedent for this exact bug class:
> commit 3c5eed894efd9 ("iio: temperature: tmp006: use
> devm_iio_trigger_register") hit the same
> devm_iio_trigger_alloc()-but-plain-register() mismatch in tmp006, and
> fixed it by switching to devm_iio_trigger_register() instead of adding a
> manual unregister call.
>
> https://github.com/torvalds/linux/commit/3c5eed894efd9
>
> devm_iio_trigger_register() only installs its cleanup action if
> iio_trigger_register() actually succeeds:
>
> int devm_iio_trigger_register(struct device *dev,
> struct iio_trigger *trig_info)
> {
> int ret;
>
> ret = iio_trigger_register(trig_info);
> if (ret)
> return ret;
>
> return devm_add_action_or_reset(dev, devm_iio_trigger_unreg, trig_info);
> }
>
> so it can never unregister a trigger that was never registered -- no
> flag/pointer tracking needed.
>
> Suggested fix, in mpu3050_trigger_probe():
>
> - ret = iio_trigger_register(mpu3050->trig);
> + ret = devm_iio_trigger_register(&indio_dev->dev, mpu3050->trig);
Ideally you shouldn't mix devm_* and non-devm_* function, this can cause headaches
down the road. Either we do the manual dance or we convert the entire driver to
devm_*. If you check the file in the commit you referenced above, you'll notice
that all the other functions are devm_*.
Bartosz Golaszewski had a talk on this at OSS Prague (recording still isn't
available, so I'm attaching the presentation instead).
https://hosted-files.sched.co/osselceu2026/0c/OSS%202026%20Prague.pdf
--
Kind regards,
Joshua Crofts
prev parent reply other threads:[~2026-10-13 11:30 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-10 20:36 [BUG] iio: gyro: mpu3050: use-after-free via trigger left on iio_trigger_list after unbind Dingisoul
2026-10-11 17:05 ` Joshua Crofts
2026-10-12 20:09 ` Dingisoul
2026-10-13 11:30 ` Joshua Crofts [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=20261013133019.000033e1@gmail.com \
--to=joshua.crofts1@gmail.com \
--cc=andy@kernel.org \
--cc=dingiso.kernel@gmail.com \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=nuno.sa@analog.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox