From: Andrew Morton <akpm@linux-foundation.org>
To: mm-commits@vger.kernel.org,sj@kernel.org,shuah@kernel.org,david@kernel.org,yanlonglong@kylinos.cn,akpm@linux-foundation.org
Subject: [merged mm-stable] selftests-mm-pagemap_ioctl-fix-missing-null-checks-after-calloc.patch removed from -mm tree
Date: Thu, 06 Aug 2026 19:02:19 -0700 [thread overview]
Message-ID: <20260807020219.80E171F000E9@smtp.kernel.org> (raw)
The quilt patch titled
Subject: selftests/mm/pagemap_ioctl: fix missing NULL checks after calloc()
has been removed from the -mm tree. Its filename was
selftests-mm-pagemap_ioctl-fix-missing-null-checks-after-calloc.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: longlong yan <yanlonglong@kylinos.cn>
Subject: selftests/mm/pagemap_ioctl: fix missing NULL checks after calloc()
Date: Tue, 21 Jul 2026 14:36:11 +0800
The pagemap_ioctl selftest allocates memory via calloc() in several places
but does not check the return values. If calloc() fails, the subsequent
code will dereference a NULL pointer and crash.
Additionally, in sanity_tests(), the calloc() failure check incorrectly
uses MAP_FAILED (the mmap() error constant) instead of NULL. Since
calloc() returns NULL on failure, the check never triggers and a failed
allocation goes undetected.
Add NULL checks after each calloc() call, and fix the wrong error constant
in sanity_tests(). Use ksft_exit_fail_msg() consistent with the existing
error handling pattern in the file.
Link: https://lore.kernel.org/20260721063611.342-1-yanlonglong@kylinos.cn
Signed-off-by: longlong yan <yanlonglong@kylinos.cn>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: SJ Park <sj@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
tools/testing/selftests/mm/pagemap_ioctl.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
--- a/tools/testing/selftests/mm/pagemap_ioctl.c~selftests-mm-pagemap_ioctl-fix-missing-null-checks-after-calloc
+++ a/tools/testing/selftests/mm/pagemap_ioctl.c
@@ -213,6 +213,8 @@ int userfaultfd_tests(void)
vec_size = mem_size/page_size;
vec = calloc(vec_size, sizeof(struct page_region));
+ if (!vec)
+ ksft_exit_fail_msg("error nomem\n");
written = pagemap_ioctl(mem, mem_size, vec, 1, PM_SCAN_WP_MATCHING | PM_SCAN_CHECK_WPASYNC,
vec_size - 2, PAGE_IS_WRITTEN, 0, 0, PAGE_IS_WRITTEN);
@@ -700,6 +702,8 @@ int base_tests(char *prefix, char *mem,
vec_size = mem_size/page_size;
vec = calloc(vec_size, sizeof(struct page_region));
vec2 = calloc(vec_size, sizeof(struct page_region));
+ if (!vec || !vec2)
+ ksft_exit_fail_msg("error nomem\n");
/* 1. all new pages must be not be written (dirty) */
written = pagemap_ioctl(mem, mem_size, vec, 1, PM_SCAN_WP_MATCHING | PM_SCAN_CHECK_WPASYNC,
@@ -1001,6 +1005,8 @@ int unmapped_region_tests(void)
int written, len = 0x00040000;
long vec_size = len / page_size;
struct page_region *vec = calloc(vec_size, sizeof(struct page_region));
+ if (!vec)
+ ksft_exit_fail_msg("error nomem\n");
/* 1. Get written pages */
written = pagemap_ioctl(start, len, vec, vec_size, 0, 0,
@@ -1163,7 +1169,7 @@ int sanity_tests(void)
vec = calloc(vec_size, sizeof(struct page_region));
mem = mmap(NULL, mem_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
- if (mem == MAP_FAILED || vec == MAP_FAILED)
+ if (mem == MAP_FAILED || !vec)
ksft_exit_fail_msg("error nomem\n");
wp_init(mem, mem_size);
_
Patches currently in -mm which might be from yanlonglong@kylinos.cn are
reply other threads:[~2026-08-07 2:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260807020219.80E171F000E9@smtp.kernel.org \
--to=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=mm-commits@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=sj@kernel.org \
--cc=yanlonglong@kylinos.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.