]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
1da177e4 LT |
2 | /* |
3 | * ioctl32.c: Conversion between 32bit and 64bit native ioctls. | |
4 | * | |
5 | * Copyright (C) 1997-2000 Jakub Jelinek ([email protected]) | |
6 | * Copyright (C) 1998 Eddie C. Dost ([email protected]) | |
7 | * Copyright (C) 2001,2002 Andi Kleen, SuSE Labs | |
a2531293 | 8 | * Copyright (C) 2003 Pavel Machek ([email protected]) |
1da177e4 LT |
9 | * |
10 | * These routines maintain argument size conversion between 32bit and 64bit | |
11 | * ioctls. | |
12 | */ | |
13 | ||
3fee37c1 AM |
14 | #include <linux/joystick.h> |
15 | ||
1da177e4 LT |
16 | #include <linux/types.h> |
17 | #include <linux/compat.h> | |
18 | #include <linux/kernel.h> | |
16f7e0fe | 19 | #include <linux/capability.h> |
1da177e4 LT |
20 | #include <linux/compiler.h> |
21 | #include <linux/sched.h> | |
22 | #include <linux/smp.h> | |
1da177e4 LT |
23 | #include <linux/ioctl.h> |
24 | #include <linux/if.h> | |
bff61975 | 25 | #include <linux/raid/md_u.h> |
3e63cbb1 | 26 | #include <linux/falloc.h> |
1da177e4 | 27 | #include <linux/file.h> |
4b32da2b | 28 | #include <linux/ppp-ioctl.h> |
1da177e4 LT |
29 | #include <linux/if_pppox.h> |
30 | #include <linux/mtio.h> | |
1da177e4 LT |
31 | #include <linux/tty.h> |
32 | #include <linux/vt_kern.h> | |
1da177e4 | 33 | #include <linux/raw.h> |
1da177e4 | 34 | #include <linux/blkdev.h> |
1da177e4 LT |
35 | #include <linux/rtc.h> |
36 | #include <linux/pci.h> | |
1da177e4 | 37 | #include <linux/serial.h> |
1da177e4 | 38 | #include <linux/ctype.h> |
1da177e4 | 39 | #include <linux/syscalls.h> |
5a0e3ad6 | 40 | #include <linux/gfp.h> |
594edf39 | 41 | #include <linux/cec.h> |
1da177e4 | 42 | |
66cf191f AV |
43 | #include "internal.h" |
44 | ||
1da177e4 | 45 | #include <net/bluetooth/bluetooth.h> |
f49daa81 | 46 | #include <net/bluetooth/hci_sock.h> |
1da177e4 LT |
47 | #include <net/bluetooth/rfcomm.h> |
48 | ||
49 | #include <linux/capi.h> | |
5024ad4a | 50 | #include <linux/gigaset_dev.h> |
1da177e4 | 51 | |
3c3622dc | 52 | #ifdef CONFIG_BLOCK |
390192b3 JS |
53 | #include <linux/cdrom.h> |
54 | #include <linux/fd.h> | |
1da177e4 | 55 | #include <scsi/scsi.h> |
1da177e4 | 56 | #include <scsi/scsi_ioctl.h> |
1da177e4 | 57 | #include <scsi/sg.h> |
3c3622dc | 58 | #endif |
1da177e4 | 59 | |
7c0f6ba6 | 60 | #include <linux/uaccess.h> |
1da177e4 | 61 | #include <linux/watchdog.h> |
1da177e4 | 62 | |
1da177e4 | 63 | #include <linux/soundcard.h> |
1da177e4 LT |
64 | |
65 | #include <linux/hiddev.h> | |
66 | ||
6e87abd0 | 67 | |
661f627d AB |
68 | #include <linux/sort.h> |
69 | ||
8163904e | 70 | #ifdef CONFIG_SPARC |
0976d4e1 | 71 | #include <linux/fb.h> |
8163904e DM |
72 | #include <asm/fbio.h> |
73 | #endif | |
74 | ||
a7f61e89 JH |
75 | #define convert_in_user(srcptr, dstptr) \ |
76 | ({ \ | |
77 | typeof(*srcptr) val; \ | |
78 | \ | |
79 | get_user(val, srcptr) || put_user(val, dstptr); \ | |
80 | }) | |
81 | ||
66cf191f | 82 | static int do_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
b4341721 JH |
83 | { |
84 | int err; | |
85 | ||
86 | err = security_file_ioctl(file, cmd, arg); | |
87 | if (err) | |
88 | return err; | |
89 | ||
66cf191f | 90 | return vfs_ioctl(file, cmd, arg); |
b4341721 JH |
91 | } |
92 | ||
9361401e | 93 | #ifdef CONFIG_BLOCK |
1da177e4 LT |
94 | typedef struct sg_io_hdr32 { |
95 | compat_int_t interface_id; /* [i] 'S' for SCSI generic (required) */ | |
96 | compat_int_t dxfer_direction; /* [i] data transfer direction */ | |
97 | unsigned char cmd_len; /* [i] SCSI command length ( <= 16 bytes) */ | |
98 | unsigned char mx_sb_len; /* [i] max length to write to sbp */ | |
99 | unsigned short iovec_count; /* [i] 0 implies no scatter gather */ | |
100 | compat_uint_t dxfer_len; /* [i] byte count of data transfer */ | |
101 | compat_uint_t dxferp; /* [i], [*io] points to data transfer memory | |
102 | or scatter gather list */ | |
103 | compat_uptr_t cmdp; /* [i], [*i] points to command to perform */ | |
104 | compat_uptr_t sbp; /* [i], [*o] points to sense_buffer memory */ | |
105 | compat_uint_t timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */ | |
106 | compat_uint_t flags; /* [i] 0 -> default, see SG_FLAG... */ | |
107 | compat_int_t pack_id; /* [i->o] unused internally (normally) */ | |
108 | compat_uptr_t usr_ptr; /* [i->o] unused internally */ | |
109 | unsigned char status; /* [o] scsi status */ | |
110 | unsigned char masked_status; /* [o] shifted, masked scsi status */ | |
111 | unsigned char msg_status; /* [o] messaging level data (optional) */ | |
112 | unsigned char sb_len_wr; /* [o] byte count actually written to sbp */ | |
113 | unsigned short host_status; /* [o] errors from host adapter */ | |
114 | unsigned short driver_status; /* [o] errors from software driver */ | |
115 | compat_int_t resid; /* [o] dxfer_len - actual_transferred */ | |
116 | compat_uint_t duration; /* [o] time taken by cmd (unit: millisec) */ | |
117 | compat_uint_t info; /* [o] auxiliary information */ | |
118 | } sg_io_hdr32_t; /* 64 bytes long (on sparc32) */ | |
119 | ||
120 | typedef struct sg_iovec32 { | |
121 | compat_uint_t iov_base; | |
122 | compat_uint_t iov_len; | |
123 | } sg_iovec32_t; | |
124 | ||
125 | static int sg_build_iovec(sg_io_hdr_t __user *sgio, void __user *dxferp, u16 iovec_count) | |
126 | { | |
127 | sg_iovec_t __user *iov = (sg_iovec_t __user *) (sgio + 1); | |
128 | sg_iovec32_t __user *iov32 = dxferp; | |
129 | int i; | |
130 | ||
131 | for (i = 0; i < iovec_count; i++) { | |
132 | u32 base, len; | |
133 | ||
134 | if (get_user(base, &iov32[i].iov_base) || | |
135 | get_user(len, &iov32[i].iov_len) || | |
136 | put_user(compat_ptr(base), &iov[i].iov_base) || | |
137 | put_user(len, &iov[i].iov_len)) | |
138 | return -EFAULT; | |
139 | } | |
140 | ||
141 | if (put_user(iov, &sgio->dxferp)) | |
142 | return -EFAULT; | |
143 | return 0; | |
144 | } | |
145 | ||
66cf191f | 146 | static int sg_ioctl_trans(struct file *file, unsigned int cmd, |
43c6e7b9 | 147 | sg_io_hdr32_t __user *sgio32) |
1da177e4 LT |
148 | { |
149 | sg_io_hdr_t __user *sgio; | |
1da177e4 LT |
150 | u16 iovec_count; |
151 | u32 data; | |
152 | void __user *dxferp; | |
153 | int err; | |
84eb8fb4 FT |
154 | int interface_id; |
155 | ||
156 | if (get_user(interface_id, &sgio32->interface_id)) | |
157 | return -EFAULT; | |
158 | if (interface_id != 'S') | |
66cf191f | 159 | return do_ioctl(file, cmd, (unsigned long)sgio32); |
1da177e4 | 160 | |
1da177e4 LT |
161 | if (get_user(iovec_count, &sgio32->iovec_count)) |
162 | return -EFAULT; | |
163 | ||
164 | { | |
165 | void __user *top = compat_alloc_user_space(0); | |
166 | void __user *new = compat_alloc_user_space(sizeof(sg_io_hdr_t) + | |
167 | (iovec_count * sizeof(sg_iovec_t))); | |
168 | if (new > top) | |
169 | return -EINVAL; | |
170 | ||
171 | sgio = new; | |
172 | } | |
173 | ||
174 | /* Ok, now construct. */ | |
175 | if (copy_in_user(&sgio->interface_id, &sgio32->interface_id, | |
176 | (2 * sizeof(int)) + | |
177 | (2 * sizeof(unsigned char)) + | |
178 | (1 * sizeof(unsigned short)) + | |
179 | (1 * sizeof(unsigned int)))) | |
180 | return -EFAULT; | |
181 | ||
182 | if (get_user(data, &sgio32->dxferp)) | |
183 | return -EFAULT; | |
184 | dxferp = compat_ptr(data); | |
185 | if (iovec_count) { | |
186 | if (sg_build_iovec(sgio, dxferp, iovec_count)) | |
187 | return -EFAULT; | |
188 | } else { | |
189 | if (put_user(dxferp, &sgio->dxferp)) | |
190 | return -EFAULT; | |
191 | } | |
192 | ||
193 | { | |
194 | unsigned char __user *cmdp; | |
195 | unsigned char __user *sbp; | |
196 | ||
197 | if (get_user(data, &sgio32->cmdp)) | |
198 | return -EFAULT; | |
199 | cmdp = compat_ptr(data); | |
200 | ||
201 | if (get_user(data, &sgio32->sbp)) | |
202 | return -EFAULT; | |
203 | sbp = compat_ptr(data); | |
204 | ||
205 | if (put_user(cmdp, &sgio->cmdp) || | |
206 | put_user(sbp, &sgio->sbp)) | |
207 | return -EFAULT; | |
208 | } | |
209 | ||
210 | if (copy_in_user(&sgio->timeout, &sgio32->timeout, | |
211 | 3 * sizeof(int))) | |
212 | return -EFAULT; | |
213 | ||
214 | if (get_user(data, &sgio32->usr_ptr)) | |
215 | return -EFAULT; | |
216 | if (put_user(compat_ptr(data), &sgio->usr_ptr)) | |
217 | return -EFAULT; | |
218 | ||
66cf191f | 219 | err = do_ioctl(file, cmd, (unsigned long) sgio); |
1da177e4 LT |
220 | |
221 | if (err >= 0) { | |
222 | void __user *datap; | |
223 | ||
224 | if (copy_in_user(&sgio32->pack_id, &sgio->pack_id, | |
225 | sizeof(int)) || | |
226 | get_user(datap, &sgio->usr_ptr) || | |
227 | put_user((u32)(unsigned long)datap, | |
228 | &sgio32->usr_ptr) || | |
229 | copy_in_user(&sgio32->status, &sgio->status, | |
230 | (4 * sizeof(unsigned char)) + | |
231 | (2 * sizeof(unsigned short)) + | |
232 | (3 * sizeof(int)))) | |
233 | err = -EFAULT; | |
234 | } | |
235 | ||
236 | return err; | |
237 | } | |
238 | ||
2966387b AK |
239 | struct compat_sg_req_info { /* used by SG_GET_REQUEST_TABLE ioctl() */ |
240 | char req_state; | |
241 | char orphan; | |
242 | char sg_io_owned; | |
243 | char problem; | |
244 | int pack_id; | |
245 | compat_uptr_t usr_ptr; | |
246 | unsigned int duration; | |
247 | int unused; | |
248 | }; | |
249 | ||
66cf191f | 250 | static int sg_grt_trans(struct file *file, |
b4341721 | 251 | unsigned int cmd, struct compat_sg_req_info __user *o) |
2966387b AK |
252 | { |
253 | int err, i; | |
6b2b4e5a | 254 | sg_req_info_t __user *r; |
2966387b | 255 | r = compat_alloc_user_space(sizeof(sg_req_info_t)*SG_MAX_QUEUE); |
66cf191f | 256 | err = do_ioctl(file, cmd, (unsigned long)r); |
2966387b AK |
257 | if (err < 0) |
258 | return err; | |
259 | for (i = 0; i < SG_MAX_QUEUE; i++) { | |
260 | void __user *ptr; | |
261 | int d; | |
262 | ||
263 | if (copy_in_user(o + i, r + i, offsetof(sg_req_info_t, usr_ptr)) || | |
264 | get_user(ptr, &r[i].usr_ptr) || | |
265 | get_user(d, &r[i].duration) || | |
266 | put_user((u32)(unsigned long)(ptr), &o[i].usr_ptr) || | |
267 | put_user(d, &o[i].duration)) | |
268 | return -EFAULT; | |
269 | } | |
270 | return err; | |
271 | } | |
9361401e | 272 | #endif /* CONFIG_BLOCK */ |
2966387b | 273 | |
1da177e4 LT |
274 | struct sock_fprog32 { |
275 | unsigned short len; | |
276 | compat_caddr_t filter; | |
277 | }; | |
278 | ||
279 | #define PPPIOCSPASS32 _IOW('t', 71, struct sock_fprog32) | |
280 | #define PPPIOCSACTIVE32 _IOW('t', 70, struct sock_fprog32) | |
281 | ||
66cf191f | 282 | static int ppp_sock_fprog_ioctl_trans(struct file *file, |
b4341721 | 283 | unsigned int cmd, struct sock_fprog32 __user *u_fprog32) |
1da177e4 | 284 | { |
1da177e4 LT |
285 | struct sock_fprog __user *u_fprog64 = compat_alloc_user_space(sizeof(struct sock_fprog)); |
286 | void __user *fptr64; | |
287 | u32 fptr32; | |
288 | u16 flen; | |
289 | ||
290 | if (get_user(flen, &u_fprog32->len) || | |
291 | get_user(fptr32, &u_fprog32->filter)) | |
292 | return -EFAULT; | |
293 | ||
294 | fptr64 = compat_ptr(fptr32); | |
295 | ||
296 | if (put_user(flen, &u_fprog64->len) || | |
297 | put_user(fptr64, &u_fprog64->filter)) | |
298 | return -EFAULT; | |
299 | ||
300 | if (cmd == PPPIOCSPASS32) | |
301 | cmd = PPPIOCSPASS; | |
302 | else | |
303 | cmd = PPPIOCSACTIVE; | |
304 | ||
66cf191f | 305 | return do_ioctl(file, cmd, (unsigned long) u_fprog64); |
1da177e4 LT |
306 | } |
307 | ||
308 | struct ppp_option_data32 { | |
309 | compat_caddr_t ptr; | |
310 | u32 length; | |
311 | compat_int_t transmit; | |
312 | }; | |
313 | #define PPPIOCSCOMPRESS32 _IOW('t', 77, struct ppp_option_data32) | |
314 | ||
315 | struct ppp_idle32 { | |
316 | compat_time_t xmit_idle; | |
317 | compat_time_t recv_idle; | |
318 | }; | |
319 | #define PPPIOCGIDLE32 _IOR('t', 63, struct ppp_idle32) | |
320 | ||
66cf191f | 321 | static int ppp_gidle(struct file *file, unsigned int cmd, |
43c6e7b9 | 322 | struct ppp_idle32 __user *idle32) |
1da177e4 LT |
323 | { |
324 | struct ppp_idle __user *idle; | |
1da177e4 LT |
325 | __kernel_time_t xmit, recv; |
326 | int err; | |
327 | ||
328 | idle = compat_alloc_user_space(sizeof(*idle)); | |
1da177e4 | 329 | |
66cf191f | 330 | err = do_ioctl(file, PPPIOCGIDLE, (unsigned long) idle); |
1da177e4 LT |
331 | |
332 | if (!err) { | |
333 | if (get_user(xmit, &idle->xmit_idle) || | |
334 | get_user(recv, &idle->recv_idle) || | |
335 | put_user(xmit, &idle32->xmit_idle) || | |
336 | put_user(recv, &idle32->recv_idle)) | |
337 | err = -EFAULT; | |
338 | } | |
339 | return err; | |
340 | } | |
341 | ||
66cf191f | 342 | static int ppp_scompress(struct file *file, unsigned int cmd, |
43c6e7b9 | 343 | struct ppp_option_data32 __user *odata32) |
1da177e4 LT |
344 | { |
345 | struct ppp_option_data __user *odata; | |
1da177e4 LT |
346 | __u32 data; |
347 | void __user *datap; | |
348 | ||
349 | odata = compat_alloc_user_space(sizeof(*odata)); | |
1da177e4 LT |
350 | |
351 | if (get_user(data, &odata32->ptr)) | |
352 | return -EFAULT; | |
353 | ||
354 | datap = compat_ptr(data); | |
355 | if (put_user(datap, &odata->ptr)) | |
356 | return -EFAULT; | |
357 | ||
358 | if (copy_in_user(&odata->length, &odata32->length, | |
359 | sizeof(__u32) + sizeof(int))) | |
360 | return -EFAULT; | |
361 | ||
66cf191f | 362 | return do_ioctl(file, PPPIOCSCOMPRESS, (unsigned long) odata); |
1da177e4 LT |
363 | } |
364 | ||
9361401e | 365 | #ifdef CONFIG_BLOCK |
1da177e4 LT |
366 | struct mtget32 { |
367 | compat_long_t mt_type; | |
368 | compat_long_t mt_resid; | |
369 | compat_long_t mt_dsreg; | |
370 | compat_long_t mt_gstat; | |
371 | compat_long_t mt_erreg; | |
372 | compat_daddr_t mt_fileno; | |
373 | compat_daddr_t mt_blkno; | |
374 | }; | |
375 | #define MTIOCGET32 _IOR('m', 2, struct mtget32) | |
376 | ||
377 | struct mtpos32 { | |
378 | compat_long_t mt_blkno; | |
379 | }; | |
380 | #define MTIOCPOS32 _IOR('m', 3, struct mtpos32) | |
381 | ||
66cf191f | 382 | static int mt_ioctl_trans(struct file *file, |
b4341721 | 383 | unsigned int cmd, void __user *argp) |
1da177e4 | 384 | { |
a7f61e89 JH |
385 | /* NULL initialization to make gcc shut up */ |
386 | struct mtget __user *get = NULL; | |
1da177e4 | 387 | struct mtget32 __user *umget32; |
a7f61e89 | 388 | struct mtpos __user *pos = NULL; |
1da177e4 LT |
389 | struct mtpos32 __user *upos32; |
390 | unsigned long kcmd; | |
391 | void *karg; | |
392 | int err = 0; | |
393 | ||
394 | switch(cmd) { | |
395 | case MTIOCPOS32: | |
396 | kcmd = MTIOCPOS; | |
a7f61e89 JH |
397 | pos = compat_alloc_user_space(sizeof(*pos)); |
398 | karg = pos; | |
1da177e4 | 399 | break; |
45bf5cd7 | 400 | default: /* MTIOCGET32 */ |
1da177e4 | 401 | kcmd = MTIOCGET; |
a7f61e89 JH |
402 | get = compat_alloc_user_space(sizeof(*get)); |
403 | karg = get; | |
1da177e4 | 404 | break; |
1da177e4 | 405 | } |
a7f61e89 JH |
406 | if (karg == NULL) |
407 | return -EFAULT; | |
66cf191f | 408 | err = do_ioctl(file, kcmd, (unsigned long)karg); |
1da177e4 LT |
409 | if (err) |
410 | return err; | |
411 | switch (cmd) { | |
412 | case MTIOCPOS32: | |
43c6e7b9 | 413 | upos32 = argp; |
a7f61e89 | 414 | err = convert_in_user(&pos->mt_blkno, &upos32->mt_blkno); |
1da177e4 LT |
415 | break; |
416 | case MTIOCGET32: | |
43c6e7b9 | 417 | umget32 = argp; |
a7f61e89 JH |
418 | err = convert_in_user(&get->mt_type, &umget32->mt_type); |
419 | err |= convert_in_user(&get->mt_resid, &umget32->mt_resid); | |
420 | err |= convert_in_user(&get->mt_dsreg, &umget32->mt_dsreg); | |
421 | err |= convert_in_user(&get->mt_gstat, &umget32->mt_gstat); | |
422 | err |= convert_in_user(&get->mt_erreg, &umget32->mt_erreg); | |
423 | err |= convert_in_user(&get->mt_fileno, &umget32->mt_fileno); | |
424 | err |= convert_in_user(&get->mt_blkno, &umget32->mt_blkno); | |
1da177e4 LT |
425 | break; |
426 | } | |
427 | return err ? -EFAULT: 0; | |
428 | } | |
429 | ||
9361401e | 430 | #endif /* CONFIG_BLOCK */ |
1da177e4 | 431 | |
1da177e4 | 432 | /* Bluetooth ioctls */ |
2cdf096f JH |
433 | #define HCIUARTSETPROTO _IOW('U', 200, int) |
434 | #define HCIUARTGETPROTO _IOR('U', 201, int) | |
435 | #define HCIUARTGETDEVICE _IOR('U', 202, int) | |
63c7d09c JH |
436 | #define HCIUARTSETFLAGS _IOW('U', 203, int) |
437 | #define HCIUARTGETFLAGS _IOR('U', 204, int) | |
1da177e4 | 438 | |
ec3cad96 CH |
439 | #define RTC_IRQP_READ32 _IOR('p', 0x0b, compat_ulong_t) |
440 | #define RTC_IRQP_SET32 _IOW('p', 0x0c, compat_ulong_t) | |
441 | #define RTC_EPOCH_READ32 _IOR('p', 0x0d, compat_ulong_t) | |
442 | #define RTC_EPOCH_SET32 _IOW('p', 0x0e, compat_ulong_t) | |
443 | ||
66cf191f | 444 | static int rtc_ioctl(struct file *file, |
b4341721 | 445 | unsigned cmd, void __user *argp) |
ec3cad96 | 446 | { |
a7f61e89 | 447 | unsigned long __user *valp = compat_alloc_user_space(sizeof(*valp)); |
ec3cad96 CH |
448 | int ret; |
449 | ||
a7f61e89 JH |
450 | if (valp == NULL) |
451 | return -EFAULT; | |
ec3cad96 CH |
452 | switch (cmd) { |
453 | case RTC_IRQP_READ32: | |
454 | case RTC_EPOCH_READ32: | |
66cf191f | 455 | ret = do_ioctl(file, (cmd == RTC_IRQP_READ32) ? |
ec3cad96 | 456 | RTC_IRQP_READ : RTC_EPOCH_READ, |
a7f61e89 | 457 | (unsigned long)valp); |
ec3cad96 CH |
458 | if (ret) |
459 | return ret; | |
a7f61e89 | 460 | return convert_in_user(valp, (unsigned int __user *)argp); |
ec3cad96 | 461 | case RTC_IRQP_SET32: |
66cf191f | 462 | return do_ioctl(file, RTC_IRQP_SET, (unsigned long)argp); |
ec3cad96 | 463 | case RTC_EPOCH_SET32: |
66cf191f | 464 | return do_ioctl(file, RTC_EPOCH_SET, (unsigned long)argp); |
ec3cad96 | 465 | } |
43c6e7b9 AB |
466 | |
467 | return -ENOIOCTLCMD; | |
ec3cad96 CH |
468 | } |
469 | ||
3e63cbb1 AJ |
470 | /* on ia32 l_start is on a 32-bit boundary */ |
471 | #if defined(CONFIG_IA64) || defined(CONFIG_X86_64) | |
472 | struct space_resv_32 { | |
473 | __s16 l_type; | |
474 | __s16 l_whence; | |
475 | __s64 l_start __attribute__((packed)); | |
476 | /* len == 0 means until end of file */ | |
477 | __s64 l_len __attribute__((packed)); | |
478 | __s32 l_sysid; | |
479 | __u32 l_pid; | |
480 | __s32 l_pad[4]; /* reserve area */ | |
481 | }; | |
482 | ||
483 | #define FS_IOC_RESVSP_32 _IOW ('X', 40, struct space_resv_32) | |
484 | #define FS_IOC_RESVSP64_32 _IOW ('X', 42, struct space_resv_32) | |
485 | ||
486 | /* just account for different alignment */ | |
43c6e7b9 AB |
487 | static int compat_ioctl_preallocate(struct file *file, |
488 | struct space_resv_32 __user *p32) | |
3e63cbb1 | 489 | { |
3e63cbb1 AJ |
490 | struct space_resv __user *p = compat_alloc_user_space(sizeof(*p)); |
491 | ||
492 | if (copy_in_user(&p->l_type, &p32->l_type, sizeof(s16)) || | |
493 | copy_in_user(&p->l_whence, &p32->l_whence, sizeof(s16)) || | |
494 | copy_in_user(&p->l_start, &p32->l_start, sizeof(s64)) || | |
495 | copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) || | |
496 | copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) || | |
497 | copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) || | |
498 | copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32))) | |
499 | return -EFAULT; | |
500 | ||
501 | return ioctl_preallocate(file, p); | |
502 | } | |
503 | #endif | |
504 | ||
661f627d AB |
505 | /* |
506 | * simple reversible transform to make our table more evenly | |
507 | * distributed after sorting. | |
508 | */ | |
509 | #define XFORM(i) (((i) ^ ((i) << 27) ^ ((i) << 17)) & 0xffffffff) | |
6272e266 | 510 | |
9280cdd6 | 511 | #define COMPATIBLE_IOCTL(cmd) XFORM((u32)cmd), |
421f0281 AK |
512 | /* ioctl should not be warned about even if it's not implemented. |
513 | Valid reasons to use this: | |
514 | - It is implemented with ->compat_ioctl on some device, but programs | |
515 | call it on others too. | |
516 | - The ioctl is not implemented in the native kernel, but programs | |
517 | call it commonly anyways. | |
518 | Most other reasons are not valid. */ | |
519 | #define IGNORE_IOCTL(cmd) COMPATIBLE_IOCTL(cmd) | |
e6a6d2ef | 520 | |
661f627d | 521 | static unsigned int ioctl_pointer[] = { |
644fd4f5 | 522 | /* compatible ioctls first */ |
644fd4f5 | 523 | /* Little t */ |
644fd4f5 | 524 | COMPATIBLE_IOCTL(TIOCOUTQ) |
644fd4f5 CH |
525 | /* Little f */ |
526 | COMPATIBLE_IOCTL(FIOCLEX) | |
527 | COMPATIBLE_IOCTL(FIONCLEX) | |
528 | COMPATIBLE_IOCTL(FIOASYNC) | |
529 | COMPATIBLE_IOCTL(FIONBIO) | |
530 | COMPATIBLE_IOCTL(FIONREAD) /* This is also TIOCINQ */ | |
69130c7c | 531 | COMPATIBLE_IOCTL(FS_IOC_FIEMAP) |
644fd4f5 CH |
532 | /* 0x00 */ |
533 | COMPATIBLE_IOCTL(FIBMAP) | |
534 | COMPATIBLE_IOCTL(FIGETBSZ) | |
5cf8cf41 CH |
535 | /* 'X' - originally XFS but some now in the VFS */ |
536 | COMPATIBLE_IOCTL(FIFREEZE) | |
537 | COMPATIBLE_IOCTL(FITHAW) | |
9abea2d6 | 538 | COMPATIBLE_IOCTL(FITRIM) |
3c3622dc | 539 | #ifdef CONFIG_BLOCK |
644fd4f5 CH |
540 | /* Big S */ |
541 | COMPATIBLE_IOCTL(SCSI_IOCTL_GET_IDLUN) | |
542 | COMPATIBLE_IOCTL(SCSI_IOCTL_DOORLOCK) | |
543 | COMPATIBLE_IOCTL(SCSI_IOCTL_DOORUNLOCK) | |
544 | COMPATIBLE_IOCTL(SCSI_IOCTL_TEST_UNIT_READY) | |
545 | COMPATIBLE_IOCTL(SCSI_IOCTL_GET_BUS_NUMBER) | |
546 | COMPATIBLE_IOCTL(SCSI_IOCTL_SEND_COMMAND) | |
547 | COMPATIBLE_IOCTL(SCSI_IOCTL_PROBE_HOST) | |
548 | COMPATIBLE_IOCTL(SCSI_IOCTL_GET_PCI) | |
3c3622dc | 549 | #endif |
3f001711 AN |
550 | /* Big V (don't complain on serial console) */ |
551 | IGNORE_IOCTL(VT_OPENQRY) | |
552 | IGNORE_IOCTL(VT_GETMODE) | |
644fd4f5 CH |
553 | /* Little p (/dev/rtc, /dev/envctrl, etc.) */ |
554 | COMPATIBLE_IOCTL(RTC_AIE_ON) | |
555 | COMPATIBLE_IOCTL(RTC_AIE_OFF) | |
556 | COMPATIBLE_IOCTL(RTC_UIE_ON) | |
557 | COMPATIBLE_IOCTL(RTC_UIE_OFF) | |
558 | COMPATIBLE_IOCTL(RTC_PIE_ON) | |
559 | COMPATIBLE_IOCTL(RTC_PIE_OFF) | |
560 | COMPATIBLE_IOCTL(RTC_WIE_ON) | |
561 | COMPATIBLE_IOCTL(RTC_WIE_OFF) | |
562 | COMPATIBLE_IOCTL(RTC_ALM_SET) | |
563 | COMPATIBLE_IOCTL(RTC_ALM_READ) | |
564 | COMPATIBLE_IOCTL(RTC_RD_TIME) | |
565 | COMPATIBLE_IOCTL(RTC_SET_TIME) | |
566 | COMPATIBLE_IOCTL(RTC_WKALM_SET) | |
567 | COMPATIBLE_IOCTL(RTC_WKALM_RD) | |
568 | /* | |
569 | * These two are only for the sbus rtc driver, but | |
570 | * hwclock tries them on every rtc device first when | |
571 | * running on sparc. On other architectures the entries | |
572 | * are useless but harmless. | |
573 | */ | |
574 | COMPATIBLE_IOCTL(_IOR('p', 20, int[7])) /* RTCGET */ | |
575 | COMPATIBLE_IOCTL(_IOW('p', 21, int[7])) /* RTCSET */ | |
576 | /* Little m */ | |
577 | COMPATIBLE_IOCTL(MTIOCTOP) | |
578 | /* Socket level stuff */ | |
579 | COMPATIBLE_IOCTL(FIOQSIZE) | |
3c3622dc | 580 | #ifdef CONFIG_BLOCK |
f79f1185 AB |
581 | /* md calls this on random blockdevs */ |
582 | IGNORE_IOCTL(RAID_VERSION) | |
390192b3 JS |
583 | /* qemu/qemu-img might call these two on plain files for probing */ |
584 | IGNORE_IOCTL(CDROM_DRIVE_STATUS) | |
585 | IGNORE_IOCTL(FDGETPRM32) | |
644fd4f5 CH |
586 | /* SG stuff */ |
587 | COMPATIBLE_IOCTL(SG_SET_TIMEOUT) | |
588 | COMPATIBLE_IOCTL(SG_GET_TIMEOUT) | |
589 | COMPATIBLE_IOCTL(SG_EMULATED_HOST) | |
644fd4f5 CH |
590 | COMPATIBLE_IOCTL(SG_GET_TRANSFORM) |
591 | COMPATIBLE_IOCTL(SG_SET_RESERVED_SIZE) | |
592 | COMPATIBLE_IOCTL(SG_GET_RESERVED_SIZE) | |
593 | COMPATIBLE_IOCTL(SG_GET_SCSI_ID) | |
594 | COMPATIBLE_IOCTL(SG_SET_FORCE_LOW_DMA) | |
595 | COMPATIBLE_IOCTL(SG_GET_LOW_DMA) | |
596 | COMPATIBLE_IOCTL(SG_SET_FORCE_PACK_ID) | |
597 | COMPATIBLE_IOCTL(SG_GET_PACK_ID) | |
598 | COMPATIBLE_IOCTL(SG_GET_NUM_WAITING) | |
599 | COMPATIBLE_IOCTL(SG_SET_DEBUG) | |
600 | COMPATIBLE_IOCTL(SG_GET_SG_TABLESIZE) | |
601 | COMPATIBLE_IOCTL(SG_GET_COMMAND_Q) | |
602 | COMPATIBLE_IOCTL(SG_SET_COMMAND_Q) | |
603 | COMPATIBLE_IOCTL(SG_GET_VERSION_NUM) | |
604 | COMPATIBLE_IOCTL(SG_NEXT_CMD_LEN) | |
605 | COMPATIBLE_IOCTL(SG_SCSI_RESET) | |
606 | COMPATIBLE_IOCTL(SG_GET_REQUEST_TABLE) | |
607 | COMPATIBLE_IOCTL(SG_SET_KEEP_ORPHAN) | |
608 | COMPATIBLE_IOCTL(SG_GET_KEEP_ORPHAN) | |
3c3622dc | 609 | #endif |
644fd4f5 CH |
610 | /* PPP stuff */ |
611 | COMPATIBLE_IOCTL(PPPIOCGFLAGS) | |
612 | COMPATIBLE_IOCTL(PPPIOCSFLAGS) | |
613 | COMPATIBLE_IOCTL(PPPIOCGASYNCMAP) | |
614 | COMPATIBLE_IOCTL(PPPIOCSASYNCMAP) | |
615 | COMPATIBLE_IOCTL(PPPIOCGUNIT) | |
616 | COMPATIBLE_IOCTL(PPPIOCGRASYNCMAP) | |
617 | COMPATIBLE_IOCTL(PPPIOCSRASYNCMAP) | |
618 | COMPATIBLE_IOCTL(PPPIOCGMRU) | |
619 | COMPATIBLE_IOCTL(PPPIOCSMRU) | |
620 | COMPATIBLE_IOCTL(PPPIOCSMAXCID) | |
621 | COMPATIBLE_IOCTL(PPPIOCGXASYNCMAP) | |
622 | COMPATIBLE_IOCTL(PPPIOCSXASYNCMAP) | |
623 | COMPATIBLE_IOCTL(PPPIOCXFERUNIT) | |
624 | /* PPPIOCSCOMPRESS is translated */ | |
625 | COMPATIBLE_IOCTL(PPPIOCGNPMODE) | |
626 | COMPATIBLE_IOCTL(PPPIOCSNPMODE) | |
627 | COMPATIBLE_IOCTL(PPPIOCGDEBUG) | |
628 | COMPATIBLE_IOCTL(PPPIOCSDEBUG) | |
629 | /* PPPIOCSPASS is translated */ | |
630 | /* PPPIOCSACTIVE is translated */ | |
631 | /* PPPIOCGIDLE is translated */ | |
632 | COMPATIBLE_IOCTL(PPPIOCNEWUNIT) | |
633 | COMPATIBLE_IOCTL(PPPIOCATTACH) | |
634 | COMPATIBLE_IOCTL(PPPIOCDETACH) | |
635 | COMPATIBLE_IOCTL(PPPIOCSMRRU) | |
636 | COMPATIBLE_IOCTL(PPPIOCCONNECT) | |
637 | COMPATIBLE_IOCTL(PPPIOCDISCONN) | |
638 | COMPATIBLE_IOCTL(PPPIOCATTCHAN) | |
639 | COMPATIBLE_IOCTL(PPPIOCGCHAN) | |
8bab6f14 | 640 | COMPATIBLE_IOCTL(PPPIOCGL2TPSTATS) |
644fd4f5 CH |
641 | /* PPPOX */ |
642 | COMPATIBLE_IOCTL(PPPOEIOCSFWD) | |
643 | COMPATIBLE_IOCTL(PPPOEIOCDFWD) | |
644fd4f5 CH |
644 | /* Big A */ |
645 | /* sparc only */ | |
646 | /* Big Q for sound/OSS */ | |
647 | COMPATIBLE_IOCTL(SNDCTL_SEQ_RESET) | |
648 | COMPATIBLE_IOCTL(SNDCTL_SEQ_SYNC) | |
649 | COMPATIBLE_IOCTL(SNDCTL_SYNTH_INFO) | |
650 | COMPATIBLE_IOCTL(SNDCTL_SEQ_CTRLRATE) | |
651 | COMPATIBLE_IOCTL(SNDCTL_SEQ_GETOUTCOUNT) | |
652 | COMPATIBLE_IOCTL(SNDCTL_SEQ_GETINCOUNT) | |
653 | COMPATIBLE_IOCTL(SNDCTL_SEQ_PERCMODE) | |
654 | COMPATIBLE_IOCTL(SNDCTL_FM_LOAD_INSTR) | |
655 | COMPATIBLE_IOCTL(SNDCTL_SEQ_TESTMIDI) | |
656 | COMPATIBLE_IOCTL(SNDCTL_SEQ_RESETSAMPLES) | |
657 | COMPATIBLE_IOCTL(SNDCTL_SEQ_NRSYNTHS) | |
658 | COMPATIBLE_IOCTL(SNDCTL_SEQ_NRMIDIS) | |
659 | COMPATIBLE_IOCTL(SNDCTL_MIDI_INFO) | |
660 | COMPATIBLE_IOCTL(SNDCTL_SEQ_THRESHOLD) | |
661 | COMPATIBLE_IOCTL(SNDCTL_SYNTH_MEMAVL) | |
662 | COMPATIBLE_IOCTL(SNDCTL_FM_4OP_ENABLE) | |
663 | COMPATIBLE_IOCTL(SNDCTL_SEQ_PANIC) | |
664 | COMPATIBLE_IOCTL(SNDCTL_SEQ_OUTOFBAND) | |
665 | COMPATIBLE_IOCTL(SNDCTL_SEQ_GETTIME) | |
666 | COMPATIBLE_IOCTL(SNDCTL_SYNTH_ID) | |
667 | COMPATIBLE_IOCTL(SNDCTL_SYNTH_CONTROL) | |
668 | COMPATIBLE_IOCTL(SNDCTL_SYNTH_REMOVESAMPLE) | |
669 | /* Big T for sound/OSS */ | |
670 | COMPATIBLE_IOCTL(SNDCTL_TMR_TIMEBASE) | |
671 | COMPATIBLE_IOCTL(SNDCTL_TMR_START) | |
672 | COMPATIBLE_IOCTL(SNDCTL_TMR_STOP) | |
673 | COMPATIBLE_IOCTL(SNDCTL_TMR_CONTINUE) | |
674 | COMPATIBLE_IOCTL(SNDCTL_TMR_TEMPO) | |
675 | COMPATIBLE_IOCTL(SNDCTL_TMR_SOURCE) | |
676 | COMPATIBLE_IOCTL(SNDCTL_TMR_METRONOME) | |
677 | COMPATIBLE_IOCTL(SNDCTL_TMR_SELECT) | |
678 | /* Little m for sound/OSS */ | |
679 | COMPATIBLE_IOCTL(SNDCTL_MIDI_PRETIME) | |
680 | COMPATIBLE_IOCTL(SNDCTL_MIDI_MPUMODE) | |
681 | COMPATIBLE_IOCTL(SNDCTL_MIDI_MPUCMD) | |
682 | /* Big P for sound/OSS */ | |
683 | COMPATIBLE_IOCTL(SNDCTL_DSP_RESET) | |
684 | COMPATIBLE_IOCTL(SNDCTL_DSP_SYNC) | |
685 | COMPATIBLE_IOCTL(SNDCTL_DSP_SPEED) | |
686 | COMPATIBLE_IOCTL(SNDCTL_DSP_STEREO) | |
687 | COMPATIBLE_IOCTL(SNDCTL_DSP_GETBLKSIZE) | |
688 | COMPATIBLE_IOCTL(SNDCTL_DSP_CHANNELS) | |
689 | COMPATIBLE_IOCTL(SOUND_PCM_WRITE_FILTER) | |
690 | COMPATIBLE_IOCTL(SNDCTL_DSP_POST) | |
691 | COMPATIBLE_IOCTL(SNDCTL_DSP_SUBDIVIDE) | |
692 | COMPATIBLE_IOCTL(SNDCTL_DSP_SETFRAGMENT) | |
693 | COMPATIBLE_IOCTL(SNDCTL_DSP_GETFMTS) | |
694 | COMPATIBLE_IOCTL(SNDCTL_DSP_SETFMT) | |
695 | COMPATIBLE_IOCTL(SNDCTL_DSP_GETOSPACE) | |
696 | COMPATIBLE_IOCTL(SNDCTL_DSP_GETISPACE) | |
697 | COMPATIBLE_IOCTL(SNDCTL_DSP_NONBLOCK) | |
698 | COMPATIBLE_IOCTL(SNDCTL_DSP_GETCAPS) | |
699 | COMPATIBLE_IOCTL(SNDCTL_DSP_GETTRIGGER) | |
700 | COMPATIBLE_IOCTL(SNDCTL_DSP_SETTRIGGER) | |
701 | COMPATIBLE_IOCTL(SNDCTL_DSP_GETIPTR) | |
702 | COMPATIBLE_IOCTL(SNDCTL_DSP_GETOPTR) | |
703 | /* SNDCTL_DSP_MAPINBUF, XXX needs translation */ | |
704 | /* SNDCTL_DSP_MAPOUTBUF, XXX needs translation */ | |
705 | COMPATIBLE_IOCTL(SNDCTL_DSP_SETSYNCRO) | |
706 | COMPATIBLE_IOCTL(SNDCTL_DSP_SETDUPLEX) | |
707 | COMPATIBLE_IOCTL(SNDCTL_DSP_GETODELAY) | |
708 | COMPATIBLE_IOCTL(SNDCTL_DSP_PROFILE) | |
709 | COMPATIBLE_IOCTL(SOUND_PCM_READ_RATE) | |
710 | COMPATIBLE_IOCTL(SOUND_PCM_READ_CHANNELS) | |
711 | COMPATIBLE_IOCTL(SOUND_PCM_READ_BITS) | |
712 | COMPATIBLE_IOCTL(SOUND_PCM_READ_FILTER) | |
713 | /* Big C for sound/OSS */ | |
714 | COMPATIBLE_IOCTL(SNDCTL_COPR_RESET) | |
715 | COMPATIBLE_IOCTL(SNDCTL_COPR_LOAD) | |
716 | COMPATIBLE_IOCTL(SNDCTL_COPR_RDATA) | |
717 | COMPATIBLE_IOCTL(SNDCTL_COPR_RCODE) | |
718 | COMPATIBLE_IOCTL(SNDCTL_COPR_WDATA) | |
719 | COMPATIBLE_IOCTL(SNDCTL_COPR_WCODE) | |
720 | COMPATIBLE_IOCTL(SNDCTL_COPR_RUN) | |
721 | COMPATIBLE_IOCTL(SNDCTL_COPR_HALT) | |
722 | COMPATIBLE_IOCTL(SNDCTL_COPR_SENDMSG) | |
723 | COMPATIBLE_IOCTL(SNDCTL_COPR_RCVMSG) | |
724 | /* Big M for sound/OSS */ | |
725 | COMPATIBLE_IOCTL(SOUND_MIXER_READ_VOLUME) | |
726 | COMPATIBLE_IOCTL(SOUND_MIXER_READ_BASS) | |
727 | COMPATIBLE_IOCTL(SOUND_MIXER_READ_TREBLE) | |
728 | COMPATIBLE_IOCTL(SOUND_MIXER_READ_SYNTH) | |
729 | COMPATIBLE_IOCTL(SOUND_MIXER_READ_PCM) | |
730 | COMPATIBLE_IOCTL(SOUND_MIXER_READ_SPEAKER) | |
731 | COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE) | |
732 | COMPATIBLE_IOCTL(SOUND_MIXER_READ_MIC) | |
733 | COMPATIBLE_IOCTL(SOUND_MIXER_READ_CD) | |
734 | COMPATIBLE_IOCTL(SOUND_MIXER_READ_IMIX) | |
735 | COMPATIBLE_IOCTL(SOUND_MIXER_READ_ALTPCM) | |
736 | COMPATIBLE_IOCTL(SOUND_MIXER_READ_RECLEV) | |
737 | COMPATIBLE_IOCTL(SOUND_MIXER_READ_IGAIN) | |
738 | COMPATIBLE_IOCTL(SOUND_MIXER_READ_OGAIN) | |
739 | COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE1) | |
740 | COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE2) | |
741 | COMPATIBLE_IOCTL(SOUND_MIXER_READ_LINE3) | |
742 | COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_DIGITAL1)) | |
743 | COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_DIGITAL2)) | |
744 | COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_DIGITAL3)) | |
745 | COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_PHONEIN)) | |
746 | COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_PHONEOUT)) | |
747 | COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_VIDEO)) | |
748 | COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_RADIO)) | |
749 | COMPATIBLE_IOCTL(MIXER_READ(SOUND_MIXER_MONITOR)) | |
750 | COMPATIBLE_IOCTL(SOUND_MIXER_READ_MUTE) | |
751 | /* SOUND_MIXER_READ_ENHANCE, same value as READ_MUTE */ | |
752 | /* SOUND_MIXER_READ_LOUD, same value as READ_MUTE */ | |
753 | COMPATIBLE_IOCTL(SOUND_MIXER_READ_RECSRC) | |
754 | COMPATIBLE_IOCTL(SOUND_MIXER_READ_DEVMASK) | |
755 | COMPATIBLE_IOCTL(SOUND_MIXER_READ_RECMASK) | |
756 | COMPATIBLE_IOCTL(SOUND_MIXER_READ_STEREODEVS) | |
757 | COMPATIBLE_IOCTL(SOUND_MIXER_READ_CAPS) | |
758 | COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_VOLUME) | |
759 | COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_BASS) | |
760 | COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_TREBLE) | |
761 | COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_SYNTH) | |
762 | COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_PCM) | |
763 | COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_SPEAKER) | |
764 | COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE) | |
765 | COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_MIC) | |
766 | COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_CD) | |
767 | COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_IMIX) | |
768 | COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_ALTPCM) | |
769 | COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_RECLEV) | |
770 | COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_IGAIN) | |
771 | COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_OGAIN) | |
772 | COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE1) | |
773 | COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE2) | |
774 | COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_LINE3) | |
775 | COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_DIGITAL1)) | |
776 | COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_DIGITAL2)) | |
777 | COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_DIGITAL3)) | |
778 | COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_PHONEIN)) | |
779 | COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_PHONEOUT)) | |
780 | COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_VIDEO)) | |
781 | COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_RADIO)) | |
782 | COMPATIBLE_IOCTL(MIXER_WRITE(SOUND_MIXER_MONITOR)) | |
783 | COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_MUTE) | |
784 | /* SOUND_MIXER_WRITE_ENHANCE, same value as WRITE_MUTE */ | |
785 | /* SOUND_MIXER_WRITE_LOUD, same value as WRITE_MUTE */ | |
786 | COMPATIBLE_IOCTL(SOUND_MIXER_WRITE_RECSRC) | |
787 | COMPATIBLE_IOCTL(SOUND_MIXER_INFO) | |
788 | COMPATIBLE_IOCTL(SOUND_OLD_MIXER_INFO) | |
789 | COMPATIBLE_IOCTL(SOUND_MIXER_ACCESS) | |
790 | COMPATIBLE_IOCTL(SOUND_MIXER_AGC) | |
791 | COMPATIBLE_IOCTL(SOUND_MIXER_3DSE) | |
792 | COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE1) | |
793 | COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE2) | |
794 | COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE3) | |
795 | COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE4) | |
796 | COMPATIBLE_IOCTL(SOUND_MIXER_PRIVATE5) | |
797 | COMPATIBLE_IOCTL(SOUND_MIXER_GETLEVELS) | |
798 | COMPATIBLE_IOCTL(SOUND_MIXER_SETLEVELS) | |
799 | COMPATIBLE_IOCTL(OSS_GETVERSION) | |
644fd4f5 CH |
800 | /* Raw devices */ |
801 | COMPATIBLE_IOCTL(RAW_SETBIND) | |
802 | COMPATIBLE_IOCTL(RAW_GETBIND) | |
644fd4f5 CH |
803 | /* Watchdog */ |
804 | COMPATIBLE_IOCTL(WDIOC_GETSUPPORT) | |
805 | COMPATIBLE_IOCTL(WDIOC_GETSTATUS) | |
806 | COMPATIBLE_IOCTL(WDIOC_GETBOOTSTATUS) | |
807 | COMPATIBLE_IOCTL(WDIOC_GETTEMP) | |
808 | COMPATIBLE_IOCTL(WDIOC_SETOPTIONS) | |
809 | COMPATIBLE_IOCTL(WDIOC_KEEPALIVE) | |
810 | COMPATIBLE_IOCTL(WDIOC_SETTIMEOUT) | |
811 | COMPATIBLE_IOCTL(WDIOC_GETTIMEOUT) | |
97beb3ae WS |
812 | COMPATIBLE_IOCTL(WDIOC_SETPRETIMEOUT) |
813 | COMPATIBLE_IOCTL(WDIOC_GETPRETIMEOUT) | |
644fd4f5 CH |
814 | /* Big R */ |
815 | COMPATIBLE_IOCTL(RNDGETENTCNT) | |
816 | COMPATIBLE_IOCTL(RNDADDTOENTCNT) | |
817 | COMPATIBLE_IOCTL(RNDGETPOOL) | |
818 | COMPATIBLE_IOCTL(RNDADDENTROPY) | |
819 | COMPATIBLE_IOCTL(RNDZAPENTCNT) | |
820 | COMPATIBLE_IOCTL(RNDCLEARPOOL) | |
821 | /* Bluetooth */ | |
822 | COMPATIBLE_IOCTL(HCIDEVUP) | |
823 | COMPATIBLE_IOCTL(HCIDEVDOWN) | |
824 | COMPATIBLE_IOCTL(HCIDEVRESET) | |
825 | COMPATIBLE_IOCTL(HCIDEVRESTAT) | |
826 | COMPATIBLE_IOCTL(HCIGETDEVLIST) | |
827 | COMPATIBLE_IOCTL(HCIGETDEVINFO) | |
828 | COMPATIBLE_IOCTL(HCIGETCONNLIST) | |
829 | COMPATIBLE_IOCTL(HCIGETCONNINFO) | |
40be492f | 830 | COMPATIBLE_IOCTL(HCIGETAUTHINFO) |
644fd4f5 CH |
831 | COMPATIBLE_IOCTL(HCISETRAW) |
832 | COMPATIBLE_IOCTL(HCISETSCAN) | |
833 | COMPATIBLE_IOCTL(HCISETAUTH) | |
834 | COMPATIBLE_IOCTL(HCISETENCRYPT) | |
835 | COMPATIBLE_IOCTL(HCISETPTYPE) | |
836 | COMPATIBLE_IOCTL(HCISETLINKPOL) | |
837 | COMPATIBLE_IOCTL(HCISETLINKMODE) | |
838 | COMPATIBLE_IOCTL(HCISETACLMTU) | |
839 | COMPATIBLE_IOCTL(HCISETSCOMTU) | |
f0358568 JH |
840 | COMPATIBLE_IOCTL(HCIBLOCKADDR) |
841 | COMPATIBLE_IOCTL(HCIUNBLOCKADDR) | |
644fd4f5 CH |
842 | COMPATIBLE_IOCTL(HCIINQUIRY) |
843 | COMPATIBLE_IOCTL(HCIUARTSETPROTO) | |
844 | COMPATIBLE_IOCTL(HCIUARTGETPROTO) | |
d10d34aa MH |
845 | COMPATIBLE_IOCTL(HCIUARTGETDEVICE) |
846 | COMPATIBLE_IOCTL(HCIUARTSETFLAGS) | |
847 | COMPATIBLE_IOCTL(HCIUARTGETFLAGS) | |
644fd4f5 CH |
848 | COMPATIBLE_IOCTL(RFCOMMCREATEDEV) |
849 | COMPATIBLE_IOCTL(RFCOMMRELEASEDEV) | |
850 | COMPATIBLE_IOCTL(RFCOMMGETDEVLIST) | |
851 | COMPATIBLE_IOCTL(RFCOMMGETDEVINFO) | |
852 | COMPATIBLE_IOCTL(RFCOMMSTEALDLC) | |
644fd4f5 CH |
853 | /* CAPI */ |
854 | COMPATIBLE_IOCTL(CAPI_REGISTER) | |
855 | COMPATIBLE_IOCTL(CAPI_GET_MANUFACTURER) | |
856 | COMPATIBLE_IOCTL(CAPI_GET_VERSION) | |
857 | COMPATIBLE_IOCTL(CAPI_GET_SERIAL) | |
858 | COMPATIBLE_IOCTL(CAPI_GET_PROFILE) | |
859 | COMPATIBLE_IOCTL(CAPI_MANUFACTURER_CMD) | |
860 | COMPATIBLE_IOCTL(CAPI_GET_ERRCODE) | |
861 | COMPATIBLE_IOCTL(CAPI_INSTALLED) | |
862 | COMPATIBLE_IOCTL(CAPI_GET_FLAGS) | |
863 | COMPATIBLE_IOCTL(CAPI_SET_FLAGS) | |
864 | COMPATIBLE_IOCTL(CAPI_CLR_FLAGS) | |
865 | COMPATIBLE_IOCTL(CAPI_NCCI_OPENCOUNT) | |
866 | COMPATIBLE_IOCTL(CAPI_NCCI_GETUNIT) | |
644fd4f5 CH |
867 | /* Misc. */ |
868 | COMPATIBLE_IOCTL(0x41545900) /* ATYIO_CLKR */ | |
869 | COMPATIBLE_IOCTL(0x41545901) /* ATYIO_CLKW */ | |
870 | COMPATIBLE_IOCTL(PCIIOC_CONTROLLER) | |
871 | COMPATIBLE_IOCTL(PCIIOC_MMAP_IS_IO) | |
872 | COMPATIBLE_IOCTL(PCIIOC_MMAP_IS_MEM) | |
873 | COMPATIBLE_IOCTL(PCIIOC_WRITE_COMBINE) | |
644fd4f5 CH |
874 | /* hiddev */ |
875 | COMPATIBLE_IOCTL(HIDIOCGVERSION) | |
876 | COMPATIBLE_IOCTL(HIDIOCAPPLICATION) | |
877 | COMPATIBLE_IOCTL(HIDIOCGDEVINFO) | |
878 | COMPATIBLE_IOCTL(HIDIOCGSTRING) | |
879 | COMPATIBLE_IOCTL(HIDIOCINITREPORT) | |
880 | COMPATIBLE_IOCTL(HIDIOCGREPORT) | |
881 | COMPATIBLE_IOCTL(HIDIOCSREPORT) | |
882 | COMPATIBLE_IOCTL(HIDIOCGREPORTINFO) | |
883 | COMPATIBLE_IOCTL(HIDIOCGFIELDINFO) | |
884 | COMPATIBLE_IOCTL(HIDIOCGUSAGE) | |
885 | COMPATIBLE_IOCTL(HIDIOCSUSAGE) | |
886 | COMPATIBLE_IOCTL(HIDIOCGUCODE) | |
887 | COMPATIBLE_IOCTL(HIDIOCGFLAG) | |
888 | COMPATIBLE_IOCTL(HIDIOCSFLAG) | |
889 | COMPATIBLE_IOCTL(HIDIOCGCOLLECTIONINDEX) | |
890 | COMPATIBLE_IOCTL(HIDIOCGCOLLECTIONINFO) | |
3fee37c1 AM |
891 | /* joystick */ |
892 | COMPATIBLE_IOCTL(JSIOCGVERSION) | |
893 | COMPATIBLE_IOCTL(JSIOCGAXES) | |
894 | COMPATIBLE_IOCTL(JSIOCGBUTTONS) | |
895 | COMPATIBLE_IOCTL(JSIOCGNAME(0)) | |
896 | ||
2724b6db AK |
897 | /* fat 'r' ioctls. These are handled by fat with ->compat_ioctl, |
898 | but we don't want warnings on other file systems. So declare | |
899 | them as compatible here. */ | |
900 | #define VFAT_IOCTL_READDIR_BOTH32 _IOR('r', 1, struct compat_dirent[2]) | |
901 | #define VFAT_IOCTL_READDIR_SHORT32 _IOR('r', 2, struct compat_dirent[2]) | |
902 | ||
903 | IGNORE_IOCTL(VFAT_IOCTL_READDIR_BOTH32) | |
904 | IGNORE_IOCTL(VFAT_IOCTL_READDIR_SHORT32) | |
98701dc1 | 905 | |
8163904e DM |
906 | #ifdef CONFIG_SPARC |
907 | /* Sparc framebuffers, handled in sbusfb_compat_ioctl() */ | |
908 | IGNORE_IOCTL(FBIOGTYPE) | |
909 | IGNORE_IOCTL(FBIOSATTR) | |
910 | IGNORE_IOCTL(FBIOGATTR) | |
911 | IGNORE_IOCTL(FBIOSVIDEO) | |
912 | IGNORE_IOCTL(FBIOGVIDEO) | |
913 | IGNORE_IOCTL(FBIOSCURPOS) | |
914 | IGNORE_IOCTL(FBIOGCURPOS) | |
915 | IGNORE_IOCTL(FBIOGCURMAX) | |
916 | IGNORE_IOCTL(FBIOPUTCMAP32) | |
917 | IGNORE_IOCTL(FBIOGETCMAP32) | |
918 | IGNORE_IOCTL(FBIOSCURSOR32) | |
919 | IGNORE_IOCTL(FBIOGCURSOR32) | |
920 | #endif | |
e6a6d2ef | 921 | }; |
6e87abd0 | 922 | |
5a07ea0b AB |
923 | /* |
924 | * Convert common ioctl arguments based on their command number | |
925 | * | |
926 | * Please do not add any code in here. Instead, implement | |
927 | * a compat_ioctl operation in the place that handleѕ the | |
928 | * ioctl for the native case. | |
929 | */ | |
66cf191f | 930 | static long do_ioctl_trans(unsigned int cmd, |
5a07ea0b AB |
931 | unsigned long arg, struct file *file) |
932 | { | |
43c6e7b9 AB |
933 | void __user *argp = compat_ptr(arg); |
934 | ||
5a07ea0b AB |
935 | switch (cmd) { |
936 | case PPPIOCGIDLE32: | |
66cf191f | 937 | return ppp_gidle(file, cmd, argp); |
5a07ea0b | 938 | case PPPIOCSCOMPRESS32: |
66cf191f | 939 | return ppp_scompress(file, cmd, argp); |
5a07ea0b AB |
940 | case PPPIOCSPASS32: |
941 | case PPPIOCSACTIVE32: | |
66cf191f | 942 | return ppp_sock_fprog_ioctl_trans(file, cmd, argp); |
5a07ea0b AB |
943 | #ifdef CONFIG_BLOCK |
944 | case SG_IO: | |
66cf191f | 945 | return sg_ioctl_trans(file, cmd, argp); |
5a07ea0b | 946 | case SG_GET_REQUEST_TABLE: |
66cf191f | 947 | return sg_grt_trans(file, cmd, argp); |
5a07ea0b AB |
948 | case MTIOCGET32: |
949 | case MTIOCPOS32: | |
66cf191f | 950 | return mt_ioctl_trans(file, cmd, argp); |
5a07ea0b | 951 | #endif |
5a07ea0b AB |
952 | /* Not implemented in the native kernel */ |
953 | case RTC_IRQP_READ32: | |
954 | case RTC_IRQP_SET32: | |
955 | case RTC_EPOCH_READ32: | |
956 | case RTC_EPOCH_SET32: | |
66cf191f | 957 | return rtc_ioctl(file, cmd, argp); |
5a07ea0b | 958 | } |
789f0f89 AB |
959 | |
960 | /* | |
961 | * These take an integer instead of a pointer as 'arg', | |
962 | * so we must not do a compat_ptr() translation. | |
963 | */ | |
964 | switch (cmd) { | |
789f0f89 AB |
965 | /* RAID */ |
966 | case HOT_REMOVE_DISK: | |
967 | case HOT_ADD_DISK: | |
968 | case SET_DISK_FAULTY: | |
969 | case SET_BITMAP_FILE: | |
66cf191f | 970 | return vfs_ioctl(file, cmd, arg); |
789f0f89 AB |
971 | } |
972 | ||
5a07ea0b AB |
973 | return -ENOIOCTLCMD; |
974 | } | |
975 | ||
661f627d AB |
976 | static int compat_ioctl_check_table(unsigned int xcmd) |
977 | { | |
978 | int i; | |
979 | const int max = ARRAY_SIZE(ioctl_pointer) - 1; | |
980 | ||
981 | BUILD_BUG_ON(max >= (1 << 16)); | |
982 | ||
983 | /* guess initial offset into table, assuming a | |
984 | normalized distribution */ | |
985 | i = ((xcmd >> 16) * max) >> 16; | |
986 | ||
987 | /* do linear search up first, until greater or equal */ | |
988 | while (ioctl_pointer[i] < xcmd && i < max) | |
989 | i++; | |
990 | ||
991 | /* then do linear search down */ | |
992 | while (ioctl_pointer[i] > xcmd && i > 0) | |
993 | i--; | |
994 | ||
995 | return ioctl_pointer[i] == xcmd; | |
996 | } | |
997 | ||
932602e2 HC |
998 | COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, |
999 | compat_ulong_t, arg32) | |
6272e266 | 1000 | { |
932602e2 | 1001 | unsigned long arg = arg32; |
2903ff01 | 1002 | struct fd f = fdget(fd); |
6272e266 | 1003 | int error = -EBADF; |
2903ff01 | 1004 | if (!f.file) |
6272e266 CH |
1005 | goto out; |
1006 | ||
1007 | /* RED-PEN how should LSM module know it's handling 32bit? */ | |
2903ff01 | 1008 | error = security_file_ioctl(f.file, cmd, arg); |
6272e266 CH |
1009 | if (error) |
1010 | goto out_fput; | |
1011 | ||
1012 | /* | |
1013 | * To allow the compat_ioctl handlers to be self contained | |
1014 | * we need to check the common ioctls here first. | |
1015 | * Just handle them with the standard handlers below. | |
1016 | */ | |
1017 | switch (cmd) { | |
1018 | case FIOCLEX: | |
1019 | case FIONCLEX: | |
1020 | case FIONBIO: | |
1021 | case FIOASYNC: | |
1022 | case FIOQSIZE: | |
1023 | break; | |
1024 | ||
3e63cbb1 AJ |
1025 | #if defined(CONFIG_IA64) || defined(CONFIG_X86_64) |
1026 | case FS_IOC_RESVSP_32: | |
1027 | case FS_IOC_RESVSP64_32: | |
2903ff01 | 1028 | error = compat_ioctl_preallocate(f.file, compat_ptr(arg)); |
3e63cbb1 AJ |
1029 | goto out_fput; |
1030 | #else | |
1031 | case FS_IOC_RESVSP: | |
1032 | case FS_IOC_RESVSP64: | |
2903ff01 | 1033 | error = ioctl_preallocate(f.file, compat_ptr(arg)); |
3e63cbb1 AJ |
1034 | goto out_fput; |
1035 | #endif | |
1036 | ||
d79bdd52 DW |
1037 | case FICLONE: |
1038 | case FICLONERANGE: | |
54dbc151 | 1039 | case FIDEDUPERANGE: |
ceac204e | 1040 | case FS_IOC_FIEMAP: |
d79bdd52 DW |
1041 | goto do_ioctl; |
1042 | ||
6272e266 CH |
1043 | case FIBMAP: |
1044 | case FIGETBSZ: | |
1045 | case FIONREAD: | |
496ad9aa | 1046 | if (S_ISREG(file_inode(f.file)->i_mode)) |
6272e266 CH |
1047 | break; |
1048 | /*FALL THROUGH*/ | |
1049 | ||
1050 | default: | |
72c2d531 | 1051 | if (f.file->f_op->compat_ioctl) { |
2903ff01 | 1052 | error = f.file->f_op->compat_ioctl(f.file, cmd, arg); |
6272e266 CH |
1053 | if (error != -ENOIOCTLCMD) |
1054 | goto out_fput; | |
1055 | } | |
1056 | ||
72c2d531 | 1057 | if (!f.file->f_op->unlocked_ioctl) |
6272e266 CH |
1058 | goto do_ioctl; |
1059 | break; | |
1060 | } | |
1061 | ||
661f627d AB |
1062 | if (compat_ioctl_check_table(XFORM(cmd))) |
1063 | goto found_handler; | |
6272e266 | 1064 | |
66cf191f | 1065 | error = do_ioctl_trans(cmd, arg, f.file); |
07d106d0 LT |
1066 | if (error == -ENOIOCTLCMD) |
1067 | error = -ENOTTY; | |
6272e266 CH |
1068 | |
1069 | goto out_fput; | |
1070 | ||
1071 | found_handler: | |
789f0f89 | 1072 | arg = (unsigned long)compat_ptr(arg); |
6272e266 | 1073 | do_ioctl: |
2903ff01 | 1074 | error = do_vfs_ioctl(f.file, fd, cmd, arg); |
6272e266 | 1075 | out_fput: |
2903ff01 | 1076 | fdput(f); |
6272e266 CH |
1077 | out: |
1078 | return error; | |
1079 | } | |
1080 | ||
661f627d | 1081 | static int __init init_sys32_ioctl_cmp(const void *p, const void *q) |
6272e266 | 1082 | { |
661f627d AB |
1083 | unsigned int a, b; |
1084 | a = *(unsigned int *)p; | |
1085 | b = *(unsigned int *)q; | |
1086 | if (a > b) | |
1087 | return 1; | |
1088 | if (a < b) | |
1089 | return -1; | |
1090 | return 0; | |
6272e266 CH |
1091 | } |
1092 | ||
1093 | static int __init init_sys32_ioctl(void) | |
1094 | { | |
661f627d AB |
1095 | sort(ioctl_pointer, ARRAY_SIZE(ioctl_pointer), sizeof(*ioctl_pointer), |
1096 | init_sys32_ioctl_cmp, NULL); | |
6272e266 CH |
1097 | return 0; |
1098 | } | |
1099 | __initcall(init_sys32_ioctl); |