Skip to contentSkip to conversation

selftests-mm-fix-unchecked-ftruncate-return-value-in-soft-dirty-test.patch removed from -mm tree

merged mm-stable Andrew Morton 1 participant 1 message Aug 25

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: selftests/mm: fix unchecked ftruncate return value in soft-dirty test
has been removed from the -mm tree. Its filename was
selftests-mm-fix-unchecked-ftruncate-return-value-in-soft-dirty-test.patch

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

------------------------------------------------------
From: Anshuman <[email protected]>
Subject: selftests/mm: fix unchecked ftruncate return value in soft-dirty test
Date: Tue, 18 Aug 2026 19:02:06 +0530

test_mprotect() calls ftruncate() to resize the backing file before mmap()'ing it, but never checks the return value. If ftruncate() fails, the file may remain shorter than the requested mapping size. The subsequent mmap() with MAP_SHARED can still succeed in this case, but the very next line writes directly into the mapped memory (*map = 1), which can trigger SIGBUS if the mapping extends beyond the actual file size.

Check the return value and fail cleanly with ksft_exit_fail_msg() if ftruncate() fails, matching the error-handling style already used for the mmap() call immediately below it.

---

 tools/testing/selftests/mm/soft-dirty.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/mm/soft-dirty.c renamed from tools/testing/selftests/mm/soft-dirty.c~selftests-mm-fix-unchecked-ftruncate-return-value-in-soft-dirty-test +2 -1
@@ -152,7 +152,8 @@ static void test_mprotect(int pagemap_fd
 			return;
 		}
 		unlink(fname);
-		ftruncate(test_fd, pagesize);
+		if (ftruncate(test_fd, pagesize) != 0)
+			ksft_exit_fail_msg("ftruncate failed\n");
 		map = mmap(NULL, pagesize, PROT_READ|PROT_WRITE,
 			   MAP_SHARED, test_fd, 0);
 		if (map == MAP_FAILED)

_

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