* [PATCH] x86: uapi: ptrace: guard register offset macros with __ASSEMBLER__ or __FRAME_OFFSETS @ 2026-08-21 22:45 Nick Desaulniers 2026-09-01 21:45 ` Nick Desaulniers 0 siblings, 1 reply; 4+ messages in thread From: Nick Desaulniers @ 2026-08-21 22:45 UTC (permalink / raw) To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, Richard Weinberger, Anton Ivanov, Johannes Berg, Oleg Nesterov, Nathan Chancellor, Bill Wendling, Justin Stitt Cc: linux-kernel, linux-um, llvm, Nick Desaulniers The register offset macros in <asm/ptrace-abi.h> are guarded by `defined(__ASSEMBLER__) || defined(__FRAME_OFFSETS)` for 64-bit, but were left unguarded for 32-bit. This causes havoc for userspace that happens to use identifiers colliding with these short macro names (e.g., EBX, ECX, EAX, DS, ES, FS, GS, CS, SS). Without this guard, userspace is forced to be super extra careful with include ordering to minimize the chance of collision. Wrap both the 32-bit and 64-bit register definitions under `#if defined(__ASSEMBLER__) || defined(__FRAME_OFFSETS)`, and ensure User-Mode Linux (UML) defines `__FRAME_OFFSETS` for 32-bit as well. Assisted-by: Gemini Link: https://github.com/llvm/llvm-project/issues/217413 Signed-off-by: Nick Desaulniers <ndesaulniers@google.com> --- arch/x86/include/uapi/asm/ptrace-abi.h | 4 ++-- arch/x86/um/asm/ptrace.h | 4 +--- arch/x86/um/ptrace_32.c | 1 + 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h index 5823584dea13..3656955c6faa 100644 --- a/arch/x86/include/uapi/asm/ptrace-abi.h +++ b/arch/x86/include/uapi/asm/ptrace-abi.h @@ -2,6 +2,7 @@ #ifndef _ASM_X86_PTRACE_ABI_H #define _ASM_X86_PTRACE_ABI_H +#if defined(__ASSEMBLER__) || defined(__FRAME_OFFSETS) #ifdef __i386__ #define EBX 0 @@ -25,7 +26,6 @@ #else /* __i386__ */ -#if defined(__ASSEMBLER__) || defined(__FRAME_OFFSETS) /* * C ABI says these regs are callee-preserved. They aren't saved on kernel entry * unless syscall needs a complete, fully filled "struct pt_regs". @@ -57,12 +57,12 @@ #define EFLAGS 144 #define RSP 152 #define SS 160 -#endif /* __ASSEMBLER__ */ /* top of stack page */ #define FRAME_SIZE 168 #endif /* !__i386__ */ +#endif /* defined(__ASSEMBLER__) || defined(__FRAME_OFFSETS) */ /* Arbitrarily choose the same ptrace numbers as used by the Sparc code. */ #define PTRACE_GETREGS 12 diff --git a/arch/x86/um/asm/ptrace.h b/arch/x86/um/asm/ptrace.h index 2641d28d115c..439c4151f6b7 100644 --- a/arch/x86/um/asm/ptrace.h +++ b/arch/x86/um/asm/ptrace.h @@ -13,9 +13,7 @@ enum { }; #include <linux/compiler.h> -#ifndef CONFIG_X86_32 -#define __FRAME_OFFSETS /* Needed to get the R* macros */ -#endif +#define __FRAME_OFFSETS /* Needed to get the register macros */ #include <asm/ptrace-generic.h> #define user_mode(r) UPT_IS_USER(&(r)->regs) diff --git a/arch/x86/um/ptrace_32.c b/arch/x86/um/ptrace_32.c index 3af3cb821524..9e9155b0e918 100644 --- a/arch/x86/um/ptrace_32.c +++ b/arch/x86/um/ptrace_32.c @@ -7,6 +7,7 @@ #include <linux/sched.h> #include <linux/uaccess.h> #include <linux/regset.h> +#define __FRAME_OFFSETS #include <asm/ptrace-abi.h> #include <registers.h> #include <skas.h> --- base-commit: 26260251022fbc2f248a3d747a9b2b961b18d2d8 change-id: 20260821-ptrace_uapi-462350036cbd Best regards, -- Nick Desaulniers <ndesaulniers@google.com> ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] x86: uapi: ptrace: guard register offset macros with __ASSEMBLER__ or __FRAME_OFFSETS 2026-08-21 22:45 [PATCH] x86: uapi: ptrace: guard register offset macros with __ASSEMBLER__ or __FRAME_OFFSETS Nick Desaulniers @ 2026-09-01 21:45 ` Nick Desaulniers 2026-09-02 13:43 ` enh 2026-09-02 17:29 ` Oleg Nesterov 0 siblings, 2 replies; 4+ messages in thread From: Nick Desaulniers @ 2026-09-01 21:45 UTC (permalink / raw) To: Oleg Nesterov, Elliott Hughes Cc: linux-kernel, linux-um, llvm, Bill Wendling, Nathan Chancellor, Justin Stitt, Johannes Berg, Anton Ivanov, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, Richard Weinberger On Fri, Aug 21, 2026 at 3:46 PM Nick Desaulniers <ndesaulniers@google.com> wrote: > > The register offset macros in <asm/ptrace-abi.h> are guarded by > `defined(__ASSEMBLER__) || defined(__FRAME_OFFSETS)` for 64-bit, but > were left unguarded for 32-bit. This causes havoc for userspace that > happens to use identifiers colliding with these short macro names > (e.g., EBX, ECX, EAX, DS, ES, FS, GS, CS, SS). Without this guard, > userspace is forced to be super extra careful with include ordering to > minimize the chance of collision. > > Wrap both the 32-bit and 64-bit register definitions under > `#if defined(__ASSEMBLER__) || defined(__FRAME_OFFSETS)`, and ensure > User-Mode Linux (UML) defines `__FRAME_OFFSETS` for 32-bit as well. > > Assisted-by: Gemini > Link: https://github.com/llvm/llvm-project/issues/217413 > Signed-off-by: Nick Desaulniers <ndesaulniers@google.com> + enh (who pulled this into android for testing) Oleg, can I get an ack/nack here? Or someone who knows better the history of UAPI headers? (I think the Assisted-by tags need `LLM` now IIUC? Assisted-by: LLM Gemini) We've worked around this now in lldb-server, but figured it might be nice to clean this up for the rest of userspace, too. > --- > arch/x86/include/uapi/asm/ptrace-abi.h | 4 ++-- > arch/x86/um/asm/ptrace.h | 4 +--- > arch/x86/um/ptrace_32.c | 1 + > 3 files changed, 4 insertions(+), 5 deletions(-) > > diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h > index 5823584dea13..3656955c6faa 100644 > --- a/arch/x86/include/uapi/asm/ptrace-abi.h > +++ b/arch/x86/include/uapi/asm/ptrace-abi.h > @@ -2,6 +2,7 @@ > #ifndef _ASM_X86_PTRACE_ABI_H > #define _ASM_X86_PTRACE_ABI_H > > +#if defined(__ASSEMBLER__) || defined(__FRAME_OFFSETS) > #ifdef __i386__ > > #define EBX 0 > @@ -25,7 +26,6 @@ > > #else /* __i386__ */ > > -#if defined(__ASSEMBLER__) || defined(__FRAME_OFFSETS) > /* > * C ABI says these regs are callee-preserved. They aren't saved on kernel entry > * unless syscall needs a complete, fully filled "struct pt_regs". > @@ -57,12 +57,12 @@ > #define EFLAGS 144 > #define RSP 152 > #define SS 160 > -#endif /* __ASSEMBLER__ */ > > /* top of stack page */ > #define FRAME_SIZE 168 > > #endif /* !__i386__ */ > +#endif /* defined(__ASSEMBLER__) || defined(__FRAME_OFFSETS) */ > > /* Arbitrarily choose the same ptrace numbers as used by the Sparc code. */ > #define PTRACE_GETREGS 12 > diff --git a/arch/x86/um/asm/ptrace.h b/arch/x86/um/asm/ptrace.h > index 2641d28d115c..439c4151f6b7 100644 > --- a/arch/x86/um/asm/ptrace.h > +++ b/arch/x86/um/asm/ptrace.h > @@ -13,9 +13,7 @@ enum { > }; > > #include <linux/compiler.h> > -#ifndef CONFIG_X86_32 > -#define __FRAME_OFFSETS /* Needed to get the R* macros */ > -#endif > +#define __FRAME_OFFSETS /* Needed to get the register macros */ > #include <asm/ptrace-generic.h> > > #define user_mode(r) UPT_IS_USER(&(r)->regs) > diff --git a/arch/x86/um/ptrace_32.c b/arch/x86/um/ptrace_32.c > index 3af3cb821524..9e9155b0e918 100644 > --- a/arch/x86/um/ptrace_32.c > +++ b/arch/x86/um/ptrace_32.c > @@ -7,6 +7,7 @@ > #include <linux/sched.h> > #include <linux/uaccess.h> > #include <linux/regset.h> > +#define __FRAME_OFFSETS > #include <asm/ptrace-abi.h> > #include <registers.h> > #include <skas.h> > > --- > base-commit: 26260251022fbc2f248a3d747a9b2b961b18d2d8 > change-id: 20260821-ptrace_uapi-462350036cbd > > Best regards, > -- > Nick Desaulniers <ndesaulniers@google.com> > -- Thanks, ~Nick Desaulniers ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] x86: uapi: ptrace: guard register offset macros with __ASSEMBLER__ or __FRAME_OFFSETS 2026-09-01 21:45 ` Nick Desaulniers @ 2026-09-02 13:43 ` enh 2026-09-02 17:29 ` Oleg Nesterov 1 sibling, 0 replies; 4+ messages in thread From: enh @ 2026-09-02 13:43 UTC (permalink / raw) To: Nick Desaulniers Cc: Oleg Nesterov, linux-kernel, linux-um, llvm, Bill Wendling, Nathan Chancellor, Justin Stitt, Johannes Berg, Anton Ivanov, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, Richard Weinberger On Tue, Sep 1, 2026 at 5:45 PM Nick Desaulniers <ndesaulniers@google.com> wrote: > > On Fri, Aug 21, 2026 at 3:46 PM Nick Desaulniers > <ndesaulniers@google.com> wrote: > > > > The register offset macros in <asm/ptrace-abi.h> are guarded by > > `defined(__ASSEMBLER__) || defined(__FRAME_OFFSETS)` for 64-bit, but > > were left unguarded for 32-bit. This causes havoc for userspace that > > happens to use identifiers colliding with these short macro names > > (e.g., EBX, ECX, EAX, DS, ES, FS, GS, CS, SS). Without this guard, > > userspace is forced to be super extra careful with include ordering to > > minimize the chance of collision. > > > > Wrap both the 32-bit and 64-bit register definitions under > > `#if defined(__ASSEMBLER__) || defined(__FRAME_OFFSETS)`, and ensure > > User-Mode Linux (UML) defines `__FRAME_OFFSETS` for 32-bit as well. > > > > Assisted-by: Gemini > > Link: https://github.com/llvm/llvm-project/issues/217413 > > Signed-off-by: Nick Desaulniers <ndesaulniers@google.com> > > + enh (who pulled this into android for testing) for those who don't know me, i've been Android's libc maintainer for a while now [was https://blog.linuxplumbersconf.org/2014/ocw/proposals/2337 really that long ago?!]... i applied this patch to Android's libc's copy of the uapi headers (because Android uses the uapi headers directly, unlike glibc, and exposes this header transitively from <sys/ptrace.h>, also unlike glibc), and everything still built without problems. this does solve a real problem for us: llvm's coding style means they have a lot of "FS" and "SS" identifiers that conflict with these macros, and we see a conflict every few years. Tested-by: Elliott Hughes <enh@google.com> > Oleg, can I get an ack/nack here? Or someone who knows better the > history of UAPI headers? > > (I think the Assisted-by tags need `LLM` now IIUC? Assisted-by: LLM Gemini) > > We've worked around this now in lldb-server, but figured it might be > nice to clean this up for the rest of userspace, too. > > > --- > > arch/x86/include/uapi/asm/ptrace-abi.h | 4 ++-- > > arch/x86/um/asm/ptrace.h | 4 +--- > > arch/x86/um/ptrace_32.c | 1 + > > 3 files changed, 4 insertions(+), 5 deletions(-) > > > > diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h > > index 5823584dea13..3656955c6faa 100644 > > --- a/arch/x86/include/uapi/asm/ptrace-abi.h > > +++ b/arch/x86/include/uapi/asm/ptrace-abi.h > > @@ -2,6 +2,7 @@ > > #ifndef _ASM_X86_PTRACE_ABI_H > > #define _ASM_X86_PTRACE_ABI_H > > > > +#if defined(__ASSEMBLER__) || defined(__FRAME_OFFSETS) > > #ifdef __i386__ > > > > #define EBX 0 > > @@ -25,7 +26,6 @@ > > > > #else /* __i386__ */ > > > > -#if defined(__ASSEMBLER__) || defined(__FRAME_OFFSETS) > > /* > > * C ABI says these regs are callee-preserved. They aren't saved on kernel entry > > * unless syscall needs a complete, fully filled "struct pt_regs". > > @@ -57,12 +57,12 @@ > > #define EFLAGS 144 > > #define RSP 152 > > #define SS 160 > > -#endif /* __ASSEMBLER__ */ > > > > /* top of stack page */ > > #define FRAME_SIZE 168 > > > > #endif /* !__i386__ */ > > +#endif /* defined(__ASSEMBLER__) || defined(__FRAME_OFFSETS) */ > > > > /* Arbitrarily choose the same ptrace numbers as used by the Sparc code. */ > > #define PTRACE_GETREGS 12 > > diff --git a/arch/x86/um/asm/ptrace.h b/arch/x86/um/asm/ptrace.h > > index 2641d28d115c..439c4151f6b7 100644 > > --- a/arch/x86/um/asm/ptrace.h > > +++ b/arch/x86/um/asm/ptrace.h > > @@ -13,9 +13,7 @@ enum { > > }; > > > > #include <linux/compiler.h> > > -#ifndef CONFIG_X86_32 > > -#define __FRAME_OFFSETS /* Needed to get the R* macros */ > > -#endif > > +#define __FRAME_OFFSETS /* Needed to get the register macros */ > > #include <asm/ptrace-generic.h> > > > > #define user_mode(r) UPT_IS_USER(&(r)->regs) > > diff --git a/arch/x86/um/ptrace_32.c b/arch/x86/um/ptrace_32.c > > index 3af3cb821524..9e9155b0e918 100644 > > --- a/arch/x86/um/ptrace_32.c > > +++ b/arch/x86/um/ptrace_32.c > > @@ -7,6 +7,7 @@ > > #include <linux/sched.h> > > #include <linux/uaccess.h> > > #include <linux/regset.h> > > +#define __FRAME_OFFSETS > > #include <asm/ptrace-abi.h> > > #include <registers.h> > > #include <skas.h> > > > > --- > > base-commit: 26260251022fbc2f248a3d747a9b2b961b18d2d8 > > change-id: 20260821-ptrace_uapi-462350036cbd > > > > Best regards, > > -- > > Nick Desaulniers <ndesaulniers@google.com> > > > > > -- > Thanks, > ~Nick Desaulniers ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] x86: uapi: ptrace: guard register offset macros with __ASSEMBLER__ or __FRAME_OFFSETS 2026-09-01 21:45 ` Nick Desaulniers 2026-09-02 13:43 ` enh @ 2026-09-02 17:29 ` Oleg Nesterov 1 sibling, 0 replies; 4+ messages in thread From: Oleg Nesterov @ 2026-09-02 17:29 UTC (permalink / raw) To: Nick Desaulniers Cc: Elliott Hughes, linux-kernel, linux-um, llvm, Bill Wendling, Nathan Chancellor, Justin Stitt, Johannes Berg, Anton Ivanov, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, Richard Weinberger On 09/01, Nick Desaulniers wrote: > > On Fri, Aug 21, 2026 at 3:46 PM Nick Desaulniers > <ndesaulniers@google.com> wrote: > > > > The register offset macros in <asm/ptrace-abi.h> are guarded by > > `defined(__ASSEMBLER__) || defined(__FRAME_OFFSETS)` for 64-bit, but > > were left unguarded for 32-bit. This causes havoc for userspace that > > happens to use identifiers colliding with these short macro names > > (e.g., EBX, ECX, EAX, DS, ES, FS, GS, CS, SS). Without this guard, > > userspace is forced to be super extra careful with include ordering to > > minimize the chance of collision. > > > > Wrap both the 32-bit and 64-bit register definitions under > > `#if defined(__ASSEMBLER__) || defined(__FRAME_OFFSETS)`, and ensure > > User-Mode Linux (UML) defines `__FRAME_OFFSETS` for 32-bit as well. > > > > Assisted-by: Gemini > > Link: https://github.com/llvm/llvm-project/issues/217413 > > Signed-off-by: Nick Desaulniers <ndesaulniers@google.com> > > + enh (who pulled this into android for testing) > > Oleg, can I get an ack/nack here? Oh... there is a little problem, I don't understand the usage of (magic to me) __FRAME_OFFSETS ;) > Or someone who knows better the > history of UAPI headers? Certainly not me.... OK. I'll try to read this patch tomorrow with the clear head after sleep. Oleg. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-09-02 17:29 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-08-21 22:45 [PATCH] x86: uapi: ptrace: guard register offset macros with __ASSEMBLER__ or __FRAME_OFFSETS Nick Desaulniers 2026-09-01 21:45 ` Nick Desaulniers 2026-09-02 13:43 ` enh 2026-09-02 17:29 ` Oleg Nesterov
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox