Skip to contentSkip to conversation

arm64/traps: Avoid unnecessary kernel/user pointer conversion

PATCH Applied Amit Daniel Kachhap 3 participants 3 messages Sep 17, 2021 – Sep 29, 2021 arm64

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 arm64/traps: Avoid unnecessary kernel/user pointer conversion

Annotating a pointer from kernel to __user and then back again requires an extra __force annotation to silent sparse warning. In call_undef_hook() this unnecessary complexity can be avoided by modifying the intermediate user pointer to unsigned long.

This way there is no inter-changeable use of user and kernel pointers and the code is consistent.

Note: This patch adds no functional changes to code.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>

---
Changes from v1:
* Instead of directly using instruction_pointer() for kernel pointers, modified the pc type from void __user * to unsigned long as suggested by Mark Rutland.

 arch/arm64/kernel/traps.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/kernel/traps.c +2 -2
index b03e383d944a..09236751283e 100644
@@ -400,11 +400,11 @@ static int call_undef_hook(struct pt_regs *regs)
 	unsigned long flags;
 	u32 instr;
 	int (*fn)(struct pt_regs *regs, u32 instr) = NULL;
-	void __user *pc = (void __user *)instruction_pointer(regs);
+	unsigned long pc = instruction_pointer(regs);
 
 	if (!user_mode(regs)) {
 		__le32 instr_le;
-		if (get_kernel_nofault(instr_le, (__force __le32 *)pc))
+		if (get_kernel_nofault(instr_le, (__le32 *)pc))
 			goto exit;
 		instr = le32_to_cpu(instr_le);
 	} else if (compat_thumb_mode(regs)) {
Signature · 1 line
2.17.1
reviewer Acked-by on v2 1/1
#1 lore raw
Quoted 5 lines · Amit Daniel Kachhap

Annotating a pointer from kernel to __user and then back again requires an extra __force annotation to silent sparse warning. In call_undef_hook() this unnecessary complexity can be avoided by modifying the intermediate user pointer to unsigned long.

Quoted 8 lines

This way there is no inter-changeable use of user and kernel pointers and the code is consistent.

Note: This patch adds no functional changes to code.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>

I like that this clarifies that pc is not necessarily a user pointer, and this makes the relevant lines shorter and eaier to read, so FWIW:

Thanks,
Mark.

Quoted 30 lines

---
Changes from v1:
* Instead of directly using instruction_pointer() for kernel pointers, modified the pc type from void __user * to unsigned long as suggested by Mark Rutland.

 arch/arm64/kernel/traps.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/kernel/traps.c +2 -2
index b03e383d944a..09236751283e 100644
@@ -400,11 +400,11 @@ static int call_undef_hook(struct pt_regs *regs)
 	unsigned long flags;
 	u32 instr;
 	int (*fn)(struct pt_regs *regs, u32 instr) = NULL;
-	void __user *pc = (void __user *)instruction_pointer(regs);
+	unsigned long pc = instruction_pointer(regs);
 
 	if (!user_mode(regs)) {
 		__le32 instr_le;
-		if (get_kernel_nofault(instr_le, (__force __le32 *)pc))
+		if (get_kernel_nofault(instr_le, (__le32 *)pc))
 			goto exit;
 		instr = le32_to_cpu(instr_le);
 	} else if (compat_thumb_mode(regs)) {
Signature · 1 line
2.17.1
maintainer Applied
#2 lore raw
In reply to Amit Daniel Kachhap
Quoted 9 lines · Amit Daniel Kachhap

Annotating a pointer from kernel to __user and then back again requires an extra __force annotation to silent sparse warning. In call_undef_hook() this unnecessary complexity can be avoided by modifying the intermediate user pointer to unsigned long.

This way there is no inter-changeable use of user and kernel pointers and the code is consistent.

[...]

Applied to arm64 (for-next/misc), thanks!

[1/1] arm64/traps: Avoid unnecessary kernel/user pointer conversion

      https://git.kernel.org/arm64/c/f5b650f887f3

Cheers,

Signature · 5 lines
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev