1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
|
/* $OpenBSD: kern_ipc_35.c,v 1.3 2004/07/15 11:00:12 millert Exp $ */
/*
* Copyright (c) 2004 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/msg.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <sys/mount.h>
#include <sys/syscallargs.h>
#ifdef SYSVMSG
/*
* Old-style shmget(2) used int for the size parameter, we now use size_t.
*/
int
compat_35_sys_shmget(struct proc *p, void *v, register_t *retval)
{
struct compat_35_sys_shmget_args /* {
syscallarg(key_t) key;
syscallarg(int) size;
syscallarg(int) shmflg;
} */ *uap = v;
struct sys_shmget_args /* {
syscallarg(key_t) key;
syscallarg(size_t) size;
syscallarg(int) shmflg;
} */ shmget_args;
SCARG(&shmget_args, key) = SCARG(uap, key);
SCARG(&shmget_args, size) = (size_t)SCARG(uap, size);
SCARG(&shmget_args, shmflg) = SCARG(uap, shmflg);
return (sys_shmget(p, &shmget_args, retval));
}
#endif
#ifdef SYSVSEM
/*
* Old-style shmget(2) used u_int for the nsops parameter, we now use size_t.
*/
int
compat_35_sys_semop(struct proc *p, void *v, register_t *retval)
{
struct compat_35_sys_semop_args /* {
syscallarg(int) semid;
syscallarg(struct sembuf *) sops;
syscallarg(u_int) nsops;
} */ *uap = v;
struct sys_semop_args /* {
syscallarg(int) semid;
syscallarg(struct sembuf *) sops;
syscallarg(size_t) nsops;
} */ semop_args;
SCARG(&semop_args, semid) = SCARG(uap, semid);
SCARG(&semop_args, sops) = SCARG(uap, sops);
SCARG(&semop_args, nsops) = (size_t)SCARG(uap, nsops);
return (sys_semop(p, &semop_args, retval));
}
#endif
/*
* Convert between new and old struct {msq,sem,shm}id_ds (both ways)
*/
#if defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM)
#define cvt_ds(to, from, type, base) do { \
(to)->type##_perm.cuid = (from)->type##_perm.cuid; \
(to)->type##_perm.cgid = (from)->type##_perm.cgid; \
(to)->type##_perm.uid = (from)->type##_perm.uid; \
(to)->type##_perm.gid = (from)->type##_perm.gid; \
(to)->type##_perm.mode = (from)->type##_perm.mode & 0xffffU; \
(to)->type##_perm.seq = (from)->type##_perm.seq; \
(to)->type##_perm.key = (from)->type##_perm.key; \
bcopy((caddr_t)&(from)->base, (caddr_t)&(to)->base, \
sizeof(*(to)) - ((caddr_t)&(to)->base - (caddr_t)to)); \
} while (0)
#endif /* SYSVMSG || SYSVSEM || SYSVSHM */
#ifdef SYSVMSG
/*
* Copy a struct msqid_ds35 from userland and convert to struct msqid_ds
*/
static int
msqid_copyin(const void *uaddr, void *kaddr, size_t len)
{
struct msqid_ds *msqbuf = kaddr;
struct msqid_ds35 omsqbuf;
int error;
if (len != sizeof(struct msqid_ds))
return (EFAULT);
if ((error = copyin(uaddr, &omsqbuf, sizeof(omsqbuf))) == 0)
cvt_ds(msqbuf, &omsqbuf, msg, msg_first);
return (error);
}
/*
* Convert a struct msqid_ds to struct msqid_ds35 and copy to userland
*/
static int
msqid_copyout(const void *kaddr, void *uaddr, size_t len)
{
const struct msqid_ds *msqbuf = kaddr;
struct msqid_ds35 omsqbuf;
if (len != sizeof(struct msqid_ds))
return (EFAULT);
cvt_ds(&omsqbuf, msqbuf, msg, msg_first);
return (copyout(&omsqbuf, uaddr, sizeof(omsqbuf)));
}
/*
* OpenBSD 3.5 msgctl(2) with 16bit mode_t in struct ipcperm.
*/
int
compat_35_sys_msgctl(struct proc *p, void *v, register_t *retval)
{
struct compat_35_sys_msgctl_args /* {
syscallarg(int) msqid;
syscallarg(int) cmd;
syscallarg(struct msqid_ds35 *) buf;
} */ *uap = v;
return (msgctl1(p, SCARG(uap, msqid), SCARG(uap, cmd),
(caddr_t)SCARG(uap, buf), msqid_copyin, msqid_copyout));
}
#endif /* SYSVMSG */
#ifdef SYSVSEM
/*
* Copy a struct semid_ds35 from userland and convert to struct semid_ds
*/
static int
semid_copyin(const void *uaddr, void *kaddr, size_t len)
{
struct semid_ds *sembuf = kaddr;
struct semid_ds35 osembuf;
int error;
if (len != sizeof(struct semid_ds))
return (EFAULT);
if ((error = copyin(uaddr, &osembuf, sizeof(osembuf))) == 0)
cvt_ds(sembuf, &osembuf, sem, sem_base);
return (error);
}
/*
* Convert a struct semid_ds to struct semid_ds35 and copy to userland
*/
static int
semid_copyout(const void *kaddr, void *uaddr, size_t len)
{
const struct semid_ds *sembuf = kaddr;
struct semid_ds35 osembuf;
if (len != sizeof(struct semid_ds))
return (EFAULT);
cvt_ds(&osembuf, sembuf, sem, sem_base);
return (copyout(&osembuf, uaddr, sizeof(osembuf)));
}
/*
* OpenBSD 3.5 semctl(2) with 16bit mode_t in struct ipcperm.
*/
int
compat_35_sys___semctl(struct proc *p, void *v, register_t *retval)
{
struct compat_35_sys___semctl_args /* {
syscallarg(int) semid;
syscallarg(int) semnum;
syscallarg(int) cmd;
syscallarg(union semun *) arg;
} */ *uap = v;
union semun arg;
int error = 0, cmd = SCARG(uap, cmd);
switch (cmd) {
case IPC_SET:
case IPC_STAT:
case GETALL:
case SETVAL:
case SETALL:
error = copyin(SCARG(uap, arg), &arg, sizeof(arg));
break;
}
if (error == 0) {
error = semctl1(p, SCARG(uap, semid), SCARG(uap, semnum),
cmd, &arg, retval, semid_copyin, semid_copyout);
}
return (error);
}
#endif /* SYSVSEM */
#ifdef SYSVSHM
/*
* Copy a struct shmid_ds35 from userland and convert to struct shmid_ds
*/
static int
shmid_copyin(const void *uaddr, void *kaddr, size_t len)
{
struct shmid_ds *shmbuf = kaddr;
struct shmid_ds35 oshmbuf;
int error;
if (len != sizeof(struct shmid_ds))
return (EFAULT);
if ((error = copyin(uaddr, &oshmbuf, sizeof(oshmbuf))) == 0)
cvt_ds(shmbuf, &oshmbuf, shm, shm_segsz);
return (error);
}
/*
* Convert a struct shmid_ds to struct shmid_ds35 and copy to userland
*/
static int
shmid_copyout(const void *kaddr, void *uaddr, size_t len)
{
const struct shmid_ds *shmbuf = kaddr;
struct shmid_ds35 oshmbuf;
if (len != sizeof(struct shmid_ds))
return (EFAULT);
cvt_ds(&oshmbuf, shmbuf, shm, shm_segsz);
return (copyout(&oshmbuf, uaddr, sizeof(oshmbuf)));
}
/*
* OpenBSD 3.5 shmctl(2) with 16bit mode_t in struct ipcperm.
*/
int
compat_35_sys_shmctl(struct proc *p, void *v, register_t *retval)
{
struct compat_35_sys_shmctl_args /* {
syscallarg(int) shmid;
syscallarg(int) cmd;
syscallarg(struct shmid_ds35 *) buf;
} */ *uap = v;
return (shmctl1(p, SCARG(uap, shmid), SCARG(uap, cmd),
(caddr_t)SCARG(uap, buf), shmid_copyin, shmid_copyout));
}
#endif /* SYSVSHM */
|