Skip to contentSkip to conversation

fat-hold-truncate_lock-in-fat_write_failed.patch removed from -mm tree

merged mm-nonmm-hotfixes-stable Andrew Morton 1 participant 1 message Nov 3 Stable branch

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: fat: hold truncate_lock in fat_write_failed()
has been removed from the -mm tree. Its filename was
fat-hold-truncate_lock-in-fat_write_failed.patch

This patch was dropped because it was merged into the mm-nonmm-hotfixes-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Matheus Alves de Almeida <[email protected]>
Subject: fat: hold truncate_lock in fat_write_failed()
Date: Wed, 21 Oct 2026 13:21:04 -0300

The current fat_write_failed() implementation calls into fat_truncate_blocks() without holding truncate_lock.

A failed or short extending write racing with FIBMAP can spuriously make a FAT filesystem read-only. FIBMAP bounds its lookup by i_blocks, so it can walk allocated clusters beyond i_size while fat_write_failed() is removing them. If the chain is shortened during the walk, the mapper can report a bogus "request beyond EOF" error, triggering the default read-only error policy. Hold truncate_lock for write around the block cleanup to serialize it with _fat_bmap().

For comparison, fat_setattr() correctly holds truncate_lock during truncation:

	down_write(&MSDOS_I(inode)->truncate_lock);
	truncate_setsize(inode, attr->ia_size);
	fat_truncate_blocks(inode, attr->ia_size);
	up_write(&MSDOS_I(inode)->truncate_lock);

Make it so ->truncate_lock is held exclusive while truncating.

Fixes 16fab2015099 ("fat: permit to return phy block number by fibmap in fallocated region")
Fixes 459f6ed3b8c7 ("fat: convert to use the new truncate convention.")
Cc Pedro Falcato <[email protected]>

---

 fs/fat/inode.c |    2 ++
 1 file changed, 2 insertions(+)
fs/fat/inode.c renamed from fs/fat/inode.c~fat-hold-truncate_lock-in-fat_write_failed +2 -0
@@ -217,7 +217,9 @@ static void fat_write_failed(struct addr
 
 	if (to > inode->i_size) {
 		truncate_pagecache(inode, inode->i_size);
+		down_write(&MSDOS_I(inode)->truncate_lock);
 		fat_truncate_blocks(inode, inode->i_size);
+		up_write(&MSDOS_I(inode)->truncate_lock);
 	}
 }
 

_

Patches currently in -mm which might be from [email protected] are

fat-batch-synchronous-mirror-writes.patch
fat-improve-fat_sync_bhs-write-submission.patch