mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: liubaolin <liubaolin12138@163.com>
To: Matthias Goergens <matthias.goergens@gmail.com>,
	Namjae Jeon <linkinjeon@kernel.org>,
	Hyunchul Lee <hyc.lee@gmail.com>
Cc: ntfs@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] ntfs: do not use a stale runlist pointer when undoing $MFT extension
Date: Sun, 27 Sep 2026 21:04:26 +0800	[thread overview]
Message-ID: <fa59fd96-5aac-48c1-b949-ea6b6b858cc3@163.com> (raw)
In-Reply-To: <20260927105706.3111333-3-matthias.goergens@gmail.com>



在 2026/9/27 18:57, Matthias Goergens 写道:
> When ntfs_mft_data_extend_allocation_nolock() fails after it has
> rebuilt the mapping pairs of the last $MFT data extent, undo_alloc
> truncates the runlist and then rebuilds the old mapping pairs from rl2,
> a pointer into the runlist taken before the truncation.
> ntfs_rl_truncate_nolock() can reallocate the runlist, and KASAN then
> reports a use-after-free in ntfs_mapping_pairs_build().
> 
> Pass the start of the runlist instead, and hold the runlist lock for
> reading while the mapping pairs are built from it.
> ntfs_mapping_pairs_build() skips to the element containing the first
> vcn by itself.
> 
> Fixes: 1e9ea7e04472 ("Revert "fs: Remove NTFS classic"")
> Cc: stable@vger.kernel.org
> Signed-off-by: Matthias Goergens <matthias.goergens@gmail.com>
> ---
> A forced lookup failure of the first $MFT data extent, on a volume
> whose $MFT has several extents, gives the KASAN report before this
> patch and nothing after it.
> 
>   fs/ntfs/mft.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/ntfs/mft.c b/fs/ntfs/mft.c
> index 58676042444b6..5831ea7600315 100644
> --- a/fs/ntfs/mft.c
> +++ b/fs/ntfs/mft.c
> @@ -2081,11 +2081,16 @@ static int ntfs_mft_data_extend_allocation_nolock(struct ntfs_volume *vol)
>   	if (ctx) {
>   		a = ctx->attr;
>   		if (mp_rebuilt && !IS_ERR(ctx->mrec)) {
> -			if (ntfs_mapping_pairs_build(vol, (u8 *)a + le16_to_cpu(
> +			int err;
> +
> +			down_read(&mft_ni->runlist.lock);
> +			err = ntfs_mapping_pairs_build(vol, (u8 *)a + le16_to_cpu(
>   				a->data.non_resident.mapping_pairs_offset),
>   				old_alen - le16_to_cpu(
>   					a->data.non_resident.mapping_pairs_offset),
> -				rl2, ll, -1, NULL, NULL, NULL)) {
> +				mft_ni->runlist.rl, ll, -1, NULL, NULL, NULL);
> +			up_read(&mft_ni->runlist.lock);
> +			if (err) {
>   				ntfs_error(vol->sb, "Failed to restore mapping pairs array.%s", es);
>   				NVolSetErrors(vol);
>   			}


Looks good to me.

Reviewed-by: Baolin Liu <liubaolin@kylinos.cn>


  reply	other threads:[~2026-09-27 13:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-27 10:57 [PATCH 0/2] ntfs: fix the undo path of $MFT data extension Matthias Goergens
2026-09-27 10:57 ` [PATCH 1/2] ntfs: balance the $MFT runlist lock in data extension error paths Matthias Goergens
2026-09-27 13:03   ` liubaolin
2026-09-28  5:01   ` Hyunchul Lee
2026-09-27 10:57 ` [PATCH 2/2] ntfs: do not use a stale runlist pointer when undoing $MFT extension Matthias Goergens
2026-09-27 13:04   ` liubaolin [this message]
2026-09-27 13:07 ` [PATCH 0/2] ntfs: fix the undo path of $MFT data extension liubaolin

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=fa59fd96-5aac-48c1-b949-ea6b6b858cc3@163.com \
    --to=liubaolin12138@163.com \
    --cc=hyc.lee@gmail.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthias.goergens@gmail.com \
    --cc=ntfs@lists.linux.dev \
    /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®