Skip to contentSkip to conversation

m68k: Implement "current_stack_pointer"

PATCH In review Kees Cook 3 participants 7 messages Feb 24, 2022 – Feb 25, 2022 m68k architecture

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 m68k: Implement "current_stack_pointer"

To follow the existing per-arch conventions, add asm "sp" as "current_stack_pointer". This will let it be used in non-arch places (like HARDENED_USERCOPY).

---
 arch/m68k/Kconfig               | 1 +
 arch/m68k/include/asm/current.h | 2 ++
 2 files changed, 3 insertions(+)
arch/m68k/Kconfig +1 -0
index 936e1803c7c7..f0eac0e2f123 100644
@@ -4,6 +4,7 @@ config M68K
 	default y
 	select ARCH_32BIT_OFF_T
 	select ARCH_HAS_BINFMT_FLAT
+	select ARCH_HAS_CURRENT_STACK_POINTER
 	select ARCH_HAS_DMA_PREP_COHERENT if HAS_DMA && MMU && !COLDFIRE
 	select ARCH_HAS_SYNC_DMA_FOR_DEVICE if HAS_DMA
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG if RMW_INSNS
arch/m68k/include/asm/current.h +2 -0
index 6390ef2f7f86..0c87a7047e15 100644
@@ -24,6 +24,8 @@ static inline struct task_struct *get_current(void)
 
 #define	current	get_current()
 
+register unsigned long current_stack_pointer __asm__("sp");
+
 #endif /* CONFNIG_MMU */
 
 #endif /* !(_M68K_CURRENT_H) */
Signature · 1 line
2.30.2
#1 lore raw

Hi Kees,

Quoted 7 lines · Kees Cook

To follow the existing per-arch conventions, add asm "sp" as "current_stack_pointer". This will let it be used in non-arch places (like HARDENED_USERCOPY).

Thanks for your patch!

arch/m68k/include/asm/current.h static inline struct task_struct *get_current(void) · line 27

Quoted 7 lines
arch/m68k/include/asm/current.h +1 -0
@@ -24,6 +24,8 @@ static inline struct task_struct *get_current(void)
 
 #define        current get_current()
 
+register unsigned long current_stack_pointer __asm__("sp");

I don't know what HARDENED_USERCOPY does, so I don't know if you need "usp" (see rdusp()) or "sp"?

arch/m68k/include/asm/current.h static inline struct task_struct *get_current(void) · line 31

Quoted 4 lines
arch/m68k/include/asm/current.h +1 -0
+
 #endif /* CONFNIG_MMU */
 
 #endif /* !(_M68K_CURRENT_H) */

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#2 lore raw

From: Geert Uytterhoeven

Quoted 1 line

Sent: 24 February 2022 08:59

...

Quoted 4 lines
Quoted 1 line

+register unsigned long current_stack_pointer __asm__("sp");

I don't know what HARDENED_USERCOPY does, so I don't know if you need "usp" (see rdusp()) or "sp"?

HARDENED_USERCOPY significantly slows down some systems calls (especially things like sendmsg()) by trying to run-time verify that the kernel buffer doesn't overrun a stack frame or kmalloc()ed buffer.

I've got measurable improvements by either using __copy_to/from_user() (which skips the tests) or user_access_begin() and __get_user().

At the moment the code for reading a compat iovec[] is actually faster than that for a native one!

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

#3 lore raw
Quoted 11 lines · David Laight

From: Geert Uytterhoeven

Quoted 1 line

Sent: 24 February 2022 08:59

...

Quoted 4 lines
Quoted 1 line

+register unsigned long current_stack_pointer __asm__("sp");

I don't know what HARDENED_USERCOPY does, so I don't know if you need "usp" (see rdusp()) or "sp"?

HARDENED_USERCOPY significantly slows down some systems calls (especially things like sendmsg()) by trying to run-time verify that the kernel buffer doesn't overrun a stack frame or kmalloc()ed

Kernel stack frame of user stack frame?

Quoted 7 lines

buffer.

I've got measurable improvements by either using __copy_to/from_user() (which skips the tests) or user_access_begin() and __get_user().

At the moment the code for reading a compat iovec[] is actually faster than that for a native one!

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#4 lore raw

From: Geert Uytterhoeven <[email protected]>

Quoted 8 lines

Sent: 24 February 2022 09:17

Quoted 5 lines · David Laight

From: Geert Uytterhoeven

Quoted 1 line

Sent: 24 February 2022 08:59

...

Quoted 2 lines
Quoted 1 line

+register unsigned long current_stack_pointer __asm__("sp");

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

I don't know what HARDENED_USERCOPY does, so I don't know if you need "usp" (see rdusp()) or "sp"?

HARDENED_USERCOPY significantly slows down some systems calls (especially things like sendmsg()) by trying to run-time verify that the kernel buffer doesn't overrun a stack frame or kmalloc()ed

Kernel stack frame of user stack frame?

Kernel, the kernel doesn't care if the user stack gets trashed.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

maintainer Reviewed-by Acked-by
#5 lore raw

Hi David, Kees,

Quoted 12 lines · David Laight

From: Geert Uytterhoeven <[email protected]>

Quoted 11 lines

Sent: 24 February 2022 09:17

Quoted 8 lines · David Laight

From: Geert Uytterhoeven

Quoted 1 line

Sent: 24 February 2022 08:59

...

Quoted 4 lines
Quoted 1 line

+register unsigned long current_stack_pointer __asm__("sp");

I don't know what HARDENED_USERCOPY does, so I don't know if you need "usp" (see rdusp()) or "sp"?

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

HARDENED_USERCOPY significantly slows down some systems calls (especially things like sendmsg()) by trying to run-time verify that the kernel buffer doesn't overrun a stack frame or kmalloc()ed

Kernel stack frame of user stack frame?

Kernel, the kernel doesn't care if the user stack gets trashed.

OK.

Kees: Do you want me to queue this in the m68k for-v5.18 branch, or do you want to take it yourself, together with the HARDENED_USERCOPY work? In case of the latter:

Please let me know. Thanks!

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

author
#6 lore raw
Quoted 22 lines · Geert Uytterhoeven

Hi David, Kees,

Quoted 19 lines · David Laight

From: Geert Uytterhoeven <[email protected]>

Quoted 8 lines

Sent: 24 February 2022 09:17

Quoted 5 lines · David Laight

From: Geert Uytterhoeven

Quoted 1 line

Sent: 24 February 2022 08:59

...

Quoted 2 lines
Quoted 1 line

+register unsigned long current_stack_pointer __asm__("sp");

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

I don't know what HARDENED_USERCOPY does, so I don't know if you need "usp" (see rdusp()) or "sp"?

HARDENED_USERCOPY significantly slows down some systems calls (especially things like sendmsg()) by trying to run-time verify that the kernel buffer doesn't overrun a stack frame or kmalloc()ed

Kernel stack frame of user stack frame?

Kernel, the kernel doesn't care if the user stack gets trashed.

Right, this is strictly a kernel-side check in mm/usercopy.c:
https://lore.kernel.org/linux-hardening/[email protected]/

Quoted 11 lines

OK.

Kees: Do you want me to queue this in the m68k for-v5.18 branch, or do you want to take it yourself, together with the HARDENED_USERCOPY work? In case of the latter:

Please let me know. Thanks!

Yeah, I'll take it via my tree, just so it's all together.

Thanks!

-Kees

Signature · 1 line
Kees Cook