mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-31 09:20:13 -04:00
selftests/mm: add missing mmap() return checks in pkey tests
Add missing checks against mmap() return value, replace (void *)-1 with MAP_FAILED for better readability and consistency. Link: https://lore.kernel.org/20260706081600.3570203-5-lihongfu@kylinos.cn Signed-off-by: Hongfu Li <lihongfu@kylinos.cn> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Acked-by: Liam R. Howlett (Oracle) <liam@infradead.org> Reviewed-by: Kevin Brodsky <kevin.brodsky@arm.com> Tested-by: Kevin Brodsky <kevin.brodsky@arm.com> Cc: David Hildenbrand <david@kernel.org> Cc: Joey Gouly <joey.gouly@arm.com> Cc: John Hubbard <jhubbard@nvidia.com> Cc: Keith Lucas <keith.lucas@oracle.com> Cc: Lorenzo Stoakes <ljs@kernel.org> Cc: Michal Hocko <mhocko@suse.com> Cc: Muhammad Usama Anjum <usama.anjum@collabora.com> Cc: Ross Zwisler <zwisler@google.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Vlastimil Babka <vbabka@kernel.org> Cc: Yury Khrustalev <yury.khrustalev@arm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
@@ -126,7 +126,7 @@ static inline void *malloc_pkey_with_mprotect_subpage(long size, int prot, u16 p
|
||||
size, prot, pkey);
|
||||
pkey_assert(pkey < NR_PKEYS);
|
||||
ptr = mmap(NULL, size, prot, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
|
||||
pkey_assert(ptr != (void *)-1);
|
||||
pkey_assert(ptr != MAP_FAILED);
|
||||
|
||||
ret = syscall(__NR_subpage_prot, ptr, size, NULL);
|
||||
if (ret) {
|
||||
|
||||
@@ -313,6 +313,7 @@ static void test_sigsegv_handler_with_different_pkey_for_stack(void)
|
||||
/* Set up alternate signal stack that will use the default MPK */
|
||||
sigstack.ss_sp = mmap(0, STACK_SIZE, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
pkey_assert(sigstack.ss_sp != MAP_FAILED);
|
||||
sigstack.ss_flags = 0;
|
||||
sigstack.ss_size = STACK_SIZE;
|
||||
|
||||
@@ -488,6 +489,7 @@ static void test_pkru_sigreturn(void)
|
||||
/* Set up alternate signal stack that will use the default MPK */
|
||||
sigstack.ss_sp = mmap(0, STACK_SIZE, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
pkey_assert(sigstack.ss_sp != MAP_FAILED);
|
||||
sigstack.ss_flags = 0;
|
||||
sigstack.ss_size = STACK_SIZE;
|
||||
|
||||
|
||||
@@ -582,7 +582,7 @@ static void *malloc_pkey_with_mprotect(long size, int prot, u16 pkey)
|
||||
size, prot, pkey);
|
||||
pkey_assert(pkey < NR_PKEYS);
|
||||
ptr = mmap(NULL, size, prot, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
|
||||
pkey_assert(ptr != (void *)-1);
|
||||
pkey_assert(ptr != MAP_FAILED);
|
||||
ret = mprotect_pkey((void *)ptr, PAGE_SIZE, prot, pkey);
|
||||
pkey_assert(!ret);
|
||||
record_pkey_malloc(ptr, size, prot);
|
||||
@@ -605,7 +605,7 @@ static void *malloc_pkey_anon_huge(long size, int prot, u16 pkey)
|
||||
*/
|
||||
size = ALIGN_UP(size, HPAGE_SIZE * 2);
|
||||
ptr = mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
|
||||
pkey_assert(ptr != (void *)-1);
|
||||
pkey_assert(ptr != MAP_FAILED);
|
||||
record_pkey_malloc(ptr, size, prot);
|
||||
mprotect_pkey(ptr, size, prot, pkey);
|
||||
|
||||
@@ -663,7 +663,7 @@ static void *malloc_pkey_hugetlb(long size, int prot, u16 pkey)
|
||||
size = ALIGN_UP(size, HPAGE_SIZE * 2);
|
||||
pkey_assert(pkey < NR_PKEYS);
|
||||
ptr = mmap(NULL, size, PROT_NONE, flags, -1, 0);
|
||||
pkey_assert(ptr != (void *)-1);
|
||||
pkey_assert(ptr != MAP_FAILED);
|
||||
mprotect_pkey(ptr, size, prot, pkey);
|
||||
|
||||
record_pkey_malloc(ptr, size, prot);
|
||||
@@ -692,7 +692,7 @@ static void *malloc_pkey(long size, int prot, u16 pkey)
|
||||
pkey_assert(malloc_type < nr_malloc_types);
|
||||
|
||||
ret = pkey_malloc[malloc_type](size, prot, pkey);
|
||||
pkey_assert(ret != (void *)-1);
|
||||
pkey_assert(ret != MAP_FAILED);
|
||||
|
||||
malloc_type++;
|
||||
if (malloc_type >= nr_malloc_types)
|
||||
@@ -1110,6 +1110,7 @@ static void arch_force_pkey_reg_init(void)
|
||||
* doing the XSAVE size enumeration dance.
|
||||
*/
|
||||
buf = mmap(NULL, 1*MB, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
|
||||
pkey_assert(buf != MAP_FAILED);
|
||||
|
||||
/* These __builtins require compiling with -mxsave */
|
||||
|
||||
@@ -1676,7 +1677,8 @@ int main(void)
|
||||
ksft_print_msg("running PKEY tests for unsupported CPU/OS\n");
|
||||
|
||||
ptr = mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
|
||||
assert(ptr != (void *)-1);
|
||||
if (ptr == MAP_FAILED)
|
||||
ksft_exit_fail_perror("mmap");
|
||||
test_mprotect_pkey_on_unsupported_cpu(ptr, 1);
|
||||
ksft_test_result_pass("pkey on unsupported CPU/OS\n");
|
||||
ksft_finished();
|
||||
|
||||
Reference in New Issue
Block a user