mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [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
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ 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	[flat|nested] 11+ 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
  2026-09-24 14:54 ` Johannes Berg
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 11+ 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] 11+ 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; 11+ 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] 11+ 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
  2026-09-17 18:20     ` Nick Desaulniers
  1 sibling, 1 reply; 11+ 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] 11+ messages in thread

* Re: [PATCH] x86: uapi: ptrace: guard register offset macros with __ASSEMBLER__ or __FRAME_OFFSETS
  2026-09-02 17:29   ` Oleg Nesterov
@ 2026-09-17 18:20     ` Nick Desaulniers
  0 siblings, 0 replies; 11+ messages in thread
From: Nick Desaulniers @ 2026-09-17 18:20 UTC (permalink / raw)
  To: Oleg Nesterov
  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 Wed, Sep 2, 2026 at 10:29 AM Oleg Nesterov <oleg@redhat.com> wrote:
>
> 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 ;)

Yeah, my Assisted by tag is from asking Gemini to triple check my
patch before posting, and it pointing out to me from a local review:
"did you intend to break the arch/x86/um/ C uses of these macro
defines?"  So I'm just matching an existing pattern in arch/x86/um/
for 64b with the __FRAME_OFFSETS parts of this patch.

The patch started off as "why are the 64b macros behind the
__ASSEMBLER__ preprocessor guards, but not the 32b ones?"  I went back
through the pre-git history tree, and FWICT, those macros have always
been guarded for 64b, since the introduction of x86_64 support itself.
Dunno if anyone remembers anymore _why_ the 32b macro defines don't
have that guard (chesterton's fence?), but to me, IMO, it looks like a
mistake.

Hence this patch.  PTAL

>
> > 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.

Thanks for taking a look.
-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 11+ 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-24 14:54 ` Johannes Berg
  2026-09-25 21:25   ` Nick Desaulniers
  2026-09-26 12:19 ` Oleg Nesterov
  2026-09-28 19:15 ` [tip: x86/urgent] {x86,um}/uapi/ptrace: Guard " tip-bot2 for Nick Desaulniers
  3 siblings, 1 reply; 11+ messages in thread
From: Johannes Berg @ 2026-09-24 14:54 UTC (permalink / raw)
  To: Nick Desaulniers, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Richard Weinberger,
	Anton Ivanov, Oleg Nesterov, Nathan Chancellor, Bill Wendling,
	Justin Stitt
  Cc: linux-kernel, linux-um, llvm

On Fri, 2026-08-21 at 15:45 -0700, Nick Desaulniers wrote:
> 
>  arch/x86/um/asm/ptrace.h               | 4 +---
>  arch/x86/um/ptrace_32.c                | 1 +

This seems like a simple adjustment for what you need to do in x86, so
that's OK, but I don't think we'll take this through the UML tree.

But for UML you can have my

Acked-by: Johannes Berg <johannes@sipsolutions.net>

johannes

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] x86: uapi: ptrace: guard register offset macros with __ASSEMBLER__ or __FRAME_OFFSETS
  2026-09-24 14:54 ` Johannes Berg
@ 2026-09-25 21:25   ` Nick Desaulniers
  2026-09-26 19:51     ` Borislav Petkov
  0 siblings, 1 reply; 11+ messages in thread
From: Nick Desaulniers @ 2026-09-25 21:25 UTC (permalink / raw)
  To: Johannes Berg, Oleg Nesterov
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Richard Weinberger, Anton Ivanov,
	Nathan Chancellor, Bill Wendling, Justin Stitt, linux-kernel,
	linux-um, llvm

On Thu, Sep 24, 2026 at 7:54 AM Johannes Berg <johannes@sipsolutions.net> wrote:
>
> On Fri, 2026-08-21 at 15:45 -0700, Nick Desaulniers wrote:
> >
> >  arch/x86/um/asm/ptrace.h               | 4 +---
> >  arch/x86/um/ptrace_32.c                | 1 +
>
> This seems like a simple adjustment for what you need to do in x86, so
> that's OK, but I don't think we'll take this through the UML tree.

Appreciated! I agree, maybe with Oleg's review this can go via the x86 tree?

>
> But for UML you can have my
>
> Acked-by: Johannes Berg <johannes@sipsolutions.net>
>
> johannes



-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 11+ 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-24 14:54 ` Johannes Berg
@ 2026-09-26 12:19 ` Oleg Nesterov
  2026-09-28 19:15 ` [tip: x86/urgent] {x86,um}/uapi/ptrace: Guard " tip-bot2 for Nick Desaulniers
  3 siblings, 0 replies; 11+ messages in thread
From: Oleg Nesterov @ 2026-09-26 12:19 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Richard Weinberger, Anton Ivanov, Johannes Berg,
	Nathan Chancellor, Bill Wendling, Justin Stitt, linux-kernel,
	linux-um, llvm

On 08/21, Nick Desaulniers 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>
> ---
>  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(-)

