On Wed, May 27, 2026 at 7:06 AM Michael Tokarev <[email protected]> wrote:
>
> On 21.05.2026 21:41, Matt Turner wrote:
> > mips64/elfload.c uses #include "../mips/elfload.c" to share code. When
> > the compiler processes mips/elfload.c the quoted #include "target_elf.h"
> > resolves relative to the including file's directory, so it picks up
> > mips/target_elf.h instead of mips64/target_elf.h.  mips/target_elf.h
> > pulls in mips/target_ptrace.h, whose target_pt_regs has a pad0[6] field
> > before regs[].  As a result elf_core_copy_regs writes:
> >
> >    r->pt.regs[i]   -> reserved[6+i]   (shifted by 6 from the correct index)
> >    r->pt.cp0_epc   -> reserved[40]    (correct mips64 N64 index is 34)
> >
> > The Linux kernel and glibc both use the mips64 N64 layout (no pad0): EPC
> > at reserved[34].  Debuggers and libunwind reading the core with N64
> > constants therefore see a completely wrong register set — EPC points to
> > GP, RA holds the branch target instead of the link address, etc.
> >
> > Fix by:
> >   - Guarding the mips32 elf_core_copy_regs in mips/elfload.c with #ifndef
> >     TARGET_MIPS64 so it is not compiled for mips64/mipsn32 targets.
> >   - Providing a mips64-specific elf_core_copy_regs in mips64/elfload.c
> >     that writes directly to r->reserved[i] with the correct N64 indices,
> >     bypassing the struct field names that are tainted by the wrong header
> >     include.
> >
> > The mipsn32 (TARGET_ABI_MIPSN32) and mips64el targets are covered by the
> > same mips64/elfload.c and benefit from the same fix.
>
> This code was different before the linux/elfload.c split into targets -
> before the split, all this was in single linux/elfload.c file.  While
> this patch should not be needed before the split (eg. for stable-10.0
> branch), the following patch is apparently needed still.
>
> Can you verify please, and maybe provide a similar fix for 10.0.x too -
> provided it's actually needed there?

I just took a look at this.

10.2 & 11.0: clean cherry-picks.

10.0 & 10.1: not affected by any of the issues fixed in this series.
Looks like all the issues were introduced by commit a8081da18d
("linux-user: Move elf_core_copy_regs to mips/elfload.c"). If I'd
realized that beforehand I would have inserted a Fixes: tag and saved
you the email :)

Thanks,
Matt

Reply via email to