* [PATCH] powerpc/ptrace: Add offsetof check for exit_flags in pt_regs_check()
@ 2026-07-03 7:49 Mukesh Kumar Chaurasiya (IBM)
2026-07-03 8:55 ` Amit Machhiwal
0 siblings, 1 reply; 2+ messages in thread
From: Mukesh Kumar Chaurasiya (IBM) @ 2026-07-03 7:49 UTC (permalink / raw)
To: maddy, mpe, npiggin, chleroy, mkchauras, sshegde, mkchauras,
linuxppc-dev, linux-kernel
pt_regs_check() verifies that fields shared between struct pt_regs and
struct user_pt_regs sit at the same offset, to catch any accidental
layout divergence between the kernel and uapi structures.
Add the missing check for exit_flags, following the same pattern as the
existing checks for result, dsisr, dar and the other shared fields.
Fixes: d7a6797e0bc1 ("powerpc: add exit_flags field in pt_regs")
Signed-off-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
---
arch/powerpc/kernel/ptrace/ptrace.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/powerpc/kernel/ptrace/ptrace.c b/arch/powerpc/kernel/ptrace/ptrace.c
index 316d4f5ead8e..fb3fec73f66a 100644
--- a/arch/powerpc/kernel/ptrace/ptrace.c
+++ b/arch/powerpc/kernel/ptrace/ptrace.c
@@ -235,6 +235,8 @@ void __init pt_regs_check(void)
offsetof(struct user_pt_regs, dsisr));
BUILD_BUG_ON(offsetof(struct pt_regs, result) !=
offsetof(struct user_pt_regs, result));
+ BUILD_BUG_ON(offsetof(struct pt_regs, exit_flags) !=
+ offsetof(struct user_pt_regs, exit_flags));
BUILD_BUG_ON(sizeof(struct user_pt_regs) > sizeof(struct pt_regs));
--
2.55.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] powerpc/ptrace: Add offsetof check for exit_flags in pt_regs_check()
2026-07-03 7:49 [PATCH] powerpc/ptrace: Add offsetof check for exit_flags in pt_regs_check() Mukesh Kumar Chaurasiya (IBM)
@ 2026-07-03 8:55 ` Amit Machhiwal
0 siblings, 0 replies; 2+ messages in thread
From: Amit Machhiwal @ 2026-07-03 8:55 UTC (permalink / raw)
To: Mukesh Kumar Chaurasiya (IBM)
Cc: maddy, mpe, npiggin, chleroy, mkchauras, sshegde, linuxppc-dev,
linux-kernel
On 2026/07/03 01:19 PM, Mukesh Kumar Chaurasiya (IBM) wrote:
> pt_regs_check() verifies that fields shared between struct pt_regs and
> struct user_pt_regs sit at the same offset, to catch any accidental
> layout divergence between the kernel and uapi structures.
>
> Add the missing check for exit_flags, following the same pattern as the
> existing checks for result, dsisr, dar and the other shared fields.
>
> Fixes: d7a6797e0bc1 ("powerpc: add exit_flags field in pt_regs")
You may want to add below in order to get this patch backported:
Cc: stable@vger.kernel.org
> Signed-off-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
> ---
> arch/powerpc/kernel/ptrace/ptrace.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/arch/powerpc/kernel/ptrace/ptrace.c b/arch/powerpc/kernel/ptrace/ptrace.c
> index 316d4f5ead8e..fb3fec73f66a 100644
> --- a/arch/powerpc/kernel/ptrace/ptrace.c
> +++ b/arch/powerpc/kernel/ptrace/ptrace.c
> @@ -235,6 +235,8 @@ void __init pt_regs_check(void)
> offsetof(struct user_pt_regs, dsisr));
> BUILD_BUG_ON(offsetof(struct pt_regs, result) !=
> offsetof(struct user_pt_regs, result));
> + BUILD_BUG_ON(offsetof(struct pt_regs, exit_flags) !=
> + offsetof(struct user_pt_regs, exit_flags));
At first, it appeared to be redundant as we already check
CHECK_REG(PT_EXIT_FLAGS, exit_flags);
which expands to:
#define CHECK_REG(_pt, _reg) \
BUILD_BUG_ON(_pt != (offsetof(struct user_pt_regs, _reg) / \
sizeof(unsigned long)));
But looking closely, it turns out to be non-redundant. CHECK_REG only
touches struct user_pt_regs — it validates the PT_EXIT_FLAGS constant
against the uapi layout. It says nothing about struct pt_regs.
struct pt_regs (asm/ptrace.h) embeds struct user_pt_regs in a union
alongside an anonymous struct that re-declares all the same fields with
kernel-internal aliases (dear/dar, esr/dsisr). exit_flags lives in that
anonymous struct. A field accidentally inserted there between result and
exit_flags would silently break the union aliasing without CHECK_REG
catching it. The new BUILD_BUG_ON closes that gap, consistent with how
result, dar and dsisr are already protected in the same block.
Looks good to me.
Reviewed-by: Amit Machhiwal <amachhiw@linux.ibm.com>
Thanks,
Amit
>
> BUILD_BUG_ON(sizeof(struct user_pt_regs) > sizeof(struct pt_regs));
>
> --
> 2.55.0
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-03 8:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-03 7:49 [PATCH] powerpc/ptrace: Add offsetof check for exit_flags in pt_regs_check() Mukesh Kumar Chaurasiya (IBM)
2026-07-03 8:55 ` Amit Machhiwal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).