linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm64: fix function types in COND_SYSCALL
@ 2019-09-10 22:40 Sami Tolvanen
  2019-09-11 15:15 ` Mark Rutland
  0 siblings, 1 reply; 4+ messages in thread
From: Sami Tolvanen @ 2019-09-10 22:40 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Mark Rutland
  Cc: Kees Cook, linux-arm-kernel, linux-kernel, Sami Tolvanen

Define a weak function in COND_SYSCALL instead of a weak alias to
sys_ni_syscall, which has an incompatible type. This fixes indirect
call mismatches with Control-Flow Integrity (CFI) checking.

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
---
 arch/arm64/include/asm/syscall_wrapper.h | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/include/asm/syscall_wrapper.h b/arch/arm64/include/asm/syscall_wrapper.h
index 507d0ee6bc69..06d880b3526c 100644
--- a/arch/arm64/include/asm/syscall_wrapper.h
+++ b/arch/arm64/include/asm/syscall_wrapper.h
@@ -8,6 +8,8 @@
 #ifndef __ASM_SYSCALL_WRAPPER_H
 #define __ASM_SYSCALL_WRAPPER_H
 
+struct pt_regs;
+
 #define SC_ARM64_REGS_TO_ARGS(x, ...)				\
 	__MAP(x,__SC_ARGS					\
 	      ,,regs->regs[0],,regs->regs[1],,regs->regs[2]	\
@@ -35,8 +37,11 @@
 	ALLOW_ERROR_INJECTION(__arm64_compat_sys_##sname, ERRNO);			\
 	asmlinkage long __arm64_compat_sys_##sname(const struct pt_regs *__unused)
 
-#define COND_SYSCALL_COMPAT(name) \
-	cond_syscall(__arm64_compat_sys_##name);
+#define COND_SYSCALL_COMPAT(name) 							\
+	asmlinkage long __weak __arm64_compat_sys_##name(const struct pt_regs *regs)	\
+	{										\
+		return sys_ni_syscall();						\
+	}
 
 #define COMPAT_SYS_NI(name) \
 	SYSCALL_ALIAS(__arm64_compat_sys_##name, sys_ni_posix_timers);
@@ -70,7 +75,11 @@
 #endif
 
 #ifndef COND_SYSCALL
-#define COND_SYSCALL(name) cond_syscall(__arm64_sys_##name)
+#define COND_SYSCALL(name)							\
+	asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs)	\
+	{									\
+		return sys_ni_syscall();					\
+	}
 #endif
 
 #ifndef SYS_NI
-- 
2.23.0.162.g0b9fbb3734-goog


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

* Re: [PATCH] arm64: fix function types in COND_SYSCALL
  2019-09-10 22:40 [PATCH] arm64: fix function types in COND_SYSCALL Sami Tolvanen
@ 2019-09-11 15:15 ` Mark Rutland
  2019-09-12 13:11   ` Will Deacon
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Rutland @ 2019-09-11 15:15 UTC (permalink / raw)
  To: Sami Tolvanen
  Cc: Catalin Marinas, Will Deacon, Kees Cook, linux-arm-kernel, linux-kernel

On Tue, Sep 10, 2019 at 03:40:44PM -0700, Sami Tolvanen wrote:
> Define a weak function in COND_SYSCALL instead of a weak alias to
> sys_ni_syscall, which has an incompatible type. This fixes indirect
> call mismatches with Control-Flow Integrity (CFI) checking.
> 
> Signed-off-by: Sami Tolvanen <samitolvanen@google.com>

This looks correct to me, builds fine, and I asume has been tested, so FWIW:

Acked-by: Mark Rutland <mark.rutland@arm.com>

In looking at this, I came to the conclusion that we can drop the ifdeffery
around our SYSCALL_DEFINE0(), COND_SYSCALL(), and SYS_NI(), which I evidently
cargo-culted from x86 (where the ifdeffery is actually necessary).

I can send a follow up for that.

Thanks,
Mark.

> ---
>  arch/arm64/include/asm/syscall_wrapper.h | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/syscall_wrapper.h b/arch/arm64/include/asm/syscall_wrapper.h
> index 507d0ee6bc69..06d880b3526c 100644
> --- a/arch/arm64/include/asm/syscall_wrapper.h
> +++ b/arch/arm64/include/asm/syscall_wrapper.h
> @@ -8,6 +8,8 @@
>  #ifndef __ASM_SYSCALL_WRAPPER_H
>  #define __ASM_SYSCALL_WRAPPER_H
>  
> +struct pt_regs;
> +
>  #define SC_ARM64_REGS_TO_ARGS(x, ...)				\
>  	__MAP(x,__SC_ARGS					\
>  	      ,,regs->regs[0],,regs->regs[1],,regs->regs[2]	\
> @@ -35,8 +37,11 @@
>  	ALLOW_ERROR_INJECTION(__arm64_compat_sys_##sname, ERRNO);			\
>  	asmlinkage long __arm64_compat_sys_##sname(const struct pt_regs *__unused)
>  
> -#define COND_SYSCALL_COMPAT(name) \
> -	cond_syscall(__arm64_compat_sys_##name);
> +#define COND_SYSCALL_COMPAT(name) 							\
> +	asmlinkage long __weak __arm64_compat_sys_##name(const struct pt_regs *regs)	\
> +	{										\
> +		return sys_ni_syscall();						\
> +	}
>  
>  #define COMPAT_SYS_NI(name) \
>  	SYSCALL_ALIAS(__arm64_compat_sys_##name, sys_ni_posix_timers);
> @@ -70,7 +75,11 @@
>  #endif
>  
>  #ifndef COND_SYSCALL
> -#define COND_SYSCALL(name) cond_syscall(__arm64_sys_##name)
> +#define COND_SYSCALL(name)							\
> +	asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs)	\
> +	{									\
> +		return sys_ni_syscall();					\
> +	}
>  #endif
>  
>  #ifndef SYS_NI
> -- 
> 2.23.0.162.g0b9fbb3734-goog
> 

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

* Re: [PATCH] arm64: fix function types in COND_SYSCALL
  2019-09-11 15:15 ` Mark Rutland
