Skip to content

Commit 078faac

Browse files
author
Dominik Brodowski
committed
ipc: add msgrcv syscall/compat_syscall wrappers
Provide ksys_msgrcv() and compat_ksys_msgrcv() 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_msgrcv() and compat_sys_msgrcv(). 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 e340db5 commit 078faac

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

ipc/msg.c

+16-3
Original file line numberDiff line numberDiff line change
@@ -1150,10 +1150,16 @@ static long do_msgrcv(int msqid, void __user *buf, size_t bufsz, long msgtyp, in
11501150
return bufsz;
11511151
}
11521152

1153+
long ksys_msgrcv(int msqid, struct msgbuf __user *msgp, size_t msgsz,
1154+
long msgtyp, int msgflg)
1155+
{
1156+
return do_msgrcv(msqid, msgp, msgsz, msgtyp, msgflg, do_msg_fill);
1157+
}
1158+
11531159
SYSCALL_DEFINE5(msgrcv, int, msqid, struct msgbuf __user *, msgp, size_t, msgsz,
11541160
long, msgtyp, int, msgflg)
11551161
{
1156-
return do_msgrcv(msqid, msgp, msgsz, msgtyp, msgflg, do_msg_fill);
1162+
return ksys_msgrcv(msqid, msgp, msgsz, msgtyp, msgflg);
11571163
}
11581164

11591165
#ifdef CONFIG_COMPAT
@@ -1171,12 +1177,19 @@ static long compat_do_msg_fill(void __user *dest, struct msg_msg *msg, size_t bu
11711177
return msgsz;
11721178
}
11731179

1174-
COMPAT_SYSCALL_DEFINE5(msgrcv, int, msqid, compat_uptr_t, msgp,
1175-
compat_ssize_t, msgsz, compat_long_t, msgtyp, int, msgflg)
1180+
long compat_ksys_msgrcv(int msqid, compat_uptr_t msgp, compat_ssize_t msgsz,
1181+
compat_long_t msgtyp, int msgflg)
11761182
{
11771183
return do_msgrcv(msqid, compat_ptr(msgp), (ssize_t)msgsz, (long)msgtyp,
11781184
msgflg, compat_do_msg_fill);
11791185
}
1186+
1187+
COMPAT_SYSCALL_DEFINE5(msgrcv, int, msqid, compat_uptr_t, msgp,
1188+
compat_ssize_t, msgsz, compat_long_t, msgtyp,
1189+
int, msgflg)
1190+
{
1191+
return compat_ksys_msgrcv(msqid, msgp, msgsz, msgtyp, msgflg);
1192+
}
11801193
#endif
11811194

11821195
int msg_init_ns(struct ipc_namespace *ns)

ipc/syscall.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ SYSCALL_DEFINE6(ipc, unsigned int, call, int, first, unsigned long, second,
5959
(struct ipc_kludge __user *) ptr,
6060
sizeof(tmp)))
6161
return -EFAULT;
62-
return sys_msgrcv(first, tmp.msgp, second,
62+
return ksys_msgrcv(first, tmp.msgp, second,
6363
tmp.msgtyp, third);
6464
}
6565
default:
66-
return sys_msgrcv(first,
66+
return ksys_msgrcv(first,
6767
(struct msgbuf __user *) ptr,
6868
second, fifth, third);
6969
}
@@ -156,10 +156,10 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
156156
return -EINVAL;
157157
if (copy_from_user(&ipck, uptr, sizeof(ipck)))
158158
return -EFAULT;
159-
return compat_sys_msgrcv(first, ipck.msgp, second,
159+
return compat_ksys_msgrcv(first, ipck.msgp, second,
160160
ipck.msgtyp, third);
161161
}
162-
return compat_sys_msgrcv(first, ptr, second, fifth, third);
162+
return compat_ksys_msgrcv(first, ptr, second, fifth, third);
163163
}
164164
case MSGGET:
165165
return ksys_msgget(first, second);

ipc/util.h

+4
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ 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);
246246
long ksys_msgctl(int msqid, int cmd, struct msqid_ds __user *buf);
247+
long ksys_msgrcv(int msqid, struct msgbuf __user *msgp, size_t msgsz,
248+
long msgtyp, int msgflg);
247249
long ksys_shmget(key_t key, size_t size, int shmflg);
248250
long ksys_shmdt(char __user *shmaddr);
249251
long ksys_shmctl(int shmid, int cmd, struct shmid_ds __user *buf);
@@ -255,6 +257,8 @@ long compat_ksys_semtimedop(int semid, struct sembuf __user *tsems,
255257
const struct compat_timespec __user *timeout);
256258
long compat_ksys_semctl(int semid, int semnum, int cmd, int arg);
257259
long compat_ksys_msgctl(int msqid, int cmd, void __user *uptr);
260+
long compat_ksys_msgrcv(int msqid, compat_uptr_t msgp, compat_ssize_t msgsz,
261+
compat_long_t msgtyp, int msgflg);
258262
long compat_ksys_shmctl(int shmid, int cmd, void __user *uptr);
259263
#endif /* CONFIG_COMPAT */
260264

0 commit comments

Comments
 (0)