compat_ioctl.c 36 KB

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