* + selftests-mm-check-stat-return-value-in-khugepaged-get_finfo.patch added to mm-unstable branch
@ 2026-08-19 20:55 Andrew Morton
0 siblings, 0 replies; only message in thread
From: Andrew Morton @ 2026-08-19 20:55 UTC (permalink / raw)
To: mm-commits, shuah, ljs, david, akpm, anshumantewari123, akpm
The patch titled
Subject: selftests/mm: check stat() return value in khugepaged get_finfo()
has been added to the -mm mm-unstable branch. Its filename is
selftests-mm-check-stat-return-value-in-khugepaged-get_finfo.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/selftests-mm-check-stat-return-value-in-khugepaged-get_finfo.patch
This patch will later appear in the mm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Anshuman <anshumantewari123@gmail.com>
Subject: selftests/mm: check stat() return value in khugepaged get_finfo()
Date: Wed, 19 Aug 2026 17:44:26 +0530
get_finfo() calls stat() to get metadata about the target directory, but
never checks the return value. On failure, stat() returns -1 and leaves
path_stat unmodified, so path_stat.st_mode may contain uninitialized stack
data.
The code then checks S_ISDIR(path_stat.st_mode) against this potentially
garbage value. This can produce a misleading "Not a directory" error when
the real problem is a nonexistent or inaccessible path, or, in the worst
case, the check could pass by chance on garbage data and let the function
continue using an invalid path_stat for the rest of its logic.
Check the return value and fail with a clear error message if stat()
fails, matching the error-handling style already used for statfs() and
read_file() later in the same function.
Link: https://lore.kernel.org/20260819121426.49500-1-anshumantewari123@gmail.com
Signed-off-by: Anshuman <anshumantewari123@gmail.com>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
tools/testing/selftests/mm/khugepaged.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
--- a/tools/testing/selftests/mm/khugepaged.c~selftests-mm-check-stat-return-value-in-khugepaged-get_finfo
+++ a/tools/testing/selftests/mm/khugepaged.c
@@ -124,7 +124,8 @@ static void get_finfo(const char *dir)
char *str, *end;
finfo.dir = dir;
- stat(finfo.dir, &path_stat);
+ if (stat(finfo.dir, &path_stat))
+ ksft_exit_fail_perror("stat()");
if (!S_ISDIR(path_stat.st_mode))
ksft_exit_fail_msg("%s: Not a directory (%s)\n", __func__, finfo.dir);
if (snprintf(finfo.path, sizeof(finfo.path), "%s/" TEST_FILE,
_
Patches currently in -mm which might be from anshumantewari123@gmail.com are
selftests-mm-fix-unchecked-ftruncate-return-value-in-soft-dirty-test.patch
selftests-mm-check-stat-return-value-in-khugepaged-get_finfo.patch
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-08-19 20:55 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-19 20:55 + selftests-mm-check-stat-return-value-in-khugepaged-get_finfo.patch added to mm-unstable branch Andrew Morton
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.