Skip to content

Commit a4aebe9

Browse files
committed
posix-timers: Get rid of [COMPAT_]SYS_NI() uses
Only the posix timer system calls use this (when the posix timer support is disabled, which does not actually happen in any normal case), because they had debug code to print out a warning about missing system calls. Get rid of that special case, and just use the standard COND_SYSCALL interface that creates weak system call stubs that return -ENOSYS for when the system call does not exist. This fixes a kCFI issue with the SYS_NI() hackery: CFI failure at int80_emulation+0x67/0xb0 (target: sys_ni_posix_timers+0x0/0x70; expected type: 0xb02b34d9) WARNING: CPU: 0 PID: 48 at int80_emulation+0x67/0xb0 Reported-by: kernel test robot <[email protected]> Reviewed-by: Sami Tolvanen <[email protected]> Tested-by: Sami Tolvanen <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Borislav Petkov <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent eee7f5b commit a4aebe9

File tree

6 files changed

+19
-96
lines changed

6 files changed

+19
-96
lines changed

arch/arm64/include/asm/syscall_wrapper.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@
4444
return sys_ni_syscall(); \
4545
}
4646

47-
#define COMPAT_SYS_NI(name) \
48-
SYSCALL_ALIAS(__arm64_compat_sys_##name, sys_ni_posix_timers);
49-
5047
#endif /* CONFIG_COMPAT */
5148

5249
#define __SYSCALL_DEFINEx(x, name, ...) \
@@ -81,6 +78,5 @@
8178
}
8279

8380
asmlinkage long __arm64_sys_ni_syscall(const struct pt_regs *__unused);
84-
#define SYS_NI(name) SYSCALL_ALIAS(__arm64_sys_##name, sys_ni_posix_timers);
8581

8682
#endif /* __ASM_SYSCALL_WRAPPER_H */

arch/riscv/include/asm/syscall_wrapper.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ asmlinkage long __riscv_sys_ni_syscall(const struct pt_regs *);
4646
return sys_ni_syscall(); \
4747
}
4848

49-
#define COMPAT_SYS_NI(name) \
50-
SYSCALL_ALIAS(__riscv_compat_sys_##name, sys_ni_posix_timers);
51-
5249
#endif /* CONFIG_COMPAT */
5350

5451
#define __SYSCALL_DEFINEx(x, name, ...) \
@@ -82,6 +79,4 @@ asmlinkage long __riscv_sys_ni_syscall(const struct pt_regs *);
8279
return sys_ni_syscall(); \
8380
}
8481

85-
#define SYS_NI(name) SYSCALL_ALIAS(__riscv_sys_##name, sys_ni_posix_timers);
86-
8782
#endif /* __ASM_SYSCALL_WRAPPER_H */

