]> git.hungrycats.org Git - linux/commitdiff
arm64: compat: Fix decrementing LDM/STM alignment emulation
authorKarl Mehltretter <kmehltretter@gmail.com>
Wed, 19 Aug 2026 22:27:12 +0000 (00:27 +0200)
committerWill Deacon <will@kernel.org>
Thu, 27 Aug 2026 14:16:04 +0000 (14:16 +0000)
The compat alignment emulator inherited unsigned long data addresses from
the 32-bit ARM implementation.

In do_alignment_ldmstm(), nr_regs is an unsigned int holding the transfer
size. The function uses the same address addition for both transfer
directions, negating nr_regs first for a decrementing LDM or STM. The
32-bit negation wraps before the addition, so the handler adds nearly
4 GiB instead of subtracting the transfer size.
The resulting address lies outside the compat task's address space, so
decrementing LDM/STM emulation fails, while incrementing forms work.

For example, a backwards-moving copy routine using decrementing LDM/STM can
take an alignment fault when called with unaligned pointers. The compat
handler should emulate the transfer, but this bug instead causes SIGBUS.

The offset negated in do_alignment_finish_ldst() is offset_union.un, which
is already unsigned long and does not have this width mismatch.

Make nr_regs unsigned long so its negation and the address arithmetic
use the same width.

Fixes: 3fc24ef32d3b ("arm64: compat: Implement misalignment fixups for multiword loads")
Cc: stable@vger.kernel.org
Suggested-by: Arnd Bergmann <arnd@arndb.de>
Assisted-by: Codex:gpt-5.6-sol
Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
Signed-off-by: Will Deacon <will@kernel.org>
arch/arm64/kernel/compat_alignment.c

index b68e1d328d4cb9b33d2e959b94225fe8fdb12769..9b58d0aa38d22556a8f0d7becf3570b95de951c5 100644 (file)
@@ -114,8 +114,8 @@ do_alignment_ldrdstrd(unsigned long addr, u32 instr, struct pt_regs *regs)
 static int
 do_alignment_ldmstm(unsigned long addr, u32 instr, struct pt_regs *regs)
 {
-       unsigned int rd, rn, nr_regs, regbits;
-       unsigned long eaddr, newaddr;
+       unsigned int rd, rn, regbits;
+       unsigned long eaddr, newaddr, nr_regs;
        unsigned int val;
 
        /* count the number of registers in the mask to be transferred */