Skip to contentSkip to conversation

fix function type mismatches in syscall wrappers

PATCH Superseded Sami Tolvanen 2 participants 6 messages May 1, 2019 – May 3, 2019 arm64

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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.

Sami Tolvanen (2):
arm64: fix syscall_fn_t type
arm64: use the correct function type in SYSCALL_DEFINE0

 arch/arm64/include/asm/syscall.h         |  2 +-
 arch/arm64/include/asm/syscall_wrapper.h | 18 +++++++++---------
 2 files changed, 10 insertions(+), 10 deletions(-)
Signature · 1 line
2.21.0.593.g511ec345e18-goog
#1 lore raw

PATCH 1/2 arm64: fix syscall_fn_t type

Use const struct pt_regs * instead of struct pt_regs * as the argument type 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
index a179df3674a1a..6206ab9bfcfc5 100644
@@ -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.21.0.593.g511ec345e18-goog
reviewer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] arm64: fix syscall_fn_t type

Quoted 3 lines · Sami Tolvanen

Use const struct pt_regs * instead of struct pt_regs * as the argument type to fix indirect call type mismatches with Control-Flow Integrity checking.

It's probably worth noting that in <asm/syscall_wrapper.h> all syscall wrappers take a const struct pt_regs *, which is where the mismatch comes from.

Quoted 11 lines
---
 arch/arm64/include/asm/syscall.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/include/asm/syscall.h +0 -0
index a179df3674a1a..6206ab9bfcfc5 100644

arch/arm64/include/asm/syscall.h line 23

Quoted 5 lines
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);

For a second I was worried that we modify the regs to assign the return value, but I see we do that in the syscall.c wrapper, where the pt_regs argument isn't const.

We certainly chouldn't need to modify the regs when acquiring the arguments, and as above this matches <asm/syscall_wrapper.h>, so this looks sound to me.

FWIW:

Thanks,
Mark.

#3 lore raw

PATCH 2/2 arm64: use the correct function type in SYSCALL_DEFINE0

In reply to Sami Tolvanen

Although 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
index a4477e515b798..507d0ee6bc690 100644
@@ -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.21.0.593.g511ec345e18-goog
reviewer
#4 lore raw

Re: [PATCH 2/2] arm64: use the correct function type in SYSCALL_DEFINE0

Quoted 3 lines · Sami Tolvanen

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

Generally, this makes sense, but I'm not sure that this is complete.

IIUC this introduces a new type mismatch with sys_ni_syscall() in some cases. We probably need that to use SYSCALL_DEFINE0(), and maybe have a ksys_ni_syscall() for in-kernel wrappers.

Thanks,
Mark.

Quoted 45 lines
---
 arch/arm64/include/asm/syscall_wrapper.h | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
arch/arm64/include/asm/syscall_wrapper.h +9 -9
index a4477e515b798..507d0ee6bc690 100644
@@ -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.21.0.593.g511ec345e18-goog
#5 lore raw

Re: [PATCH 2/2] arm64: use the correct function type in SYSCALL_DEFINE0

Hi Mark,

Quoted 4 lines · Mark Rutland

Generally, this makes sense, but I'm not sure that this is complete.

IIUC this introduces a new type mismatch with sys_ni_syscall() in some cases.

Thanks for the review. You're correct, sys_ni_syscall needs to be fixed too. I'll include this in v2.

Quoted 2 lines

We probably need that to use SYSCALL_DEFINE0(), and maybe have a ksys_ni_syscall() for in-kernel wrappers.

Why would we need ksys_ni_syscall? It seems something like this should be sufficient:

  asmlinkage long sys_ni_syscall(void);

  SYSCALL_DEFINE0(ni_syscall)
  {
          return sys_ni_syscall();
  }

Sami