Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[CVE-2009-0029] System call wrapper infrastructure

From: Martin Schwidefsky <schwidefsky@de.ibm.com>

By selecting HAVE_SYSCALL_WRAPPERS architectures can activate
system call wrappers in order to sign extend system call arguments.

All architectures where the ABI defines that the caller of a function
has to perform sign extension probably need this.

Reported-by: Christian Borntraeger <borntraeger@de.ibm.com>
Acked-by: Ralf Baechle <ralf@linux-mips.org>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>

+65
+3
arch/Kconfig
··· 62 62 See Documentation/unaligned-memory-access.txt for more 63 63 information on the topic of unaligned memory accesses. 64 64 65 + config HAVE_SYSCALL_WRAPPERS 66 + bool 67 + 65 68 config KRETPROBES 66 69 def_bool y 67 70 depends on KPROBES && HAVE_KRETPROBES
+62
include/linux/syscalls.h
··· 66 66 #include <linux/quota.h> 67 67 #include <linux/key.h> 68 68 69 + #define __SC_DECL1(t1, a1) t1 a1 70 + #define __SC_DECL2(t2, a2, ...) t2 a2, __SC_DECL1(__VA_ARGS__) 71 + #define __SC_DECL3(t3, a3, ...) t3 a3, __SC_DECL2(__VA_ARGS__) 72 + #define __SC_DECL4(t4, a4, ...) t4 a4, __SC_DECL3(__VA_ARGS__) 73 + #define __SC_DECL5(t5, a5, ...) t5 a5, __SC_DECL4(__VA_ARGS__) 74 + #define __SC_DECL6(t6, a6, ...) t6 a6, __SC_DECL5(__VA_ARGS__) 75 + 76 + #define __SC_LONG1(t1, a1) long a1 77 + #define __SC_LONG2(t2, a2, ...) long a2, __SC_LONG1(__VA_ARGS__) 78 + #define __SC_LONG3(t3, a3, ...) long a3, __SC_LONG2(__VA_ARGS__) 79 + #define __SC_LONG4(t4, a4, ...) long a4, __SC_LONG3(__VA_ARGS__) 80 + #define __SC_LONG5(t5, a5, ...) long a5, __SC_LONG4(__VA_ARGS__) 81 + #define __SC_LONG6(t6, a6, ...) long a6, __SC_LONG5(__VA_ARGS__) 82 + 83 + #define __SC_CAST1(t1, a1) (t1) a1 84 + #define __SC_CAST2(t2, a2, ...) (t2) a2, __SC_CAST1(__VA_ARGS__) 85 + #define __SC_CAST3(t3, a3, ...) (t3) a3, __SC_CAST2(__VA_ARGS__) 86 + #define __SC_CAST4(t4, a4, ...) (t4) a4, __SC_CAST3(__VA_ARGS__) 87 + #define __SC_CAST5(t5, a5, ...) (t5) a5, __SC_CAST4(__VA_ARGS__) 88 + #define __SC_CAST6(t6, a6, ...) (t6) a6, __SC_CAST5(__VA_ARGS__) 89 + 90 + #define __SC_TEST(type) BUILD_BUG_ON(sizeof(type) > sizeof(long)) 91 + #define __SC_TEST1(t1, a1) __SC_TEST(t1) 92 + #define __SC_TEST2(t2, a2, ...) __SC_TEST(t2); __SC_TEST1(__VA_ARGS__) 93 + #define __SC_TEST3(t3, a3, ...) __SC_TEST(t3); __SC_TEST2(__VA_ARGS__) 94 + #define __SC_TEST4(t4, a4, ...) __SC_TEST(t4); __SC_TEST3(__VA_ARGS__) 95 + #define __SC_TEST5(t5, a5, ...) __SC_TEST(t5); __SC_TEST4(__VA_ARGS__) 96 + #define __SC_TEST6(t6, a6, ...) __SC_TEST(t6); __SC_TEST5(__VA_ARGS__) 97 + 98 + #define SYSCALL_DEFINE0(name) asmlinkage long sys_##name(void) 99 + #define SYSCALL_DEFINE1(...) SYSCALL_DEFINEx(1, __VA_ARGS__) 100 + #define SYSCALL_DEFINE2(...) SYSCALL_DEFINEx(2, __VA_ARGS__) 101 + #define SYSCALL_DEFINE3(...) SYSCALL_DEFINEx(3, __VA_ARGS__) 102 + #define SYSCALL_DEFINE4(...) SYSCALL_DEFINEx(4, __VA_ARGS__) 103 + #define SYSCALL_DEFINE5(...) SYSCALL_DEFINEx(5, __VA_ARGS__) 104 + #define SYSCALL_DEFINE6(...) SYSCALL_DEFINEx(6, __VA_ARGS__) 105 + 106 + #define SYSCALL_ALIAS(alias, name) \ 107 + asm ("\t.globl " #alias "\n\t.set " #alias ", " #name) 108 + 109 + #ifdef CONFIG_HAVE_SYSCALL_WRAPPERS 110 + 111 + #define SYSCALL_DEFINE(name) static inline long SYSC_##name 112 + #define SYSCALL_DEFINEx(x, name, ...) \ 113 + asmlinkage long sys_##name(__SC_DECL##x(__VA_ARGS__)); \ 114 + static inline long SYSC_##name(__SC_DECL##x(__VA_ARGS__)); \ 115 + asmlinkage long SyS_##name(__SC_LONG##x(__VA_ARGS__)) \ 116 + { \ 117 + __SC_TEST##x(__VA_ARGS__); \ 118 + return (long) SYSC_##name(__SC_CAST##x(__VA_ARGS__)); \ 119 + } \ 120 + SYSCALL_ALIAS(sys_##name, SyS_##name); \ 121 + static inline long SYSC_##name(__SC_DECL##x(__VA_ARGS__)) 122 + 123 + #else /* CONFIG_HAVE_SYSCALL_WRAPPERS */ 124 + 125 + #define SYSCALL_DEFINE(name) asmlinkage long sys_##name 126 + #define SYSCALL_DEFINEx(x, name, ...) \ 127 + asmlinkage long sys_##name(__SC_DECL##x(__VA_ARGS__)) 128 + 129 + #endif /* CONFIG_HAVE_SYSCALL_WRAPPERS */ 130 + 69 131 asmlinkage long sys_time(time_t __user *tloc); 70 132 asmlinkage long sys_stime(time_t __user *tptr); 71 133 asmlinkage long sys_gettimeofday(struct timeval __user *tv,