[PATCH 2/4] arm64: elf: clear MMF_USER_HWCAP on architecture switch
Andrei Vagin <[email protected]> Mon, 23 Mar 2026 17:53:38 +0000
| Newsgroups | dev.linux.lists.criu,org.infradead.lists.linux-arm-kernel,org.kernel.vger.linux-fsdevel,org.kernel.vger.linux-kernel,org.kvack.linux-mm |
|---|---|
| Message-ID | <[email protected]> |
The HWCAP bits have different meanings between AArch64 and AArch32, so HWCAP inheritance is not applicable when switching architectures. Inherited HWCAP vectors can lead to unpredictable side effects. For example, bit 0 in AArch64 signifies FP support, whereas in AArch32 it signifies SWP instruction support. Fix this by clearing the MMF_USER_HWCAP flag in SET_PERSONALITY and COMPAT_SET_PERSONALITY if the architecture is changing. This ensures that create_elf_tables() will use the default kernel HWCAPs for the new process. Signed-off-by: Andrei Vagin <[email protected]> --- arch/arm64/include/asm/elf.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h index d2779d604c7b..2049d42e2e6a 100644 --- a/arch/arm64/include/asm/elf.h +++ b/arch/arm64/include/asm/elf.h @@ -160,7 +160,10 @@ typedef struct user_fpsimd_state elf_fpregset_t; #define SET_PERSONALITY(ex) \ ({ \ - clear_thread_flag(TIF_32BIT); \ + if (test_thread_flag(TIF_32BIT)) { \ + mm_flags_clear(MMF_USER_HWCAP, current->mm); \ + clear_thread_flag(TIF_32BIT); \ + } \ current->personality &= ~READ_IMPLIES_EXEC; \ }) @@ -223,8 +226,11 @@ int compat_elf_check_arch(const struct elf32_hdr *); */ #define COMPAT_SET_PERSONALITY(ex) \ ({ \ - set_thread_flag(TIF_32BIT); \ - }) + if (!test_thread_flag(TIF_32BIT)) { \ + mm_flags_clear(MMF_USER_HWCAP, current->mm); \ + set_thread_flag(TIF_32BIT); \ + } \ +}) #ifdef CONFIG_COMPAT_VDSO #define COMPAT_ARCH_DLINFO \ do { \ -- 2.53.0.983.g0bb29b3bc5-goog