The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Wesley Atwell <atwellwea@gmail.com>
To: Yuezhang Mo <yuezhang.mo@sony.com>,
	Sungjong Seo <sj1557.seo@samsung.com>,
	Namjae Jeon <linkinjeon@kernel.org>
Cc: exfat@lists.linux.dev, Wesley Atwell <atwellwea@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH] exfat: free directory cluster when zeroing fails
Date: Sat, 28 Nov 2026 14:19:21 -0700	[thread overview]
Message-ID: <kernel-7be3083ed7a0fec5-v1.atwellwea@gmail.com> (raw)

When a synchronous exFAT directory needs another cluster,
exfat_find_empty_entry() allocates one and zeroes it before linking it
into the directory. If the zeroing write fails, the function returns an
error but leaves the new cluster allocated. The directory has not grown,
so the cluster is unreachable and its space remains unavailable.

In a QEMU guest on the exFAT dev tree, a tar extraction to a dirsync
volume hit a targeted block write error while extending a directory.
Tar reported EIO and the new file was absent, but the allocation bitmap
showed one extra 4 KiB cluster in use after remount. The default
fsck.exfat check and repair both called the volume clean.

Free the newly allocated cluster on the zeroing error and return that
error, as exfat_alloc_new_dir() already does for the analogous path.
The healthy extraction still grows the directory. With the fix, the
failed extraction still reports EIO but the bitmap returns to its
original free-cluster count after remount.

OpenAI Codex identified the missing rollback, drafted the fix and
changelog, and prepared the QEMU tar extraction tests. Both kernels
passed the healthy extraction. Under the injected write error, the fix
preserved EIO and restored the original free-cluster count after
remount.

Fixes: 5f2aa075070c ("exfat: add inode operations")
Signed-off-by: Wesley Atwell <atwellwea@gmail.com>
---
 fs/exfat/namei.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c
index 307a2130406e..d077051e7ea2 100644
--- a/fs/exfat/namei.c
+++ b/fs/exfat/namei.c
@@ -345,8 +345,11 @@ int exfat_find_empty_entry(struct inode *inode,
 		if (ret)
 			return ret;
 
-		if (exfat_zeroed_cluster(inode, clu.dir))
-			return -EIO;
+		ret = exfat_zeroed_cluster(inode, clu.dir);
+		if (ret) {
+			exfat_free_cluster(inode, &clu);
+			return ret;
+		}
 
 		if (ei->start_clu == EXFAT_EOF_CLUSTER) {
 			ei->start_clu = clu.dir;

base-commit: 36edb65f309977762fc001c17dcab748bad4b7c1

                 reply	other threads:[~2026-11-28 21:19 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=kernel-7be3083ed7a0fec5-v1.atwellwea@gmail.com \
    --to=atwellwea@gmail.com \
    --cc=exfat@lists.linux.dev \
    --cc=linkinjeon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sj1557.seo@samsung.com \
    --cc=yuezhang.mo@sony.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