Linux MIPS Architecture development
 help / color / mirror / Atom feed
* [PATCH v3] MIPS: Fix MAX_REG_OFFSET
@ 2025-04-27 11:34 Thorsten Blum
  2025-04-27 12:32 ` Huacai Chen
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Thorsten Blum @ 2025-04-27 11:34 UTC (permalink / raw)
  To: Oleg Nesterov, Thomas Bogendoerfer
  Cc: Maciej W. Rozycki, Thorsten Blum, linux-mips, linux-kernel

Fix MAX_REG_OFFSET to point to the last register in 'pt_regs' and not to
the marker itself, which could allow regs_get_register() to return an
invalid offset.

Fixes: 40e084a506eb ("MIPS: Add uprobes support.")
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
Compile-tested only.

Changes in v2:
- Fix MAX_REG_OFFSET as suggested by Maciej (thanks!)
- Link to v1: https://lore.kernel.org/lkml/20250411090032.7844-1-thorsten.blum@linux.dev/

Changes in v3:
- Keep the marker and avoid using #ifdef by adjusting MAX_REG_OFFSET as
  suggested by Thomas and Maciej
- Link to v2: https://lore.kernel.org/lkml/20250417174712.69292-2-thorsten.blum@linux.dev/
---
 arch/mips/include/asm/ptrace.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/mips/include/asm/ptrace.h b/arch/mips/include/asm/ptrace.h
index 85fa9962266a..ef72c46b5568 100644
--- a/arch/mips/include/asm/ptrace.h
+++ b/arch/mips/include/asm/ptrace.h
@@ -65,7 +65,8 @@ static inline void instruction_pointer_set(struct pt_regs *regs,
 
 /* Query offset/name of register from its name/offset */
 extern int regs_query_register_offset(const char *name);
-#define MAX_REG_OFFSET (offsetof(struct pt_regs, __last))
+#define MAX_REG_OFFSET \
+	(offsetof(struct pt_regs, __last) - sizeof(unsigned long))
 
 /**
  * regs_get_register() - get register value from its offset
-- 
2.49.0


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

end of thread, other threads:[~2025-04-30 18:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-27 11:34 [PATCH v3] MIPS: Fix MAX_REG_OFFSET Thorsten Blum
2025-04-27 12:32 ` Huacai Chen
2025-04-27 12:51   ` Thomas Bogendoerfer
2025-04-27 13:30     ` Huacai Chen
2025-04-28  1:43       ` Maciej W. Rozycki
2025-04-28  1:35 ` Maciej W. Rozycki
2025-04-28  6:11   ` Thorsten Blum
2025-04-30 18:07 ` Thomas Bogendoerfer

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