mirror-linux/tools/testing/selftests/mm
Wake Liu 632b874d59 selftests/mm: fix thread state check in uffd-unit-tests
In the thread_state_get() function, the logic to find the thread's state
character was using `sizeof(header) - 1` to calculate the offset from the
"State:\t" string.

The `header` variable is a `const char *` pointer.  `sizeof()` on a
pointer returns the size of the pointer itself, not the length of the
string literal it points to.  This makes the code's behavior dependent on
the architecture's pointer size.

This bug was identified on a 32-bit ARM build (`gsi_tv_arm`) for Android,
running on an ARMv8-based device, compiled with Clang 19.0.1.

On this 32-bit architecture, `sizeof(char *)` is 4.  The expression
`sizeof(header) - 1` resulted in an incorrect offset of 3, causing the
test to read the wrong character from `/proc/[tid]/status` and fail.

On 64-bit architectures, `sizeof(char *)` is 8, so the expression
coincidentally evaluates to 7, which matches the length of "State:\t". 
This is why the bug likely remained hidden on 64-bit builds.

To fix this and make the code portable and correct across all
architectures, this patch replaces `sizeof(header) - 1` with
`strlen(header)`.  The `strlen()` function correctly calculates the
string's length, ensuring the correct offset is always used.

Link: https://lkml.kernel.org/r/20251210091408.3781445-1-wakel@google.com
Fixes: f60b6634cd ("mm/selftests: add a test to verify mmap_changing race with -EAGAIN")
Signed-off-by: Wake Liu <wakel@google.com>
Acked-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: Bill Wendling <morbo@google.com>
Cc: Justin Stitt <justinstitt@google.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2025-12-23 11:23:14 -08:00
..
page_frag mm: page_frag: fix a compile error when kernel is not compiled 2024-11-19 12:20:40 +01:00
.gitignore selftests/mm: test that rmap behaves as expected 2025-09-13 16:55:13 -07:00
Makefile selftests/mm: add -Wunreachable-code and fix warnings 2025-09-21 14:22:34 -07:00
charge_reserved_hugetlb.sh selftests/mm: generate a temporary mountpoint for cgroup filesystem 2025-04-11 17:32:37 -07:00
check_config.sh
compaction_test.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
config selftests/mm: add configs to fix testcase failure 2025-06-19 20:48:02 -07:00
cow.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
droppable.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
guard-regions.c Significant patch series in this pull request: 2025-12-06 14:01:20 -08:00
gup_longterm.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
gup_test.c Significant patch series in this pull request: 2025-12-06 14:01:20 -08:00
hmm-tests.c Significant patch series in this pull request: 2025-12-06 14:01:20 -08:00
hugepage-mmap.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
hugepage-mremap.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
hugepage-shm.c selftests/mm: remove unnecessary ia64 code and comment 2024-09-03 21:15:38 -07:00
hugepage-vmemmap.c selftests/mm: remove unnecessary ia64 code and comment 2024-09-03 21:15:38 -07:00
hugetlb-madvise.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
hugetlb-read-hwpoison.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
hugetlb-soft-offline.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
hugetlb_dio.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
hugetlb_fault_after_madv.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
hugetlb_madv_vs_map.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
hugetlb_reparenting_test.sh selftests/mm: restore default nr_hugepages value during cleanup in hugetlb_reparenting_test.sh 2025-05-11 17:48:29 -07:00
khugepaged.c selftests/mm: remove PROT_EXEC req from file-collapse tests 2025-09-21 14:22:31 -07:00
ksm_functional_tests.c Significant patch series in this pull request: 2025-12-06 14:01:20 -08:00
ksm_tests.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
madv_populate.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
map_fixed_noreplace.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
map_hugetlb.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
map_populate.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
mdwe_test.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
memfd_secret.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
merge.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
migration.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
mkdirty.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
mlock-random-test.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
mlock2-tests.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
mlock2.h selftests/mm/mlock: print error on failure 2025-03-16 22:06:40 -07:00
mrelease_test.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
mremap_dontunmap.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
mremap_test.c Significant patch series in this pull request: 2025-12-06 14:01:20 -08:00
mseal_helpers.h selftests/mm: mseal, self_elf: rename TEST_END_CHECK to REPORT_TEST_PASS 2024-07-03 19:30:07 -07:00
mseal_test.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
on-fault-limit.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
pagemap_ioctl.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
pfnmap.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
pkey-arm64.h selftests/mm: rename pkey register macro 2025-01-13 22:40:56 -08:00
pkey-helpers.h selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
pkey-powerpc.h selftests/mm: fix a build failure on powerpc 2025-05-07 23:39:41 -07:00
pkey-x86.h selftests/mm: ensure pkey-*.h define inline functions only 2025-01-13 22:40:55 -08:00
pkey_sighandler_tests.c selftests/mm: add -Wunreachable-code and fix warnings 2025-09-21 14:22:34 -07:00
pkey_util.c selftests/mm: fix build break when compiling pkey_util.c 2025-05-07 23:39:41 -07:00
prctl_thp_disable.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
process_madv.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
protection_keys.c selftests/mm: protection_keys: fix dead code 2025-09-21 14:22:34 -07:00
rmap.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
run_vmtests.sh selftests/mm: gup_tests: option to GUP all pages in a single call 2025-09-21 14:22:33 -07:00
settings selftests/mm: increase timeout from 180 to 900 seconds 2025-06-19 20:48:01 -07:00
soft-dirty.c Significant patch series in this pull request: 2025-12-06 14:01:20 -08:00
split_huge_page_test.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
test_hmm.sh
test_page_frag.sh mm: page_frag: add a test module for page_frag 2024-11-11 10:56:26 -08:00
test_vmalloc.sh kselftest: mm: fix typos in test_vmalloc.sh 2025-09-13 16:55:16 -07:00
thp_settings.c selftests: prctl: introduce tests for disabling THPs completely 2025-09-13 16:55:06 -07:00
thp_settings.h selftests: prctl: introduce tests for disabling THPs completely 2025-09-13 16:55:06 -07:00
thuge-gen.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
transhuge-stress.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
uffd-common.c selftests/mm/uffd: remove static address usage in shmem_allocate_area() 2025-11-20 13:44:00 -08:00
uffd-common.h selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
uffd-stress.c selftests/mm/uffd: initialize char variable to Null 2025-11-29 10:41:09 -08:00
uffd-unit-tests.c selftests/mm: fix thread state check in uffd-unit-tests 2025-12-23 11:23:14 -08:00
uffd-wp-mremap.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
va_high_addr_switch.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
va_high_addr_switch.sh selftests/mm: alloc hugepages in va_high_addr_switch test 2025-09-21 14:22:28 -07:00
virtual_address_range.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
vm_util.c Significant patch series in this pull request: 2025-12-06 14:01:20 -08:00
vm_util.h Significant patch series in this pull request: 2025-12-06 14:01:20 -08:00
write_hugetlb_memory.sh
write_to_hugetlbfs.c selftests/mm: fix strncpy() length 2025-01-13 22:40:54 -08:00