mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhan Xusheng <zhanxusheng1024@gmail.com>
To: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Cc: ntfs3@lists.linux.dev, linux-kernel@vger.kernel.org,
	Zhan Xusheng <zhanxusheng@xiaomi.com>,
	stable@vger.kernel.org
Subject: [PATCH] fs/ntfs3: fix cluster over-free on allocation failure
Date: Fri, 23 Oct 2026 10:34:24 +0800	[thread overview]
Message-ID: <20261023023424.4003943-1-zhanxusheng1024@gmail.com> (raw)

From: Zhan Xusheng <zhanxusheng@xiaomi.com>

ntfs_look_for_free_space() returns in @flen how many clusters it marked
used, which is fewer than the requested @len whenever wnd_find() falls
back to the longest free run it could find.  That run is maximal, so the
cluster just past it is in use.  The undo path after a failed
run_add_entry() frees @len, releasing clusters that are still referenced,
and a later allocation can hand them out again.

run_add_entry() fails only when its kvmalloc() does.

Commit 0e5b044cbf3a ("fs/ntfs3: Refactoring attr_set_size to restore
after errors") replaced wnd_set_free(wnd, lcn, flen) here with
mark_as_free_ex(sbi, lcn, len, false).  Use @flen again.

Fixes: 0e5b044cbf3a ("fs/ntfs3: Refactoring attr_set_size to restore after errors")
Cc: stable@vger.kernel.org
Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
---
 fs/ntfs3/attrib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ntfs3/attrib.c b/fs/ntfs3/attrib.c
index b1c315206ffa..fefd201809a5 100644
--- a/fs/ntfs3/attrib.c
+++ b/fs/ntfs3/attrib.c
@@ -199,7 +199,7 @@ int attr_allocate_clusters(struct ntfs_sb_info *sbi, struct runs_tree *run,
 		if (!run_add_entry(run, vcn, lcn, flen, opt & ALLOCATE_MFT)) {
 undo_alloc:
 			/* Undo last 'ntfs_look_for_free_space' */
-			mark_as_free_ex(sbi, lcn, len, false);
+			mark_as_free_ex(sbi, lcn, flen, false);
 			err = -ENOMEM;
 			goto out;
 		}

base-commit: 3ac032ef6ca8e47bb06d1e189dfcf88fa0a09c75
-- 
2.43.0


                 reply	other threads:[~2026-10-23  2:34 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=20261023023424.4003943-1-zhanxusheng1024@gmail.com \
    --to=zhanxusheng1024@gmail.com \
    --cc=almaz.alexandrovich@paragon-software.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ntfs3@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=zhanxusheng@xiaomi.com \
    /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®