mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Yuansheng Yang <0xbeac@gmail.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] iio: trigger: loop: fix use-after-free on configfs removal
Date: Thu, 3 Dec 2026 13:18:01 +0200	[thread overview]
Message-ID: <axFP6RuWKQNhhZ_y@ashevche-desk.local> (raw)
In-Reply-To: <20261202034718.2917551-1-0xbeac@gmail.com>

On Wed, Dec 02, 2026 at 11:47:18AM +0800, Yuansheng Yang wrote:
> Removing a tight-loop trigger directory via configfs while an IIO
> consumer still holds a reference to its iio_trigger frees iio_loop_info
> underneath the consumer:
> 
> 1. iio_trig_loop_probe() allocates struct iio_loop_info (embedding
>    struct iio_sw_trigger swt and storing struct task_struct *task) and
>    sets it as the trigger's drvdata.
> 2. Attaching the trigger to a device's current_trigger acquires a
>    reference on struct iio_trigger via iio_trigger_get().
> 3. rmdir on the configfs trigger directory invokes
>    iio_trig_loop_remove(), which calls iio_trigger_unregister() and
>    iio_trigger_free() (only dropping one device reference), then
>    configfs drops the last config_item reference and iio_loop_release()
>    frees iio_loop_info.  Any active loop kthread is also left running.
> 4. Disabling or re-enabling the consumer's buffer calls
>    iio_loop_trigger_set_state(), which retrieves the freed
>    iio_loop_info via iio_trigger_get_drvdata() and reads or writes
>    loop_trig->task.
> 
> On an x86_64 KASAN QEMU guest with commit 8fb20cdf9c86 applied,
> disabling the buffer after rmdir triggers:
> 
>   BUG: KASAN: slab-use-after-free in iio_loop_trigger_set_state+0x138/0x150
>   Read of size 8 at addr ffff888008b25a98 by task bash/336
>   Call Trace:
>    iio_loop_trigger_set_state+0x138/0x150
>    iio_trigger_detach_poll_func+0x23a/0x2d0
>    iio_disable_buffers+0x38e/0x490
>    __iio_update_buffers+0x1dfc/0x2470
>    enable_store+0x1c1/0x1f0
>   Allocated by task 344:
>    iio_trig_loop_probe+0x47/0x1d0
>    iio_sw_trigger_create+0x156/0x260
>    trigger_make_group+0x33/0x90
>    configfs_mkdir+0x521/0xe90
>   Freed by task 354:
>    kfree+0x154/0x420
>    config_item_cleanup+0x143/0x1e0
>    config_item_put+0x91/0xa0
>    configfs_rmdir+0x881/0xac0
> 
> Re-enabling the buffer afterwards also triggers a slab-use-after-free
> write of size 8 at iio_loop_trigger_set_state+0x149/0x150.
> 
> Commit 8fb20cdf9c86 ("iio: trigger: free hrtimer and loop triggers on
> configfs release") moved kfree(trig_info) from iio_trig_loop_remove()
> to iio_loop_release(), fixing the plain mkdir/rmdir config_item UAF,
> but left the consumer-outlives-rmdir lifetime mismatch intact.
> 
> Serialize iio_loop_trigger_set_state() and iio_trig_loop_remove() with a
> static mutex.  In iio_trig_loop_remove(), stop any running kthread
> after iio_trigger_unregister() and clear the trigger's drvdata to NULL
> before iio_trigger_free().  In iio_loop_trigger_set_state(), return 0 on
> disable or -ENODEV on enable once drvdata has been cleared.
> 
> Discovered by manual code inspection following the sibling hrtimer
> trigger UAF report, with Gemini assisting in path verification, QEMU
> reproduction, and preparing this patch and changelog.

Read Submitting Patches documentation about backtraces in the commit messages
and use *your own words* to make this commit message readable.

This is no-go in this form.

-- 
With Best Regards,
Andy Shevchenko



      reply	other threads:[~2026-12-03 11:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  3:47 Yuansheng Yang
2026-12-03 11:18 ` Andy Shevchenko [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=axFP6RuWKQNhhZ_y@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=0xbeac@gmail.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

all inboxes | Powered by JetHome®