fix function type mismatches in syscall wrappers
v3 cover fix function type mismatches in syscall wrappers
These patches fix type mismatches in arm64 syscall wrapper definitions, which trip indirect call checks with Control-Flow Integrity.
Changes in v3:
- instead of SYSCALL_DEFINE0, just define __arm64_sys_ni_syscall with the correct type to avoid unnecessary error injection
Changes in v2:
- more informative commit message for the syscall_fn_t change
- added a patch for fixing sys_ni_syscall
Sami Tolvanen (3):
arm64: fix syscall_fn_t type
arm64: use the correct function type in SYSCALL_DEFINE0
arm64: use the correct function type for __arm64_sys_ni_syscall
arch/arm64/include/asm/syscall.h | 2 +- arch/arm64/include/asm/syscall_wrapper.h | 18 +++++++++--------- arch/arm64/kernel/sys.c | 14 +++++++++----- arch/arm64/kernel/sys32.c | 7 ++----- 4 files changed, 21 insertions(+), 20 deletions(-)
Signature · 1 line
2.22.0.rc1.257.g3120a18244-goog
PATCH v3 1/3 arm64: fix syscall_fn_t type
Syscall wrappers in <asm/syscall_wrapper.h> use const struct pt_regs * as the argument type. Use const in syscall_fn_t as well to fix indirect call type mismatches with Control-Flow Integrity checking.
--- arch/arm64/include/asm/syscall.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/include/asm/syscall.h +1 -1
@@ -20,7 +20,7 @@#include <linux/compat.h> #include <linux/err.h> -typedef long (*syscall_fn_t )(struct pt_regs *regs); +typedef long (*syscall_fn_t )(const struct pt_regs *regs);extern const syscall_fn_t sys_call_table[];
Signature · 1 line
2.22.0.rc1.257.g3120a18244-goog
PATCH v3 2/3 arm64: use the correct function type in SYSCALL_DEFINE0
In reply to Sami TolvanenAlthough a syscall defined using SYSCALL_DEFINE0 doesn't accept parameters, use the correct function type to avoid indirect call type mismatches with Control-Flow Integrity checking.
--- arch/arm64/include/asm/syscall_wrapper.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
arch/arm64/include/asm/syscall_wrapper.h +9 -9
@@ -30,10 +30,10 @@ } \ static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) -#define COMPAT_SYSCALL_DEFINE0 (sname) \ - asmlinkage long __arm64_compat_sys_##sname(void); \ - ALLOW_ERROR_INJECTION(__arm64_compat_sys_##sname, ERRNO); \ - asmlinkage long __arm64_compat_sys_##sname(void) +#define COMPAT_SYSCALL_DEFINE0 (sname) \ + asmlinkage long __arm64_compat_sys_##sname(const struct pt_regs *__unused); \ + 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);
@@ -62,11 +62,11 @@ static inline long __do_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))#ifndef SYSCALL_DEFINE0 -#define SYSCALL_DEFINE0 (sname) \ - SYSCALL_METADATA(_##sname, 0); \ - asmlinkage long __arm64_sys_##sname(void); \ - ALLOW_ERROR_INJECTION(__arm64_sys_##sname, ERRNO); \ - asmlinkage long __arm64_sys_##sname(void) +#define SYSCALL_DEFINE0 (sname) \ + SYSCALL_METADATA(_##sname, 0); \ + asmlinkage long __arm64_sys_##sname(const struct pt_regs *__unused); \ + ALLOW_ERROR_INJECTION(__arm64_sys_##sname, ERRNO); \ + asmlinkage long __arm64_sys_##sname(const struct pt_regs *__unused)#endif #ifndef COND_SYSCALL
Signature · 1 line
2.22.0.rc1.257.g3120a18244-goog
PATCH v3 3/3 arm64: use the correct function type for __arm64_sys_ni_syscall
In reply to Sami TolvanenCalling sys_ni_syscall through a syscall_fn_t pointer trips indirect call Control-Flow Integrity checking due to a function type mismatch. Use SYSCALL_DEFINE0 for __arm64_sys_ni_syscall instead and remove the now unnecessary casts.
--- arch/arm64/kernel/sys.c | 14 +++++++++----- arch/arm64/kernel/sys32.c | 7 ++----- 2 files changed, 11 insertions(+), 10 deletions(-)
arch/arm64/kernel/sys.c +9 -5
@@ -47,22 +47,26 @@ SYSCALL_DEFINE1(arm64_personality, unsigned int, personality)return ksys_personality (personality); } +asmlinkage long sys_ni_syscall (void ); + +asmlinkage long __arm64_sys_ni_syscall (const struct pt_regs *__unused) +{ +return sys_ni_syscall (); +} +/* * Wrappers to pass the pt_regs argument. */ #define sys_personality sys_arm64_personality -asmlinkage long sys_ni_syscall (const struct pt_regs *); -#define __arm64_sys_ni_syscall sys_ni_syscall -#undef __SYSCALL#define __SYSCALL (nr, sym) asmlinkage long __arm64_##sym(const struct pt_regs *);#include <asm/unistd.h> #undef __SYSCALL -#define __SYSCALL (nr, sym) [nr] = (syscall_fn_t)__arm64_##sym, +#define __SYSCALL (nr, sym) [nr] = __arm64_##sym,const syscall_fn_t sys_call_table[__NR_syscalls] = { - [0 ... __NR_syscalls -1 ] = (syscall_fn_t )sys_ni_syscall, + [0 ... __NR_syscalls -1 ] = __arm64_sys_ni_syscall, #include <asm/unistd.h> };
arch/arm64/kernel/sys32.c +2 -5
@@ -133,17 +133,14 @@ COMPAT_SYSCALL_DEFINE6(aarch32_fallocate, int, fd, int, mode,return ksys_fallocate (fd, mode,arg_u64 (offset),arg_u64 (len)); } -asmlinkage long sys_ni_syscall (const struct pt_regs *); -#define __arm64_sys_ni_syscall sys_ni_syscall -#undef __SYSCALL#define __SYSCALL (nr, sym) asmlinkage long __arm64_##sym(const struct pt_regs *);#include <asm/unistd32.h> #undef __SYSCALL -#define __SYSCALL (nr, sym) [nr] = (syscall_fn_t)__arm64_##sym, +#define __SYSCALL (nr, sym) [nr] = __arm64_##sym,const syscall_fn_t compat_sys_call_table[__NR_compat_syscalls] = { - [0 ... __NR_compat_syscalls -1 ] = (syscall_fn_t )sys_ni_syscall, + [0 ... __NR_compat_syscalls -1 ] = __arm64_sys_ni_syscall, #include <asm/unistd32.h> };
Signature · 1 line
2.22.0.rc1.257.g3120a18244-goog
Quoted 7 lines · Sami Tolvanen
These patches fix type mismatches in arm64 syscall wrapper definitions, which trip indirect call checks with Control-Flow Integrity.
Changes in v3:
- instead ofSYSCALL_DEFINE0, just define__arm64_sys_ni_syscallwith the correct type to avoid unnecessary error injection
Thanks, I've picked this up for -rc3.
Will