]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
baed7fc9 CH |
2 | /* |
3 | * sys_ipc() is the old de-multiplexer for the SysV IPC calls. | |
4 | * | |
5 | * This is really horribly ugly, and new architectures should just wire up | |
6 | * the individual syscalls instead. | |
7 | */ | |
8 | #include <linux/unistd.h> | |
20bc2a3a | 9 | #include <linux/syscalls.h> |
41f4f0e2 DB |
10 | #include <linux/security.h> |
11 | #include <linux/ipc_namespace.h> | |
12 | #include "util.h" | |
baed7fc9 CH |
13 | |
14 | #ifdef __ARCH_WANT_SYS_IPC | |
15 | #include <linux/errno.h> | |
16 | #include <linux/ipc.h> | |
17 | #include <linux/shm.h> | |
baed7fc9 CH |
18 | #include <linux/uaccess.h> |
19 | ||
58fa4a41 AB |
20 | int ksys_ipc(unsigned int call, int first, unsigned long second, |
21 | unsigned long third, void __user * ptr, long fifth) | |
baed7fc9 CH |
22 | { |
23 | int version, ret; | |
24 | ||
25 | version = call >> 16; /* hack for backward compatibility */ | |
26 | call &= 0xffff; | |
27 | ||
28 | switch (call) { | |
29 | case SEMOP: | |
41f4f0e2 DB |
30 | return ksys_semtimedop(first, (struct sembuf __user *)ptr, |
31 | second, NULL); | |
baed7fc9 | 32 | case SEMTIMEDOP: |
3ca47e95 | 33 | if (IS_ENABLED(CONFIG_64BIT)) |
5dc0b152 AB |
34 | return ksys_semtimedop(first, ptr, second, |
35 | (const struct __kernel_timespec __user *)fifth); | |
36 | else if (IS_ENABLED(CONFIG_COMPAT_32BIT_TIME)) | |
37 | return compat_ksys_semtimedop(first, ptr, second, | |
9afc5eee | 38 | (const struct old_timespec32 __user *)fifth); |
5dc0b152 AB |
39 | else |
40 | return -ENOSYS; | |
baed7fc9 CH |
41 | |
42 | case SEMGET: | |
69894718 | 43 | return ksys_semget(first, second, third); |
baed7fc9 | 44 | case SEMCTL: { |
e1fd1f49 | 45 | unsigned long arg; |
baed7fc9 CH |
46 | if (!ptr) |
47 | return -EINVAL; | |
e1fd1f49 | 48 | if (get_user(arg, (unsigned long __user *) ptr)) |
baed7fc9 | 49 | return -EFAULT; |
275f2214 | 50 | return ksys_old_semctl(first, second, third, arg); |
baed7fc9 CH |
51 | } |
52 | ||
53 | case MSGSND: | |
31c213f2 | 54 | return ksys_msgsnd(first, (struct msgbuf __user *) ptr, |
baed7fc9 CH |
55 | second, third); |
56 | case MSGRCV: | |
57 | switch (version) { | |
58 | case 0: { | |
59 | struct ipc_kludge tmp; | |
60 | if (!ptr) | |
61 | return -EINVAL; | |
62 | ||
63 | if (copy_from_user(&tmp, | |
64 | (struct ipc_kludge __user *) ptr, | |
65 | sizeof(tmp))) | |
66 | return -EFAULT; | |
078faac9 | 67 | return ksys_msgrcv(first, tmp.msgp, second, |
baed7fc9 CH |
68 | tmp.msgtyp, third); |
69 | } | |
70 | default: | |
078faac9 | 71 | return ksys_msgrcv(first, |
baed7fc9 CH |
72 | (struct msgbuf __user *) ptr, |
73 | second, fifth, third); | |
74 | } | |
75 | case MSGGET: | |
3d65661a | 76 | return ksys_msgget((key_t) first, second); |
baed7fc9 | 77 | case MSGCTL: |
275f2214 | 78 | return ksys_old_msgctl(first, second, |
e340db56 | 79 | (struct msqid_ds __user *)ptr); |
baed7fc9 CH |
80 | |
81 | case SHMAT: | |
82 | switch (version) { | |
83 | default: { | |
84 | unsigned long raddr; | |
85 | ret = do_shmat(first, (char __user *)ptr, | |
079a96ae | 86 | second, &raddr, SHMLBA); |
baed7fc9 CH |
87 | if (ret) |
88 | return ret; | |
89 | return put_user(raddr, (unsigned long __user *) third); | |
90 | } | |
91 | case 1: | |
92 | /* | |
93 | * This was the entry point for kernel-originating calls | |
94 | * from iBCS2 in 2.2 days. | |
95 | */ | |
96 | return -EINVAL; | |
97 | } | |
98 | case SHMDT: | |
da1e2744 | 99 | return ksys_shmdt((char __user *)ptr); |
baed7fc9 | 100 | case SHMGET: |
65749e0b | 101 | return ksys_shmget(first, second, third); |
baed7fc9 | 102 | case SHMCTL: |
275f2214 | 103 | return ksys_old_shmctl(first, second, |
baed7fc9 CH |
104 | (struct shmid_ds __user *) ptr); |
105 | default: | |
106 | return -ENOSYS; | |
107 | } | |
108 | } | |
58fa4a41 AB |
109 | |
110 | SYSCALL_DEFINE6(ipc, unsigned int, call, int, first, unsigned long, second, | |
111 | unsigned long, third, void __user *, ptr, long, fifth) | |
112 | { | |
113 | return ksys_ipc(call, first, second, third, ptr, fifth); | |
114 | } | |
baed7fc9 | 115 | #endif |
20bc2a3a AV |
116 | |
117 | #ifdef CONFIG_COMPAT | |
118 | #include <linux/compat.h> | |
119 | ||
120 | #ifndef COMPAT_SHMLBA | |
121 | #define COMPAT_SHMLBA SHMLBA | |
122 | #endif | |
123 | ||
124 | struct compat_ipc_kludge { | |
125 | compat_uptr_t msgp; | |
126 | compat_long_t msgtyp; | |
127 | }; | |
128 | ||
129 | #ifdef CONFIG_ARCH_WANT_OLD_COMPAT_IPC | |
58fa4a41 AB |
130 | int compat_ksys_ipc(u32 call, int first, int second, |
131 | u32 third, compat_uptr_t ptr, u32 fifth) | |
20bc2a3a AV |
132 | { |
133 | int version; | |
134 | u32 pad; | |
135 | ||
136 | version = call >> 16; /* hack for backward compatibility */ | |
137 | call &= 0xffff; | |
138 | ||
139 | switch (call) { | |
140 | case SEMOP: | |
141 | /* struct sembuf is the same on 32 and 64bit :)) */ | |
41f4f0e2 | 142 | return ksys_semtimedop(first, compat_ptr(ptr), second, NULL); |
20bc2a3a | 143 | case SEMTIMEDOP: |
5dc0b152 AB |
144 | if (!IS_ENABLED(CONFIG_COMPAT_32BIT_TIME)) |
145 | return -ENOSYS; | |
41f4f0e2 | 146 | return compat_ksys_semtimedop(first, compat_ptr(ptr), second, |
20bc2a3a AV |
147 | compat_ptr(fifth)); |
148 | case SEMGET: | |
69894718 | 149 | return ksys_semget(first, second, third); |
20bc2a3a AV |
150 | case SEMCTL: |
151 | if (!ptr) | |
152 | return -EINVAL; | |
153 | if (get_user(pad, (u32 __user *) compat_ptr(ptr))) | |
154 | return -EFAULT; | |
275f2214 | 155 | return compat_ksys_old_semctl(first, second, third, pad); |
20bc2a3a AV |
156 | |
157 | case MSGSND: | |
31c213f2 | 158 | return compat_ksys_msgsnd(first, ptr, second, third); |
20bc2a3a AV |
159 | |
160 | case MSGRCV: { | |
161 | void __user *uptr = compat_ptr(ptr); | |
162 | ||
163 | if (first < 0 || second < 0) | |
164 | return -EINVAL; | |
165 | ||
166 | if (!version) { | |
167 | struct compat_ipc_kludge ipck; | |
168 | if (!uptr) | |
169 | return -EINVAL; | |
170 | if (copy_from_user(&ipck, uptr, sizeof(ipck))) | |
171 | return -EFAULT; | |
078faac9 | 172 | return compat_ksys_msgrcv(first, ipck.msgp, second, |
20bc2a3a AV |
173 | ipck.msgtyp, third); |
174 | } | |
078faac9 | 175 | return compat_ksys_msgrcv(first, ptr, second, fifth, third); |
20bc2a3a AV |
176 | } |
177 | case MSGGET: | |
3d65661a | 178 | return ksys_msgget(first, second); |
20bc2a3a | 179 | case MSGCTL: |
275f2214 | 180 | return compat_ksys_old_msgctl(first, second, compat_ptr(ptr)); |
20bc2a3a AV |
181 | |
182 | case SHMAT: { | |
183 | int err; | |
184 | unsigned long raddr; | |
185 | ||
186 | if (version == 1) | |
187 | return -EINVAL; | |
188 | err = do_shmat(first, compat_ptr(ptr), second, &raddr, | |
189 | COMPAT_SHMLBA); | |
190 | if (err < 0) | |
191 | return err; | |
6aa211e8 | 192 | return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third)); |
20bc2a3a AV |
193 | } |
194 | case SHMDT: | |
da1e2744 | 195 | return ksys_shmdt(compat_ptr(ptr)); |
20bc2a3a | 196 | case SHMGET: |
65749e0b | 197 | return ksys_shmget(first, (unsigned int)second, third); |
20bc2a3a | 198 | case SHMCTL: |
275f2214 | 199 | return compat_ksys_old_shmctl(first, second, compat_ptr(ptr)); |
20bc2a3a AV |
200 | } |
201 | ||
202 | return -ENOSYS; | |
203 | } | |
58fa4a41 AB |
204 | |
205 | COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second, | |
206 | u32, third, compat_uptr_t, ptr, u32, fifth) | |
207 | { | |
208 | return compat_ksys_ipc(call, first, second, third, ptr, fifth); | |
209 | } | |
20bc2a3a AV |
210 | #endif |
211 | #endif |