]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
selftests/mm: fix incorrect mmap() error handling with NULL instead of MAP_FAILED
authorHongfu Li <lihongfu@kylinos.cn>
Wed, 13 May 2026 02:52:23 +0000 (10:52 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Sun, 21 Jun 2026 18:37:31 +0000 (11:37 -0700)
commita179686b917ca30232cb70eb4408d34d9de3814d
treefdc30cfa67a193a99c6cf8ab09a01aee3c9c898e
parentb89a641056227403bf54847caf228b8a607c5fc4
selftests/mm: fix incorrect mmap() error handling with NULL instead of MAP_FAILED

mmap() returns MAP_FAILED, which is defined as (void *)-1, on error, not
NULL.  Several selftests incorrectly check the return value of mmap()
using !ptr or ptr == NULL, which would erroneously treat MAP_FAILED as a
valid pointer since MAP_FAILED is non-zero and non-NULL.  This can lead to
segfaults when mmap() actually fails under memory pressure.

Link: https://lore.kernel.org/20260513025223.592766-1-lihongfu@kylinos.cn
Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>
Reviewed-by: Dev Jain <dev.jain@arm.com>
Reviewed-by: Lorenzo Stoakes <ljs@kernel.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
tools/testing/selftests/mm/ksm_tests.c
tools/testing/selftests/mm/madv_populate.c
tools/testing/selftests/mm/soft-dirty.c
tools/testing/selftests/mm/vm_util.c