summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatheus Alves de Almeida <matheus.aalmeida@inf.ufrgs.br>2026-10-21 13:21:04 -0300
committerAndrew Morton <akpm@linux-foundation.org>2026-11-02 19:18:56 -0800
commit7b90009546f5d3f3ac9428040cd7ffbdfd60f2eb (patch)
treea1f042960deb04124ceca1273c15e197564406e1
parent4bdfe8dd2342f9c2bdc3b788699164ebe21d9126 (diff)
fat: hold truncate_lock in fat_write_failed()
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. Link: https://lore.kernel.org/20261021162105.62525-1-matheus.aalmeida@inf.ufrgs.br Fixes: 16fab2015099 ("fat: permit to return phy block number by fibmap in fallocated region") Fixes: 459f6ed3b8c7 ("fat: convert to use the new truncate convention.") Signed-off-by: Matheus Alves de Almeida <matheus.aalmeida@inf.ufrgs.br> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> Cc: Pedro Falcato <pfalcato@suse.de> Cc: <stable@vger.kernel.org>
-rw-r--r--fs/fat/inode.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index d85c8fbdcca4..353c91f0a843 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -217,7 +217,9 @@ static void fat_write_failed(struct address_space *mapping, loff_t to)
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);
}
}