From: sashiko-bot@kernel.org
To: "Mikulas Patocka" <mpatocka@redhat.com>,
"Ming Hung Tsai" <mtsai@redhat.com>,
"Alasdair Kergon" <agk@redhat.com>,
"Mike Snitzer" <snitzer@kernel.org>,
"Benjamin Marzinski" <bmarzins@redhat.com>
Cc: dm-devel@lists.linux.dev
Subject: Re: [PATCH] dm: fix use-after-free when dm_get_device() widens the open mode
Date: Fri, 06 Nov 2026 19:08:40 +0000 [thread overview]
Message-ID: <sashiko-outbox-202135@kernel.org> (raw)
In-Reply-To: <7acdd5f5-72bd-1fc2-cf90-26c9c2a16ba8@redhat.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] dm: missing Fixes trailer for commit 86f1152b117a in commit
message
- [Low] dm: commit message claim about table_device->count contradicts
code
--
commit 16907af74a028c1489b22d6e8c7c48ae64949725
Author: Ming-Hung Tsai <mtsai@redhat.com>
> dm: fix use-after-free when dm_get_device() widens the open mode
>
> There's an UAF bug in dm_get_device(): when a table construction calls
> dm_get_device() on the same device twice with widen access mode (e.g.,
> read-only first then read-write), the second dm_get_device() calls
> upgrade_mode(), which reopens the device in upgraded mode, making
> previously returned dm_dev* a stale pointer.
>
> Fixing approaches:
> - Add per-mode views (dm_dev_ref) from a per-device dm_dev_internal to
> multiple table_devices.
> - Keep reusing the dm_dev_ref when the requested mode is included, i.e.,
> a read-only reference can reuse the read-write opened device within a
> table.
> - Maintain a canonical block_device pointer in dm_dev_internal for
> handling the DM_TABLE_DEPS ioctl.
>
> Also tweak the way of mode sharing check in find_ref() to
> "(x & mask) == mask". The result stays the same to the previous
> upgrade_mode() guard "(x | mask) == x".
>
> Pros: keep the relationship between dm_dev_internal and table_device:
> one dm_dev_internal per device, regardless the mode, so the output of
> DMM_TABLE_DEPS ioctl unchanged.
>
> Cons: extra dm_dev_ref allocation.
>
> Note that now the table_device's count not necessarily mean the number
> tables referecing this <dev, mode> pair, since we're allowing multiple
> references within a table.
[Severity: Low]
Is the closing note about table_device->count accurate? In
dm_get_device(), find_ref() reuses an existing dm_dev_ref whenever its
mode covers the requested mode, so a table still holds at most one
dm_dev_ref (and one reference to the table_device) for any given
<dev, mode> pair, as the comment on struct dm_dev_ref in
drivers/md/dm.h notes.
>
> Signed-off-by: Ming Hung Tsai <mtsai@redhat.com>
> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
> Cc: stable@vger.kernel.org
[Severity: Low]
Since 86f1152b117a ("dm: allow active and inactive tables to share
dm_devs") changed upgrade_mode() to replace dd->dm_dev and drop the old
table_device reference while earlier targets in the table still held it,
should this include:
Fixes: 86f1152b117a ("dm: allow active and inactive tables to share dm_devs")
--
Sashiko AI review · https://sashiko.dev/#/patchset/7acdd5f5-72bd-1fc2-cf90-26c9c2a16ba8@redhat.com?part=1
prev parent reply other threads:[~2026-11-06 19:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 18:59 [PATCH] dm: fix use-after-free when dm_get_device() widens the open mode Mikulas Patocka
2026-11-06 19:08 ` sashiko-bot [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=sashiko-outbox-202135@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agk@redhat.com \
--cc=bmarzins@redhat.com \
--cc=dm-devel@lists.linux.dev \
--cc=mpatocka@redhat.com \
--cc=mtsai@redhat.com \
--cc=sashiko-reviews@lists.linux.dev \
--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