Linux IIO development
 help / color / mirror / Atom feed
From: Dingisoul <dingiso.kernel@gmail.com>
To: joshua.crofts1@gmail.com
Cc: andy@kernel.org, dingiso.kernel@gmail.com, 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: Mon, 12 Oct 2026 16:09:04 -0400	[thread overview]
Message-ID: <20261012200904.1853361-1-dingiso.kernel@gmail.com> (raw)
In-Reply-To: <20261011190522.79da3607@systembl0wer>

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);

(same scope devm_iio_trigger_alloc() already uses a few lines above).
With this, both iio_trigger_unregister() calls in your patch can be
dropped.

I rebuilt with just this one-line change and reran my reproducer:
the trigger registers normally on probe, and after delete_device 
it's actually gone instead of left dangling, so the attack just 
gets -EINVAL instead of a UAF. No KASAN report, no warnings.

Happy to test further revisions.

Best,
Dingisoul

  reply	other threads:[~2026-10-12 20:09 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 [this message]
2026-10-13 11:30     ` Joshua Crofts

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=20261012200904.1853361-1-dingiso.kernel@gmail.com \
    --to=dingiso.kernel@gmail.com \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=joshua.crofts1@gmail.com \
    --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