From: sashiko-bot@kernel.org
To: "Mikulas Patocka" <mpatocka@redhat.com>,
"Alasdair Kergon" <agk@redhat.com>,
"Mike Snitzer" <snitzer@kernel.org>,
"Benjamin Marzinski" <bmarzins@redhat.com>,
"Ming-Hung Tsai" <mtsai@redhat.com>,
dm-devel@lists.linux.dev
Subject: Re: [PATCH] dm persistent data: assign new_root only when removal succeeds
Date: Mon, 23 Nov 2026 21:15:31 +0000 [thread overview]
Message-ID: <sashiko-outbox-230071@kernel.org> (raw)
In-Reply-To: <66133e69-7c3f-74bf-32b0-fdc9f0fd836c@redhat.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] dm persistent data: lost shadow root on -ENODATA in
remove_one()
--
commit 4eeca185df6005174039047dc72433972f6d625f
Author: Mikulas Patocka <mpatocka@redhat.com>
dm persistent data: assign new_root only when removal succeeds
This commit changes remove_one() to update *new_root only when r is 0, so
that uninitialized spine.root is not read on error.
> diff --git a/drivers/md/persistent-data/dm-btree-remove.c b/drivers/md/persistent-data/dm-btree-remove.c
> index 18f53c6722027..cdcaf36bbc9e9 100644
> --- a/drivers/md/persistent-data/dm-btree-remove.c
> +++ b/drivers/md/persistent-data/dm-btree-remove.c
> @@ -755,7 +755,8 @@ static int remove_one(struct dm_btree_info *info, dm_block_t root,
> r = -ENODATA;
>
> out:
> - *new_root = shadow_root(&spine);
> + if (!r)
> + *new_root = shadow_root(&spine);
> exit_shadow_spine(&spine);
>
> return r;
[Severity: High]
Does skipping *new_root = shadow_root(&spine) when r == -ENODATA leak the
new shadow root block and leave *new_root pointing to a freed block?
remove_one() only sets r = -ENODATA after remove_raw() and
remove_nearest() have already called shadow_step() on root. If root was
not already in the transaction manager's shadow table (for example, on the
first iteration of dm_btree_remove_leaves() when no key lies in the target
range, or after insert_shadow() silently drops a GFP_NOIO allocation),
__shadow_block() allocates a new block for spine.root and decrements the
old root block's reference count.
Because dm_btree_remove_leaves() treats -ENODATA as normal completion:
drivers/md/persistent-data/dm-btree-remove.c:dm_btree_remove_leaves() {
do {
r = remove_one(info, root, first_key, end_key, &root, nr_removed);
if (!r)
(*nr_removed)++;
} while (!r);
*new_root = root;
return r == -ENODATA ? 0 : r;
}
not updating *new_root on -ENODATA discards the newly allocated shadow
root and returns 0 with *new_root still referencing the old root block
whose space-map reference count was already decremented. Checking
if (!r || r == -ENODATA) would avoid reading an uninitialized spine.root
on I/O errors while preserving the shadowed root on -ENODATA.
--
Sashiko AI review · https://sashiko.dev/#/patchset/66133e69-7c3f-74bf-32b0-fdc9f0fd836c@redhat.com?part=1
prev parent reply other threads:[~2026-11-23 21:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 20:55 [PATCH] dm persistent data: assign new_root only when removal succeeds Mikulas Patocka
2026-11-23 21:15 ` 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-230071@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