From: Benjamin Marzinski <bmarzins@redhat.com>
To: Qiliang Yuan <qiliang.yuan@linux.dev>
Cc: Alasdair Kergon <agk@redhat.com>,
Mike Snitzer <snitzer@kernel.org>,
Mikulas Patocka <mpatocka@redhat.com>,
dm-devel@lists.linux.dev, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH v3 2/3] dm thin: keep a thin on active_thins until its last reference is dropped
Date: Thu, 19 Nov 2026 14:20:16 -0500 [thread overview]
Message-ID: <av9L8MWVWbhGcON6@redhat.com> (raw)
In-Reply-To: <20261119-bug-dm-thin-rcu-gp-v3-2-c80ecc475e1e@linux.dev>
On Thu, Nov 19, 2026 at 06:05:07AM -0500, Qiliang Yuan wrote:
> get_first_thin() and get_next_thin() let the pool worker process the
> thins on pool->active_thins without holding rcu_read_lock() while it
> does: they take a reference on a thin under the lock, and
> get_next_thin() continues from that thin in a new read-side section.
> thin_dtr() takes the thin off the list, waits for a grace period and
> then for the references still held.
>
> Once thin_dtr() has removed a thin that the worker holds, nothing
> updates its list.next pointer any more. If the thin after it is removed
> and freed before the worker calls get_next_thin(), the walk continues
> from freed memory:
>
> BUG: KASAN: slab-use-after-free in get_next_thin+0x8b/0x240 [dm_thin_pool]
> Write of size 4 at addr ff11000116371cc8 by task kworker/u128:0/13
> Workqueue: dm-thin do_worker [dm_thin_pool]
> Call Trace:
> get_next_thin+0x8b/0x240 [dm_thin_pool]
> process_deferred_bios+0x34/0x650 [dm_thin_pool]
> do_worker+0x2b7/0x4f0 [dm_thin_pool]
> process_one_work+0x8ce/0x1850
> worker_thread+0x639/0x1190
> Allocated by task 2290:
> thin_ctr+0x130/0x1260 [dm_thin_pool]
> dm_table_add_target+0x65f/0xf60 [dm_mod]
> table_load+0x1c2/0x480 [dm_mod]
> Freed by task 2391:
> kfree+0x15d/0x550
> thin_dtr+0x21c/0x2c0 [dm_thin_pool]
> dm_table_destroy+0x13c/0x570 [dm_mod]
> __dm_destroy+0x2eb/0x5d0 [dm_mod]
> dev_remove+0x2f1/0x3c0 [dm_mod]
>
> Mark the thin as dying in thin_dtr() instead of removing it, and take it
> off the list only after the last reference is dropped, so that removing
> its neighbours keeps its list.next valid. Take references with
> refcount_inc_not_zero() and skip dying thins, so that thin_dtr() only
> waits for the references already taken, and have requeue_bios() and
> error_retry_list_with_code() skip dying thins as they skipped the thins
> already off the list.
>
> With a test-only 3 s msleep() added to the worker after each thin it
> processes, thins 1 and 2 of a pool with three thins are suspended and
> then removed while the worker holds thin 1. Trials in which KASAN reports
> a slab-use-after-free in get_next_thin():
>
> before (trials) after (trials) change
> KASAN report 3 of 3 0 of 5 -100%
>
> Fixes: 17181fb7a0c3 ("dm thin: fix a race in thin_dtr")
> Cc: stable@vger.kernel.org
> Reported-by: Benjamin Marzinski <bmarzins@redhat.com>
> Closes: https://lore.kernel.org/r/avz7qDWd2g-uubmL@redhat.com
> Co-developed-by: Benjamin Marzinski <bmarzins@redhat.com>
> Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
> Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
Thanks for updating this.
-Ben
next prev parent reply other threads:[~2026-11-19 19:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 11:05 [PATCH v3 0/3] dm thin: stop waiting for grace periods when activating and removing thins Qiliang Yuan
2026-11-19 11:05 ` [PATCH v3 1/3] dm thin: drop the grace period from thin_ctr() Qiliang Yuan
2026-11-19 11:05 ` [PATCH v3 2/3] dm thin: keep a thin on active_thins until its last reference is dropped Qiliang Yuan
2026-11-19 19:20 ` Benjamin Marzinski [this message]
2026-11-19 11:05 ` [PATCH v3 3/3] dm thin: free thins with kfree_rcu() instead of waiting in thin_dtr() Qiliang Yuan
2026-11-19 19:20 ` Benjamin Marzinski
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=av9L8MWVWbhGcON6@redhat.com \
--to=bmarzins@redhat.com \
--cc=agk@redhat.com \
--cc=dm-devel@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=mpatocka@redhat.com \
--cc=qiliang.yuan@linux.dev \
--cc=snitzer@kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.