Skip to contentSkip to conversation

MIPS: Fix MAX_REG_OFFSET

PATCH Applied Thorsten Blum 4 participants 8 messages Apr 27, 2025 – Apr 30, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 MIPS: Fix MAX_REG_OFFSET

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

---
Compile-tested only.

Changes in v2:
- Fix MAX_REG_OFFSET as suggested by Maciej (thanks!)
- Link to v1: https://lore.kernel.org/lkml/[email protected]/

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/[email protected]/

---
 arch/mips/include/asm/ptrace.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/mips/include/asm/ptrace.h +2 -1
index 85fa9962266a..ef72c46b5568 100644
@@ -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
Signature · 1 line
2.49.0
#1 lore raw

Hi, Thorsten,

Quoted 27 lines · Thorsten Blum

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

---
Compile-tested only.

Changes in v2:
- Fix MAX_REG_OFFSET as suggested by Maciej (thanks!)
- Link to v1: https://lore.kernel.org/lkml/[email protected]/

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/[email protected]/

---
 arch/mips/include/asm/ptrace.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/mips/include/asm/ptrace.h +0 -0
index 85fa9962266a..ef72c46b5568 100644

arch/mips/include/asm/ptrace.h static inline void instruction_pointer_set(struct pt_regs *regs, · line 69

Quoted 6 lines
arch/mips/include/asm/ptrace.h +2 -1
@@ -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))

There is no 80 columns limit now, so no new line needed here.

Huacai

Quoted 7 lines
arch/mips/include/asm/ptrace.h +0 -1
 /**
  * regs_get_register() - get register value from its offset
--

2.49.0

#2 lore raw
Quoted 31 lines · Huacai Chen

Hi, Thorsten,

Quoted 28 lines · Thorsten Blum

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

---
Compile-tested only.

Changes in v2:
- Fix MAX_REG_OFFSET as suggested by Maciej (thanks!)
- Link to v1: https://lore.kernel.org/lkml/[email protected]/

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/[email protected]/

---
 arch/mips/include/asm/ptrace.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/mips/include/asm/ptrace.h +0 -0
index 85fa9962266a..ef72c46b5568 100644
@@ -65,7 +65,8 @@ static inline void instruction_pointer_set(struct pt_regs *regs,
 
Quoted 6 lines

arch/mips/include/asm/ptrace.h static inline void instruction_pointer_set(struct pt_regs *regs, · line 69

Quoted 5 lines
arch/mips/include/asm/ptrace.h +2 -1
 /* 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))

There is no 80 columns limit now, so no new line needed here.

but not forbidden to care about it. I still prefer this limit.

Thomas.

Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]
#3 lore raw
Quoted 33 lines · Thomas Bogendoerfer
Quoted 31 lines · Huacai Chen

Hi, Thorsten,

Quoted 28 lines · Thorsten Blum

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

---
Compile-tested only.

Changes in v2:
- Fix MAX_REG_OFFSET as suggested by Maciej (thanks!)
- Link to v1: https://lore.kernel.org/lkml/[email protected]/

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/[email protected]/

---
 arch/mips/include/asm/ptrace.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/mips/include/asm/ptrace.h +0 -0
index 85fa9962266a..ef72c46b5568 100644
@@ -65,7 +65,8 @@ static inline void instruction_pointer_set(struct pt_regs *regs,
 
Quoted 8 lines
Quoted 6 lines

arch/mips/include/asm/ptrace.h static inline void instruction_pointer_set(struct pt_regs *regs, · line 69

Quoted 5 lines
arch/mips/include/asm/ptrace.h +2 -1
 /* 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))

There is no 80 columns limit now, so no new line needed here.

but not forbidden to care about it. I still prefer this limit.

Of course you are free to choose. But in my opinion "force to long lines" and "force to short lines" are both bad, code readability is the first thing to be considered.

Huacai

Quoted 6 lines

Thomas.

--
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea. [ RFC1925, 2.3 ]

#4 lore raw
Quoted 6 lines · Huacai Chen
Quoted 3 lines
Quoted 1 line

There is no 80 columns limit now, so no new line needed here.

but not forbidden to care about it. I still prefer this limit.

Of course you are free to choose. But in my opinion "force to long lines" and "force to short lines" are both bad, code readability is the first thing to be considered.

Correct, and I start getting lost when lines are wrapped by overrunning
the width of my screen. NB in the old days some terminals would actually truncate lines instead; at least it does not happen anymore, or at least you can tell your terminal not to do it via a suitable stty(1) invocation.

Maciej

#5 lore raw
In reply to Thorsten Blum
Quoted 11 lines · Thorsten Blum

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

---
Compile-tested only.

Changes in v2:
- Fix MAX_REG_OFFSET as suggested by Maciej (thanks!)

You're welcome; please add a `Suggested-by' tag accordingly.

Maciej

#6 lore raw
Quoted 10 lines · Maciej W. Rozycki
Quoted 9 lines · Thorsten Blum

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

---
Compile-tested only.

Quoted 4 lines
Quoted 2 lines

Changes in v2:
- Fix MAX_REG_OFFSET as suggested by Maciej (thanks!)

You're welcome; please add a `Suggested-by' tag accordingly.

maintainer Applied
#7 lore raw
In reply to Thorsten Blum
Quoted 37 lines · Thorsten Blum

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

---
Compile-tested only.

Changes in v2:
- Fix MAX_REG_OFFSET as suggested by Maciej (thanks!)
- Link to v1: https://lore.kernel.org/lkml/[email protected]/

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/[email protected]/

---
 arch/mips/include/asm/ptrace.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/mips/include/asm/ptrace.h +2 -1
index 85fa9962266a..ef72c46b5568 100644
@@ -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
Signature · 1 line
2.49.0

applied to mips-fixes.

Thomas.

Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]