Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH v1] exfat: bail prematurely from exfat_extend_valid_size() upon fatal signal
@ 2026-07-13  6:19 David Timber
  2026-07-13  6:53 ` Greg KH
  0 siblings, 1 reply; 6+ messages in thread
From: David Timber @ 2026-07-13  6:19 UTC (permalink / raw)
  To: Namjae Jeon, Sungjong Seo, Yuezhang Mo
  Cc: Andy Wu, Aoyama Wataru, David Timber, stable

commit 82a81a7352bcf5f2756ac33d47ee0582737e9a85 upstream.

If a file in an exfat volume has a large (isize - VDL) gap and userspace
write past a large amount of unwritten clusters, write amplification
occurs. Currently there was no way for userspace to cancel this.

As tasks with pending fatal signal receives preferential treatment in
mm/vmscan.c, if the userspace process is killed during the iteration,
the excessive use of pages in block_write may lead to system instability
and OOM killer activating in vain to free up some pages.

Demo:

	truncate -s 16G /mnt/exfat/file
	dd if=/dev/urandom of=/mnt/exfat/file bs=1 count=1 seek=16G &
	kill -KILL $!

To fix this, add the fatal_signal_pending() check in the loop. This
mirrors the behaviour of iomap variant of exfat. Note that the iomap
exfat implementation is unaffected as the check is already present in
iomap_zero_range().

Fixes: 11a347fb6cef ("exfat: change to get file size from DataLength")
Cc: <stable@vger.kernel.org> # 6.18+
Signed-off-by: David Timber <dxdt@dev.snart.me>
---
 fs/exfat/file.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/fs/exfat/file.c b/fs/exfat/file.c
index 91e5511945d1..4db6a4b773fd 100644
--- a/fs/exfat/file.c
+++ b/fs/exfat/file.c
@@ -656,6 +656,11 @@ static int exfat_extend_valid_size(struct inode *inode, loff_t new_valid_size)
 		struct folio *folio;
 		unsigned long off;
 
+		if (fatal_signal_pending(current)) {
+			err = -EINTR;
+			goto out;
+		}
+
 		len = PAGE_SIZE - (pos & (PAGE_SIZE - 1));
 		if (pos + len > new_valid_size)
 			len = new_valid_size - pos;
@@ -717,13 +722,20 @@ static ssize_t exfat_file_write_iter(struct kiocb *iocb, struct iov_iter *iter)
 
 	if (pos > valid_size) {
 		ret = exfat_extend_valid_size(inode, pos);
-		if (ret < 0 && ret != -ENOSPC) {
-			exfat_err(inode->i_sb,
-				"write: fail to zero from %llu to %llu(%zd)",
-				valid_size, pos, ret);
-		}
-		if (ret < 0)
+		if (ret < 0) {
+			/* Do not report trivial errors. */
+			switch (ret) {
+			case -ENOSPC:
+			case -EINTR:
+				break;
+			default:
+				exfat_err(inode->i_sb,
+					"write: fail to zero from %llu to %llu(%zd)",
+					valid_size, pos, ret);
+			}
+
 			goto unlock;
+		}
 	}
 
 	ret = __generic_file_write_iter(iocb, iter);
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-07-13 12:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-13  6:19 [PATCH v1] exfat: bail prematurely from exfat_extend_valid_size() upon fatal signal David Timber
2026-07-13  6:53 ` Greg KH
2026-07-13  6:56   ` David Timber
2026-07-13  7:55   ` David Timber
2026-07-13 12:05     ` Greg KH
2026-07-13 12:14       ` David Timber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox