Skip to content

Commit e340db5

Browse files
author
Dominik Brodowski
committed
ipc: add msgctl syscall/compat_syscall wrappers
Provide ksys_msgctl() and compat_ksys_msgctl() 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_msgctl() and compat_sys_msgctl(). 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 c84d079 commit e340db5

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

‎ipc/msg.c‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ static int msgctl_stat(struct ipc_namespace *ns, int msqid,
538538
return err;
539539
}
540540

541-
SYSCALL_DEFINE3(msgctl, int, msqid, int, cmd, struct msqid_ds __user *, buf)
541+
long ksys_msgctl(int msqid, int cmd, struct msqid_ds __user *buf)
542542
{
543543
int version;
544544
struct ipc_namespace *ns;
@@ -581,6 +581,11 @@ SYSCALL_DEFINE3(msgctl, int, msqid, int, cmd, struct msqid_ds __user *, buf)
581581
}
582582
}
583583

584+
SYSCALL_DEFINE3(msgctl, int, msqid, int, cmd, struct msqid_ds __user *, buf)
585+
{
586+
return ksys_msgctl(msqid, cmd, buf);
587+
}
588+
584589
#ifdef CONFIG_COMPAT
585590

586591
struct compat_msqid_ds {
@@ -651,7 +656,7 @@ static int copy_compat_msqid_to_user(void __user *buf, struct msqid64_ds *in,
651656
}
652657
}
653658

654-
COMPAT_SYSCALL_DEFINE3(msgctl, int, msqid, int, cmd, void __user *, uptr)
659+
long compat_ksys_msgctl(int msqid, int cmd, void __user *uptr)
655660
{
656661
struct ipc_namespace *ns;
657662
int err;
@@ -692,6 +697,11 @@ COMPAT_SYSCALL_DEFINE3(msgctl, int, msqid, int, cmd, void __user *, uptr)
692697
return -EINVAL;
693698
}
694699
}
700+
701+
COMPAT_SYSCALL_DEFINE3(msgctl, int, msqid, int, cmd, void __user *, uptr)
702+
{
703+
return compat_ksys_msgctl(msqid, cmd, uptr);
704+
}
695705
#endif
696706

697707
static int testmsg(struct msg_msg *msg, long type, int mode)

‎ipc/syscall.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ SYSCALL_DEFINE6(ipc, unsigned int, call, int, first, unsigned long, second,
7070
case MSGGET:
7171
return ksys_msgget((key_t) first, second);
7272
case MSGCTL:
73-
return sys_msgctl(first, second, (struct msqid_ds __user *)ptr);
73+
return ksys_msgctl(first, second,
74+
(struct msqid_ds __user *)ptr);
7475

7576
case SHMAT:
7677
switch (version) {
@@ -163,7 +164,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
163164
case MSGGET:
164165
return ksys_msgget(first, second);
165166
case MSGCTL:
166-
return compat_sys_msgctl(first, second, compat_ptr(ptr));
167+
return compat_ksys_msgctl(first, second, compat_ptr(ptr));
167168

168169
case SHMAT: {
169170
int err;

‎ipc/util.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ long ksys_semtimedop(int semid, struct sembuf __user *tsops,
243243
long ksys_semget(key_t key, int nsems, int semflg);
244244
long ksys_semctl(int semid, int semnum, int cmd, unsigned long arg);
245245
long ksys_msgget(key_t key, int msgflg);
246+
long ksys_msgctl(int msqid, int cmd, struct msqid_ds __user *buf);
246247
long ksys_shmget(key_t key, size_t size, int shmflg);
247248
long ksys_shmdt(char __user *shmaddr);
248249
long ksys_shmctl(int shmid, int cmd, struct shmid_ds __user *buf);
@@ -253,6 +254,7 @@ long compat_ksys_semtimedop(int semid, struct sembuf __user *tsems,
253254
unsigned int nsops,
254255
const struct compat_timespec __user *timeout);
255256
long compat_ksys_semctl(int semid, int semnum, int cmd, int arg);
257+
long compat_ksys_msgctl(int msqid, int cmd, void __user *uptr);
256258
long compat_ksys_shmctl(int shmid, int cmd, void __user *uptr);
257259
#endif /* CONFIG_COMPAT */
258260

0 commit comments

Comments
 (0)