Acked-by: Oleg Nesterov <oleg@redhat.com>


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] x86: uapi: ptrace: guard register offset macros with __ASSEMBLER__ or __FRAME_OFFSETS
  2026-09-25 21:25   ` Nick Desaulniers
@ 2026-09-26 19:51     ` Borislav Petkov
  2026-09-28 16:19       ` Nick Desaulniers
  0 siblings, 1 reply; 11+ messages in thread
From: Borislav Petkov @ 2026-09-26 19:51 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Johannes Berg, Oleg Nesterov, Thomas Gleixner, Ingo Molnar,
	Dave Hansen, x86, H. Peter Anvin, Richard Weinberger,
	Anton Ivanov, Nathan Chancellor, Bill Wendling, Justin Stitt,
	linux-kernel, linux-um, llvm

On Fri, Sep 25, 2026 at 02:25:47PM -0700, Nick Desaulniers wrote:
> On Thu, Sep 24, 2026 at 7:54 AM Johannes Berg <johannes@sipsolutions.net> wrote:
> >
> > On Fri, 2026-08-21 at 15:45 -0700, Nick Desaulniers wrote:
> > >
> > >  arch/x86/um/asm/ptrace.h               | 4 +---
> > >  arch/x86/um/ptrace_32.c                | 1 +
> >
> > This seems like a simple adjustment for what you need to do in x86, so
> > that's OK, but I don't think we'll take this through the UML tree.
> 
> Appreciated! I agree, maybe with Oleg's review this can go via the x86 tree?

Do we want it in stable too even if it is not really stable material so that
userspace does not have to upgrade kernels just for this?

Or are they simply copying upstream UAPI headers from the latest kernel so
that stable backports don't matter?

Thx.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] x86: uapi: ptrace: guard register offset macros with __ASSEMBLER__ or __FRAME_OFFSETS
  2026-09-26 19:51     ` Borislav Petkov
@ 2026-09-28 16:19       ` Nick Desaulniers
  0 siblings, 0 replies; 11+ messages in thread
From: Nick Desaulniers @ 2026-09-28 16:19 UTC (permalink / raw)
  To: Borislav Petkov, Elliott Hughes
  Cc: Johannes Berg, Oleg Nesterov, Thomas Gleixner, Ingo Molnar,
	Dave Hansen, x86, H. Peter Anvin, Richard Weinberger,
	Anton Ivanov, Nathan Chancellor, Bill Wendling, Justin Stitt,
	linux-kernel, linux-um, llvm

On Sat, Sep 26, 2026 at 12:52 PM Borislav Petkov <bp@alien8.de> wrote:
>
> On Fri, Sep 25, 2026 at 02:25:47PM -0700, Nick Desaulniers wrote:
> > On Thu, Sep 24, 2026 at 7:54 AM Johannes Berg <johannes@sipsolutions.net> wrote:
> > >
> > > On Fri, 2026-08-21 at 15:45 -0700, Nick Desaulniers wrote:
> > > >
> > > >  arch/x86/um/asm/ptrace.h               | 4 +---
> > > >  arch/x86/um/ptrace_32.c                | 1 +
> > >
> > > This seems like a simple adjustment for what you need to do in x86, so
> > > that's OK, but I don't think we'll take this through the UML tree.
> >
> > Appreciated! I agree, maybe with Oleg's review this can go via the x86 tree?
>
> Do we want it in stable too even if it is not really stable material so that
> userspace does not have to upgrade kernels just for this?

I don't think so.  Android, say, is not going to upgrade kernels just for this.

>
> Or are they simply copying upstream UAPI headers from the latest kernel so
> that stable backports don't matter?

Right.  IIUC, bionic doesn't have N copies of UAPI headers (one for
each branch of stable), just 1 copy which they do move to newer kernel
versions when they need something. (enh@ can correct me precisely).

>
> Thx.
>
> --
> Regards/Gruss,
>     Boris.
>
> https://people.kernel.org/tglx/notes-about-netiquette



-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [tip: x86/urgent] {x86,um}/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
                   ` (2 preceding siblings ...)
  2026-09-26 12:19 ` Oleg Nesterov
@ 2026-09-28 19:15 ` tip-bot2 for Nick Desaulniers
  3 siblings, 0 replies; 11+ messages in thread
From: tip-bot2 for Nick Desaulniers @ 2026-09-28 19:15 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Nick Desaulniers, Borislav Petkov (AMD),
	Oleg Nesterov, Johannes Berg, Elliott Hughes, x86, linux-kernel

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     a661c34fe693c8f9ef29b45ee71cfa1fe593502b
Gitweb:        https://git.kernel.org/tip/a661c34fe693c8f9ef29b45ee71cfa1fe593502b
Author:        Nick Desaulniers <ndesaulniers@google.com>
AuthorDate:    Fri, 21 Aug 2026 15:45:42 -07:00
Committer:     Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Mon, 28 Sep 2026 12:11:19 -07:00

{x86,um}/uapi/ptrace: Guard register offset macros with __ASSEMBLER__ or __FRAME_OFFSETS

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.

Closes: https://github.com/llvm/llvm-project/issues/217413
Assisted-by: LLM
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Acked-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Johannes Berg <johannes@sipsolutions.net>
Tested-by: Elliott Hughes <enh@google.com>
Link: https://patch.msgid.link/20260821-ptrace_uapi-v1-1-3de8638a29f2@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 5823584..3656955 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 2641d28..439c415 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 3af3cb8..9e9155b 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>

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-09-28 19:15 UTC | newest]

Thread overview: 11+ 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
2026-09-17 18:20     ` Nick Desaulniers
2026-09-24 14:54 ` Johannes Berg
2026-09-25 21:25   ` Nick Desaulniers
2026-09-26 19:51     ` Borislav Petkov
2026-09-28 16:19       ` Nick Desaulniers
2026-09-26 12:19 ` Oleg Nesterov
2026-09-28 19:15 ` [tip: x86/urgent] {x86,um}/uapi/ptrace: Guard " tip-bot2 for Nick Desaulniers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®