From: Yuansheng Yang <0xbeac@gmail.com>
To: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH v2] iio: trigger: loop: fix use-after-free on configfs removal
Date: Sat, 5 Dec 2026 03:09:18 +0800 [thread overview]
Message-ID: <20261204190918.1355662-1-0xbeac@gmail.com> (raw)
In-Reply-To: <axLvTO2L7V8OmA7V@ashevche-desk.local>
On Fri, Dec 04, 2026 at 06:50:20PM +0200, Andy Shevchenko wrote:
> On Fri, Dec 04, 2026 at 03:32:02AM +0800, Yuansheng Yang wrote:
...
> > Gemini was used to assist with code path verification, QEMU KASAN
> > reproduction, and drafting the initial patch; the final code and this
> > changelog were reviewed and edited by me.
>
> This should be moved to the comment block.
Sure, will move this below the '---' line in v3.
> > static int iio_loop_trigger_set_state(struct iio_trigger *trig, bool state)
> > {
> > - struct iio_loop_info *loop_trig = iio_trigger_get_drvdata(trig);
> > + struct iio_loop_info *loop_trig;
> > + struct task_struct *task;
> > +
> > + guard(mutex)(&iio_loop_lock);
>
> > + loop_trig = iio_trigger_get_drvdata(trig);
>
> Leave this line as it was before...
>
> > + if (!loop_trig)
> > + return state ? -ENODEV : 0;
>
> ...and just add two conditionals to each of the existing if (state) branches
> below.
Folding the NULL checks into the two if (state) branches makes sense and
I'll do that in v3.
However, iio_trigger_get_drvdata(trig) needs to stay after
guard(mutex)(&iio_loop_lock). There is no outer lock shared between
enable_store() -> iio_loop_trigger_set_state() and configfs rmdir ->
iio_trig_loop_remove(). If iio_trigger_get_drvdata(trig) is called
before acquiring iio_loop_lock:
1. Thread A (set_trigger_state) reads a non-NULL loop_trig before taking
iio_loop_lock.
2. Thread B (rmdir) takes iio_loop_lock in iio_trig_loop_remove(), stops
any running kthread, clears drvdata to NULL, drops iio_loop_lock, and
config_item_put() frees loop_trig via iio_loop_release().
3. Thread A acquires iio_loop_lock with its cached non-NULL loop_trig
now dangling, bypasses the NULL check, and dereferences freed
loop_trig->task.
So in v3 it would look like:
guard(mutex)(&iio_loop_lock);
loop_trig = iio_trigger_get_drvdata(trig);
if (state) {
if (!loop_trig)
return -ENODEV;
if (loop_trig->task)
return -EBUSY;
...
} else if (loop_trig && loop_trig->task) {
kthread_stop(loop_trig->task);
loop_trig->task = NULL;
}
Does that look good to you before I send v3?
Thanks,
Yuansheng
prev parent reply other threads:[~2026-12-04 19:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 19:32 [PATCH v2] iio: trigger: loop: fix use-after-free on configfs removal Yuansheng Yang
2026-12-04 16:50 ` Andy Shevchenko
2026-12-04 19:09 ` Yuansheng Yang [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=20261204190918.1355662-1-0xbeac@gmail.com \
--to=0xbeac@gmail.com \
--cc=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=stable@vger.kernel.org \
/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