arch/s390/include/asm/syscall_wrapper.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@
6363
cond_syscall(__s390x_sys_##name); \
6464
cond_syscall(__s390_sys_##name)
6565

66-
#define SYS_NI(name) \
67-
SYSCALL_ALIAS(__s390x_sys_##name, sys_ni_posix_timers); \
68-
SYSCALL_ALIAS(__s390_sys_##name, sys_ni_posix_timers)
69-
7066
#define COMPAT_SYSCALL_DEFINEx(x, name, ...) \
7167
long __s390_compat_sys##name(struct pt_regs *regs); \
7268
ALLOW_ERROR_INJECTION(__s390_compat_sys##name, ERRNO); \
@@ -85,15 +81,11 @@
8581

8682
/*
8783
* As some compat syscalls may not be implemented, we need to expand
88-
* COND_SYSCALL_COMPAT in kernel/sys_ni.c and COMPAT_SYS_NI in
89-
* kernel/time/posix-stubs.c to cover this case as well.
84+
* COND_SYSCALL_COMPAT in kernel/sys_ni.c to cover this case as well.
9085
*/
9186
#define COND_SYSCALL_COMPAT(name) \
9287
cond_syscall(__s390_compat_sys_##name)
9388

94-
#define COMPAT_SYS_NI(name) \
95-
SYSCALL_ALIAS(__s390_compat_sys_##name, sys_ni_posix_timers)
96-
9789
#define __S390_SYS_STUBx(x, name, ...) \
9890
long __s390_sys##name(struct pt_regs *regs); \
9991
ALLOW_ERROR_INJECTION(__s390_sys##name, ERRNO); \
@@ -124,9 +116,6 @@
124116
#define COND_SYSCALL(name) \
125117
cond_syscall(__s390x_sys_##name)
126118

127-
#define SYS_NI(name) \
128-
SYSCALL_ALIAS(__s390x_sys_##name, sys_ni_posix_timers)
129-
130119
#define __S390_SYS_STUBx(x, fullname, name, ...)
131120

132121
#endif /* CONFIG_COMPAT */

arch/x86/include/asm/syscall_wrapper.h

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ extern long __ia32_sys_ni_syscall(const struct pt_regs *regs);
8686
return sys_ni_syscall(); \
8787
}
8888

89-
#define __SYS_NI(abi, name) \
90-
SYSCALL_ALIAS(__##abi##_##name, sys_ni_posix_timers);
91-
9289
#ifdef CONFIG_X86_64
9390
#define __X64_SYS_STUB0(name) \
9491
__SYS_STUB0(x64, sys_##name)
@@ -100,13 +97,10 @@ extern long __ia32_sys_ni_syscall(const struct pt_regs *regs);
10097
#define __X64_COND_SYSCALL(name) \
10198
__COND_SYSCALL(x64, sys_##name)
10299

103-
#define __X64_SYS_NI(name) \
104-
__SYS_NI(x64, sys_##name)
105100
#else /* CONFIG_X86_64 */
106101
#define __X64_SYS_STUB0(name)
107102
#define __X64_SYS_STUBx(x, name, ...)
108103
#define __X64_COND_SYSCALL(name)
109-
#define __X64_SYS_NI(name)
110104
#endif /* CONFIG_X86_64 */
111105

112106
#if defined(CONFIG_X86_32) || defined(CONFIG_IA32_EMULATION)
@@ -120,13 +114,10 @@ extern long __ia32_sys_ni_syscall(const struct pt_regs *regs);
120114
#define __IA32_COND_SYSCALL(name) \
121115
__COND_SYSCALL(ia32, sys_##name)
122116

123-
#define __IA32_SYS_NI(name) \
124-
__SYS_NI(ia32, sys_##name)
125117
#else /* CONFIG_X86_32 || CONFIG_IA32_EMULATION */
126118
#define __IA32_SYS_STUB0(name)
127119
#define __IA32_SYS_STUBx(x, name, ...)
128120
#define __IA32_COND_SYSCALL(name)
129-
#define __IA32_SYS_NI(name)
130121
#endif /* CONFIG_X86_32 || CONFIG_IA32_EMULATION */
131122

132123
#ifdef CONFIG_IA32_EMULATION
@@ -135,8 +126,7 @@ extern long __ia32_sys_ni_syscall(const struct pt_regs *regs);
135126
* additional wrappers (aptly named __ia32_sys_xyzzy) which decode the
136127
* ia32 regs in the proper order for shared or "common" syscalls. As some
137128
* syscalls may not be implemented, we need to expand COND_SYSCALL in
138-
* kernel/sys_ni.c and SYS_NI in kernel/time/posix-stubs.c to cover this
139-
* case as well.
129+
* kernel/sys_ni.c to cover this case as well.
140130
*/
141131
#define __IA32_COMPAT_SYS_STUB0(name) \
142132
__SYS_STUB0(ia32, compat_sys_##name)
@@ -148,14 +138,10 @@ extern long __ia32_sys_ni_syscall(const struct pt_regs *regs);
148138
#define __IA32_COMPAT_COND_SYSCALL(name) \
149139
__COND_SYSCALL(ia32, compat_sys_##name)
150140

151-
#define __IA32_COMPAT_SYS_NI(name) \
152-
__SYS_NI(ia32, compat_sys_##name)
153-
154141
#else /* CONFIG_IA32_EMULATION */
155142
#define __IA32_COMPAT_SYS_STUB0(name)
156143
#define __IA32_COMPAT_SYS_STUBx(x, name, ...)
157144
#define __IA32_COMPAT_COND_SYSCALL(name)
158-
#define __IA32_COMPAT_SYS_NI(name)
159145
#endif /* CONFIG_IA32_EMULATION */
160146

161147

@@ -175,13 +161,10 @@ extern long __ia32_sys_ni_syscall(const struct pt_regs *regs);
175161
#define __X32_COMPAT_COND_SYSCALL(name) \
176162
__COND_SYSCALL(x64, compat_sys_##name)
177163

178-
#define __X32_COMPAT_SYS_NI(name) \
179-
__SYS_NI(x64, compat_sys_##name)
180164
#else /* CONFIG_X86_X32_ABI */
181165
#define __X32_COMPAT_SYS_STUB0(name)
182166
#define __X32_COMPAT_SYS_STUBx(x, name, ...)
183167
#define __X32_COMPAT_COND_SYSCALL(name)
184-
#define __X32_COMPAT_SYS_NI(name)
185168
#endif /* CONFIG_X86_X32_ABI */
186169

187170

@@ -212,17 +195,12 @@ extern long __ia32_sys_ni_syscall(const struct pt_regs *regs);
212195

213196
/*
214197
* As some compat syscalls may not be implemented, we need to expand
215-
* COND_SYSCALL_COMPAT in kernel/sys_ni.c and COMPAT_SYS_NI in
216-
* kernel/time/posix-stubs.c to cover this case as well.
198+
* COND_SYSCALL_COMPAT in kernel/sys_ni.c to cover this case as well.
217199
*/
218200
#define COND_SYSCALL_COMPAT(name) \
219201
__IA32_COMPAT_COND_SYSCALL(name) \
220202
__X32_COMPAT_COND_SYSCALL(name)
221203

222-
#define COMPAT_SYS_NI(name) \
223-
__IA32_COMPAT_SYS_NI(name) \
224-
__X32_COMPAT_SYS_NI(name)
225-
226204
#endif /* CONFIG_COMPAT */
227205

228206
#define __SYSCALL_DEFINEx(x, name, ...) \
@@ -243,8 +221,8 @@ extern long __ia32_sys_ni_syscall(const struct pt_regs *regs);
243221
* As the generic SYSCALL_DEFINE0() macro does not decode any parameters for
244222
* obvious reasons, and passing struct pt_regs *regs to it in %rdi does not
245223
* hurt, we only need to re-define it here to keep the naming congruent to
246-
* SYSCALL_DEFINEx() -- which is essential for the COND_SYSCALL() and SYS_NI()
247-
* macros to work correctly.
224+
* SYSCALL_DEFINEx() -- which is essential for the COND_SYSCALL() macro
225+
* to work correctly.
248226
*/
249227
#define SYSCALL_DEFINE0(sname) \
250228
SYSCALL_METADATA(_##sname, 0); \
@@ -257,10 +235,6 @@ extern long __ia32_sys_ni_syscall(const struct pt_regs *regs);
257235
__X64_COND_SYSCALL(name) \
258236
__IA32_COND_SYSCALL(name)
259237

260-
#define SYS_NI(name) \
261-
__X64_SYS_NI(name) \
262-
__IA32_SYS_NI(name)
263-
264238

265239
/*
266240
* For VSYSCALLS, we need to declare these three syscalls with the new

kernel/sys_ni.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,20 @@ COND_SYSCALL(recvmmsg_time32);
201201
COND_SYSCALL_COMPAT(recvmmsg_time32);
202202
COND_SYSCALL_COMPAT(recvmmsg_time64);
203203

204+
/* Posix timer syscalls may be configured out */
205+
COND_SYSCALL(timer_create);
206+
COND_SYSCALL(timer_gettime);
207+
COND_SYSCALL(timer_getoverrun);
208+
COND_SYSCALL(timer_settime);
209+
COND_SYSCALL(timer_delete);
210+
COND_SYSCALL(clock_adjtime);
211+
COND_SYSCALL(getitimer);
212+
COND_SYSCALL(setitimer);
213+
COND_SYSCALL(alarm);
214+
COND_SYSCALL_COMPAT(timer_create);
215+
COND_SYSCALL_COMPAT(getitimer);
216+
COND_SYSCALL_COMPAT(setitimer);
217+
204218
/*
205219
* Architecture specific syscalls: see further below
206220
*/

kernel/time/posix-stubs.c

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,6 @@
1717
#include <linux/time_namespace.h>
1818
#include <linux/compat.h>
1919

20-
#ifdef CONFIG_ARCH_HAS_SYSCALL_WRAPPER
21-
/* Architectures may override SYS_NI and COMPAT_SYS_NI */
22-
#include <asm/syscall_wrapper.h>
23-
#endif
24-
25-
asmlinkage long sys_ni_posix_timers(void)
26-
{
27-
pr_err_once("process %d (%s) attempted a POSIX timer syscall "
28-
"while CONFIG_POSIX_TIMERS is not set\n",
29-
current->pid, current->comm);
30-
return -ENOSYS;
31-
}
32-
33-
#ifndef SYS_NI
34-
#define SYS_NI(name) SYSCALL_ALIAS(sys_##name, sys_ni_posix_timers)
35-
#endif
36-
37-
#ifndef COMPAT_SYS_NI
38-
#define COMPAT_SYS_NI(name) SYSCALL_ALIAS(compat_sys_##name, sys_ni_posix_timers)
39-
#endif
40-
41-
SYS_NI(timer_create);
42-
SYS_NI(timer_gettime);
43-
SYS_NI(timer_getoverrun);
44-
SYS_NI(timer_settime);
45-
SYS_NI(timer_delete);
46-
SYS_NI(clock_adjtime);
47-
SYS_NI(getitimer);
48-
SYS_NI(setitimer);
49-
SYS_NI(clock_adjtime32);
50-
#ifdef __ARCH_WANT_SYS_ALARM
51-
SYS_NI(alarm);
52-
#endif
53-
5420
/*
5521
* We preserve minimal support for CLOCK_REALTIME and CLOCK_MONOTONIC
5622
* as it is easy to remain compatible with little code. CLOCK_BOOTTIME
@@ -158,18 +124,7 @@ SYSCALL_DEFINE4(clock_nanosleep, const clockid_t, which_clock, int, flags,
158124
which_clock);
159125
}
160126

161-
#ifdef CONFIG_COMPAT
162-
COMPAT_SYS_NI(timer_create);
163-
#endif
164-
165-
#if defined(CONFIG_COMPAT) || defined(CONFIG_ALPHA)
166-
COMPAT_SYS_NI(getitimer);
167-
COMPAT_SYS_NI(setitimer);
168-
#endif
169-
170127
#ifdef CONFIG_COMPAT_32BIT_TIME
171-
SYS_NI(timer_settime32);
172-
SYS_NI(timer_gettime32);
173128

174129
SYSCALL_DEFINE2(clock_settime32, const clockid_t, which_clock,
175130
struct old_timespec32 __user *, tp)

0 commit comments

Comments
 (0)