@ 2019-09-12 13:11   ` Will Deacon
  2019-09-13 11:33     ` Mark Rutland
  0 siblings, 1 reply; 4+ messages in thread
From: Will Deacon @ 2019-09-12 13:11 UTC (permalink / raw)
  To: Mark Rutland
  Cc: Sami Tolvanen, Catalin Marinas, Kees Cook, linux-arm-kernel,
	linux-kernel

On Wed, Sep 11, 2019 at 04:15:46PM +0100, Mark Rutland wrote:
> On Tue, Sep 10, 2019 at 03:40:44PM -0700, Sami Tolvanen wrote:
> > Define a weak function in COND_SYSCALL instead of a weak alias to
> > sys_ni_syscall, which has an incompatible type. This fixes indirect
> > call mismatches with Control-Flow Integrity (CFI) checking.
> > 
> > Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
> 
> This looks correct to me, builds fine, and I asume has been tested, so FWIW:
> 
> Acked-by: Mark Rutland <mark.rutland@arm.com>
> 
> In looking at this, I came to the conclusion that we can drop the ifdeffery
> around our SYSCALL_DEFINE0(), COND_SYSCALL(), and SYS_NI(), which I evidently
> cargo-culted from x86 (where the ifdeffery is actually necessary).

Curious: why is it required on x86?

> I can send a follow up for that.

Yes, please.

Will

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

* Re: [PATCH] arm64: fix function types in COND_SYSCALL
  2019-09-12 13:11   ` Will Deacon
@ 2019-09-13 11:33     ` Mark Rutland
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Rutland @ 2019-09-13 11:33 UTC (permalink / raw)
  To: Will Deacon
  Cc: Sami Tolvanen, Catalin Marinas, Kees Cook, linux-arm-kernel,
	linux-kernel

On Thu, Sep 12, 2019 at 02:11:44PM +0100, Will Deacon wrote:
> On Wed, Sep 11, 2019 at 04:15:46PM +0100, Mark Rutland wrote:
> > On Tue, Sep 10, 2019 at 03:40:44PM -0700, Sami Tolvanen wrote:
> > > Define a weak function in COND_SYSCALL instead of a weak alias to
> > > sys_ni_syscall, which has an incompatible type. This fixes indirect
> > > call mismatches with Control-Flow Integrity (CFI) checking.
> > > 
> > > Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
> > 
> > This looks correct to me, builds fine, and I asume has been tested, so FWIW:
> > 
> > Acked-by: Mark Rutland <mark.rutland@arm.com>
> > 
> > In looking at this, I came to the conclusion that we can drop the ifdeffery
> > around our SYSCALL_DEFINE0(), COND_SYSCALL(), and SYS_NI(), which I evidently
> > cargo-culted from x86 (where the ifdeffery is actually necessary).
> 
> Curious: why is it required on x86?

Due to the way they share some native calls with (IA32) compat, but need
slightly different wrappers to marshall registers, they have ifdeffery
like:

#ifdef CONFIG_IA32_EMULATION
#define COND_SYSCALL(name)                                              \
        cond_syscall(__x64_sys_##name);                                 \
        cond_syscall(__ia32_sys_##name)
#endif

#ifndef COND_SYSCALL
#define COND_SYSCALL(name) cond_syscall(__x64_sys_##name)
#endif

... so that they define the compat wrapper when necessary, but not otherwise.

As we don't share the native syscall table with compat tasks, we don't
need to do anything like that, and can unconditionally define the native
case once.

> > I can send a follow up for that.
> 
> Yes, please.

I'll cook that up now, atop of Sami's patch applied to arm64's
for-next/core.

Thanks,
Mark.

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

end of thread, other threads:[~2019-09-13 11:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-10 22:40 [PATCH] arm64: fix function types in COND_SYSCALL Sami Tolvanen
2019-09-11 15:15 ` Mark Rutland
2019-09-12 13:11   ` Will Deacon
2019-09-13 11:33     ` Mark Rutland

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