Skip to content

Commit 41f4f0e

Browse files
author
Dominik Brodowski
committed
ipc: add semtimedop syscall/compat_syscall wrappers
Provide ksys_semtimedop() and compat_ksys_semtimedop() wrappers to avoid in-kernel calls to these syscalls. The ksys_ prefix denotes that these functions are meant as a drop-in replacement for the syscalls. In particular, they use the same calling convention as sys_semtimedop() and compat_sys_semtimedop(). This patch is part of a series which removes in-kernel calls to syscalls. On this basis, the syscall entry path can be streamlined. For details, see http://lkml.kernel.org/r/20180325162527.GA17492@light.dominikbrodowski.net Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
1 parent 6df3546 commit 41f4f0e

3 files changed

Lines changed: 41 additions & 12 deletions

File tree

‎ipc/sem.c‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,8 +2120,8 @@ static long do_semtimedop(int semid, struct sembuf __user *tsops,
21202120
return error;
21212121
}
21222122

2123-
SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,
2124-
unsigned, nsops, const struct timespec __user *, timeout)
2123+
long ksys_semtimedop(int semid, struct sembuf __user *tsops,
2124+
unsigned int nsops, const struct timespec __user *timeout)
21252125
{
21262126
if (timeout) {
21272127
struct timespec64 ts;
@@ -2132,10 +2132,16 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,
21322132
return do_semtimedop(semid, tsops, nsops, NULL);
21332133
}
21342134

2135+
SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,
2136+
unsigned int, nsops, const struct timespec __user *, timeout)
2137+
{
2138+
return ksys_semtimedop(semid, tsops, nsops, timeout);
2139+
}
2140+
21352141
#ifdef CONFIG_COMPAT
2136-
COMPAT_SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsems,
2137-
unsigned, nsops,
2138-
const struct compat_timespec __user *, timeout)
2142+
long compat_ksys_semtimedop(int semid, struct sembuf __user *tsems,
2143+
unsigned int nsops,
2144+
const struct compat_timespec __user *timeout)
21392145
{
21402146
if (timeout) {
21412147
struct timespec64 ts;
@@ -2145,6 +2151,13 @@ COMPAT_SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsems,
21452151
}
21462152
return do_semtimedop(semid, tsems, nsops, NULL);
21472153
}
2154+
2155+
COMPAT_SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsems,
2156+
unsigned int, nsops,
2157+
const struct compat_timespec __user *, timeout)
2158+
{
2159+
return compat_ksys_semtimedop(semid, tsems, nsops, timeout);
2160+
}
21482161
#endif
21492162

21502163
SYSCALL_DEFINE3(semop, int, semid, struct sembuf __user *, tsops,

‎ipc/syscall.c‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
*/
88
#include <linux/unistd.h>
99
#include <linux/syscalls.h>
10+
#include <linux/security.h>
11+
#include <linux/ipc_namespace.h>
12+
#include "util.h"
1013

1114
#ifdef __ARCH_WANT_SYS_IPC
1215
#include <linux/errno.h>
@@ -24,12 +27,12 @@ SYSCALL_DEFINE6(ipc, unsigned int, call, int, first, unsigned long, second,
2427

2528
switch (call) {
2629
case SEMOP:
27-
return sys_semtimedop(first, (struct sembuf __user *)ptr,
28-
second, NULL);
30+
return ksys_semtimedop(first, (struct sembuf __user *)ptr,
31+
second, NULL);
2932
case SEMTIMEDOP:
30-
return sys_semtimedop(first, (struct sembuf __user *)ptr,
31-
second,
32-
(const struct timespec __user *)fifth);
33+
return ksys_semtimedop(first, (struct sembuf __user *)ptr,
34+
second,
35+
(const struct timespec __user *)fifth);
3336

3437
case SEMGET:
3538
return sys_semget(first, second, third);
@@ -124,9 +127,9 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
124127
switch (call) {
125128
case SEMOP:
126129
/* struct sembuf is the same on 32 and 64bit :)) */
127-
return sys_semtimedop(first, compat_ptr(ptr), second, NULL);
130+
return ksys_semtimedop(first, compat_ptr(ptr), second, NULL);
128131
case SEMTIMEDOP:
129-
return compat_sys_semtimedop(first, compat_ptr(ptr), second,
132+
return compat_ksys_semtimedop(first, compat_ptr(ptr), second,
130133
compat_ptr(fifth));
131134
case SEMGET:
132135
return sys_semget(first, second, third);

‎ipc/util.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,17 @@ static inline int compat_ipc_parse_version(int *cmd)
235235
#endif
236236
}
237237
#endif
238+
239+
/* for __ARCH_WANT_SYS_IPC */
240+
long ksys_semtimedop(int semid, struct sembuf __user *tsops,
241+
unsigned int nsops,
242+
const struct timespec __user *timeout);
243+
244+
/* for CONFIG_ARCH_WANT_OLD_COMPAT_IPC */
245+
#ifdef CONFIG_COMPAT
246+
long compat_ksys_semtimedop(int semid, struct sembuf __user *tsems,
247+
unsigned int nsops,
248+
const struct compat_timespec __user *timeout);
249+
#endif /* CONFIG_COMPAT */
250+
238251
#endif

0 commit comments

Comments
 (0)