Linux Device Mapper development
 help / color / mirror / Atom feed
From: Junzhe Yu <junzheyu1@gmail.com>
To: Mike Snitzer <snitzer@kernel.org>,
	Mikulas Patocka <mpatocka@redhat.com>,
	Benjamin Marzinski <bmarzins@redhat.com>,
	Alasdair Kergon <agk@redhat.com>
Cc: dm-devel@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [BUG] dm: dm_setup_md_queue UAF walking table_devices without lock
Date: Sat, 18 Jul 2026 21:43:37 +0800	[thread overview]
Message-ID: <5947c25a-0a1e-4bb2-ad3e-8e4d9ecbd8c2@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 3138 bytes --]

Hello,

I am reporting a KASAN slab use-after-free in the device-mapper core in
dm_setup_md_queue().

Summary
=======

dm_setup_md_queue() walks md->table_devices without holding
md->table_devices_lock while a concurrent failed DM_TABLE_LOAD frees a
table_device via dm_table_destroy() -> close_table_device(). The crash
shows as a KASAN UAF on the list walk, and often a follow-on page fault
in bd_link_disk_holder().

Affected
========

- Confirmed on Linux 6.6.144 (da47cbc254661aa66d61ef061485a7080305c4be)
- Originally found on Linux 6.6.0 (ffc253263a1375a65fa6c9f62a893e9767fbebfa)
- Files: drivers/md/dm.c, drivers/md/dm-ioctl.c
- Config: CONFIG_DM=y, CONFIG_BLK_DEV_LOOP=y, CONFIG_KASAN=y

Root cause (brief)
==================

- Top frame: dm_setup_md_queue() at drivers/md/dm.c:2380
   (list_for_each_entry over md->table_devices), called from table_load()
   while md->type == DM_TYPE_NONE.
- table_devices_lock is held only around add_disk() and then released. The
   subsequent list walk that calls bd_link_disk_holder() has no lock.
- A concurrent failed table_load unlocks at err_unlock_md_type and then
   dm_table_destroy() -> close_table_device() (list_del + kfree) races with
   that walk.

The PoC uses only documented DM ioctls (DM_DEV_CREATE, DM_TABLE_LOAD,
DM_DEV_REMOVE) as root. Concurrent table loads are not forbidden by the
userspace API; the kernel must serialize mapped-device state.

Crash excerpt (KASAN)
=====================

BUG: KASAN: slab-use-after-free in dm_setup_md_queue+0x4f4/0x590
Call Trace:
  dm_setup_md_queue+0x4f4/0x590
  table_load+0x56b/0x8b0
  ctl_ioctl+0x72a/0xcb0

Allocated by: linear_ctr -> dm_get_table_device -> table_load
Freed by:     linear_dtr -> dm_table_destroy -> table_load error path

Full stack is in the attached tarball as stacktrace.txt.

Impact
======

Privileged local DoS (CAP_SYS_ADMIN required). Practical exploitation
beyond DoS has not been evaluated; reporting as a privileged memory-safety
bug / DoS in DM core.

Reproducer
==========

Attached: dm-setup-md-queue-uaf-repro.tar.gz

VM-only. Six workers race: create a fresh DM device, concurrent failing
linear table load vs successful error-target load (dm_setup_md_queue runs
while type is DM_TYPE_NONE), then remove.

Quick path (Docker + KVM):

   tar xzf dm-setup-md-queue-uaf-repro.tar.gz
   cd <extracted-dir>
   docker build -t dm-setup-md-queue-uaf -f Dockerfile .
   mkdir -p artifacts
   docker run --rm --privileged --device=/dev/kvm --network=host \
     -v "$PWD/artifacts:/artifacts" \
     -e OUTPUT_DIR=/artifacts \
     -e RUN_TIMEOUT_SEC=240 \
     dm-setup-md-queue-uaf

Expected within ~40s after the PoC starts (first run also builds the
kernel):

   BUG: KASAN: slab-use-after-free in dm_setup_md_queue
   ...
   Kernel panic - not syncing: Fatal exception

Note: a WARNING in bd_unlink_disk_holder / bd_link_disk_holder may appear
first. The attached run.sh omits panic_on_warn=1 so the guest can continue
into the KASAN UAF.

I am happy to test patches. Please let me know if you need more detail.

Thanks,
Yu Junzhe
FuzzAnything <fuzzanything@gmail.com>

[-- Attachment #2: dm-setup-md-queue-uaf-repro.tar.gz --]
[-- Type: application/x-gzip, Size: 9683 bytes --]

                 reply	other threads:[~2026-07-18 13:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=5947c25a-0a1e-4bb2-ad3e-8e4d9ecbd8c2@gmail.com \
    --to=junzheyu1@gmail.com \
    --cc=agk@redhat.com \
    --cc=bmarzins@redhat.com \
    --cc=dm-devel@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpatocka@redhat.com \
    --cc=snitzer@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