Skip to content

Commit d969c6f

Browse files
author
Dominik Brodowski
committed
ipc: add semctl syscall/compat_syscall wrappers
Provide ksys_semctl() and compat_ksys_semctl() 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_semctl() and compat_sys_semctl(). 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 6989471 commit d969c6f

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

‎ipc/sem.c‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,7 @@ static int semctl_down(struct ipc_namespace *ns, int semid,
15811581
return err;
15821582
}
15831583

1584-
SYSCALL_DEFINE4(semctl, int, semid, int, semnum, int, cmd, unsigned long, arg)
1584+
long ksys_semctl(int semid, int semnum, int cmd, unsigned long arg)
15851585
{
15861586
int version;
15871587
struct ipc_namespace *ns;
@@ -1635,6 +1635,11 @@ SYSCALL_DEFINE4(semctl, int, semid, int, semnum, int, cmd, unsigned long, arg)
16351635
}
16361636
}
16371637

1638+
SYSCALL_DEFINE4(semctl, int, semid, int, semnum, int, cmd, unsigned long, arg)
1639+
{
1640+
return ksys_semctl(semid, semnum, cmd, arg);
1641+
}
1642+
16381643
#ifdef CONFIG_COMPAT
16391644

16401645
struct compat_semid_ds {
@@ -1683,7 +1688,7 @@ static int copy_compat_semid_to_user(void __user *buf, struct semid64_ds *in,
16831688
}
16841689
}
16851690

1686-
COMPAT_SYSCALL_DEFINE4(semctl, int, semid, int, semnum, int, cmd, int, arg)
1691+
long compat_ksys_semctl(int semid, int semnum, int cmd, int arg)
16871692
{
16881693
void __user *p = compat_ptr(arg);
16891694
struct ipc_namespace *ns;
@@ -1727,6 +1732,11 @@ COMPAT_SYSCALL_DEFINE4(semctl, int, semid, int, semnum, int, cmd, int, arg)
17271732
return -EINVAL;
17281733
}
17291734
}
1735+
1736+
COMPAT_SYSCALL_DEFINE4(semctl, int, semid, int, semnum, int, cmd, int, arg)
1737+
{
1738+
return compat_ksys_semctl(semid, semnum, cmd, arg);
1739+
}
17301740
#endif
17311741

17321742
/* If the task doesn't already have a undo_list, then allocate one

‎ipc/syscall.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ SYSCALL_DEFINE6(ipc, unsigned int, call, int, first, unsigned long, second,
4242
return -EINVAL;
4343
if (get_user(arg, (unsigned long __user *) ptr))
4444
return -EFAULT;
45-
return sys_semctl(first, second, third, arg);
45+
return ksys_semctl(first, second, third, arg);
4646
}
4747

4848
case MSGSND:
@@ -138,7 +138,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
138138
return -EINVAL;
139139
if (get_user(pad, (u32 __user *) compat_ptr(ptr)))
140140
return -EFAULT;
141-
return compat_sys_semctl(first, second, third, pad);
141+
return compat_ksys_semctl(first, second, third, pad);
142142

143143
case MSGSND:
144144
return compat_sys_msgsnd(first, ptr, second, third);

‎ipc/util.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,14 @@ long ksys_semtimedop(int semid, struct sembuf __user *tsops,
241241
unsigned int nsops,
242242
const struct timespec __user *timeout);
243243
long ksys_semget(key_t key, int nsems, int semflg);
244+
long ksys_semctl(int semid, int semnum, int cmd, unsigned long arg);
244245

245246
/* for CONFIG_ARCH_WANT_OLD_COMPAT_IPC */
246247
#ifdef CONFIG_COMPAT
247248
long compat_ksys_semtimedop(int semid, struct sembuf __user *tsems,
248249
unsigned int nsops,
249250
const struct compat_timespec __user *timeout);
251+
long compat_ksys_semctl(int semid, int semnum, int cmd, int arg);
250252
#endif /* CONFIG_COMPAT */
251253

252254
#endif

0 commit comments

Comments
 (0)