compat.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. /*
  2. * 32 bit compatibility code for System V IPC
  3. *
  4. * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  5. * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
  6. * Copyright (C) 1999 Arun Sharma <arun.sharma@intel.com>
  7. * Copyright (C) 2000 VA Linux Co
  8. * Copyright (C) 2000 Don Dugger <n0ano@valinux.com>
  9. * Copyright (C) 2000 Hewlett-Packard Co.
  10. * Copyright (C) 2000 David Mosberger-Tang <davidm@hpl.hp.com>
  11. * Copyright (C) 2000 Gerhard Tonn (ton@de.ibm.com)
  12. * Copyright (C) 2000-2002 Andi Kleen, SuSE Labs (x86-64 port)
  13. * Copyright (C) 2000 Silicon Graphics, Inc.
  14. * Copyright (C) 2001 IBM
  15. * Copyright (C) 2004 IBM Deutschland Entwicklung GmbH, IBM Corporation
  16. * Copyright (C) 2004 Arnd Bergmann (arnd@arndb.de)
  17. *
  18. * This code is collected from the versions for sparc64, mips64, s390x, ia64,
  19. * ppc64 and x86_64, all of which are based on the original sparc64 version
  20. * by Jakub Jelinek.
  21. *
  22. */
  23. #include <linux/compat.h>
  24. #include <linux/errno.h>
  25. #include <linux/highuid.h>
  26. #include <linux/init.h>
  27. #include <linux/msg.h>
  28. #include <linux/shm.h>
  29. #include <linux/syscalls.h>
  30. #include <linux/mutex.h>
  31. #include <asm/uaccess.h>
  32. #include "util.h"
  33. struct compat_msgbuf {
  34. compat_long_t mtype;
  35. char mtext[1];
  36. };
  37. struct compat_ipc_perm {
  38. key_t key;
  39. __compat_uid_t uid;
  40. __compat_gid_t gid;
  41. __compat_uid_t cuid;
  42. __compat_gid_t cgid;
  43. compat_mode_t mode;
  44. unsigned short seq;
  45. };
  46. struct compat_semid_ds {
  47. struct compat_ipc_perm sem_perm;
  48. compat_time_t sem_otime;
  49. compat_time_t sem_ctime;
  50. compat_uptr_t sem_base;
  51. compat_uptr_t sem_pending;
  52. compat_uptr_t sem_pending_last;
  53. compat_uptr_t undo;
  54. unsigned short sem_nsems;
  55. };
  56. struct compat_msqid_ds {
  57. struct compat_ipc_perm msg_perm;
  58. compat_uptr_t msg_first;
  59. compat_uptr_t msg_last;
  60. compat_time_t msg_stime;
  61. compat_time_t msg_rtime;
  62. compat_time_t msg_ctime;
  63. compat_ulong_t msg_lcbytes;
  64. compat_ulong_t msg_lqbytes;
  65. unsigned short msg_cbytes;
  66. unsigned short msg_qnum;
  67. unsigned short msg_qbytes;
  68. compat_ipc_pid_t msg_lspid;
  69. compat_ipc_pid_t msg_lrpid;
  70. };
  71. struct compat_shmid_ds {
  72. struct compat_ipc_perm shm_perm;
  73. int shm_segsz;
  74. compat_time_t shm_atime;
  75. compat_time_t shm_dtime;
  76. compat_time_t shm_ctime;
  77. compat_ipc_pid_t shm_cpid;
  78. compat_ipc_pid_t shm_lpid;
  79. unsigned short shm_nattch;
  80. unsigned short shm_unused;
  81. compat_uptr_t shm_unused2;
  82. compat_uptr_t shm_unused3;
  83. };
  84. struct compat_ipc_kludge {
  85. compat_uptr_t msgp;
  86. compat_long_t msgtyp;
  87. };
  88. struct compat_shminfo64 {
  89. compat_ulong_t shmmax;
  90. compat_ulong_t shmmin;
  91. compat_ulong_t shmmni;
  92. compat_ulong_t shmseg;
  93. compat_ulong_t shmall;
  94. compat_ulong_t __unused1;
  95. compat_ulong_t __unused2;
  96. compat_ulong_t __unused3;
  97. compat_ulong_t __unused4;
  98. };
  99. struct compat_shm_info {
  100. compat_int_t used_ids;
  101. compat_ulong_t shm_tot, shm_rss, shm_swp;
  102. compat_ulong_t swap_attempts, swap_successes;
  103. };
  104. extern int sem_ctls[];
  105. #define sc_semopm (sem_ctls[2])
  106. static inline int compat_ipc_parse_version(int *cmd)
  107. {
  108. int version = *cmd & IPC_64;
  109. /* this is tricky: architectures that have support for the old
  110. * ipc structures in 64 bit binaries need to have IPC_64 set
  111. * in cmd, the others need to have it cleared */
  112. #ifndef ipc_parse_version
  113. *cmd |= IPC_64;
  114. #else
  115. *cmd &= ~IPC_64;
  116. #endif
  117. return version;
  118. }
  119. static inline int __get_compat_ipc64_perm(struct ipc64_perm *p64,
  120. struct compat_ipc64_perm __user *up64)
  121. {
  122. int err;
  123. err = __get_user(p64->uid, &up64->uid);
  124. err |= __get_user(p64->gid, &up64->gid);
  125. err |= __get_user(p64->mode, &up64->mode);
  126. return err;
  127. }
  128. static inline int __get_compat_ipc_perm(struct ipc64_perm *p,
  129. struct compat_ipc_perm __user *up)
  130. {
  131. int err;
  132. err = __get_user(p->uid, &up->uid);
  133. err |= __get_user(p->gid, &up->gid);
  134. err |= __get_user(p->mode, &up->mode);
  135. return err;
  136. }
  137. static inline int __put_compat_ipc64_perm(struct ipc64_perm *p64,
  138. struct compat_ipc64_perm __user *up64)
  139. {
  140. int err;
  141. err = __put_user(p64->key, &up64->key);
  142. err |= __put_user(p64->uid, &up64->uid);
  143. err |= __put_user(p64->gid, &up64->gid);
  144. err |= __put_user(p64->cuid, &up64->cuid);
  145. err |= __put_user(p64->cgid, &up64->cgid);
  146. err |= __put_user(p64->mode, &up64->mode);
  147. err |= __put_user(p64->seq, &up64->seq);
  148. return err;
  149. }
  150. static inline int __put_compat_ipc_perm(struct ipc64_perm *p,
  151. struct compat_ipc_perm __user *up)
  152. {
  153. int err;
  154. __compat_uid_t u;
  155. __compat_gid_t g;
  156. err = __put_user(p->key, &up->key);
  157. SET_UID(u, p->uid);
  158. err |= __put_user(u, &up->uid);
  159. SET_GID(g, p->gid);
  160. err |= __put_user(g, &up->gid);
  161. SET_UID(u, p->cuid);
  162. err |= __put_user(u, &up->cuid);
  163. SET_GID(g, p->cgid);
  164. err |= __put_user(g, &up->cgid);
  165. err |= __put_user(p->mode, &up->mode);
  166. err |= __put_user(p->seq, &up->seq);
  167. return err;
  168. }
  169. static inline int get_compat_semid64_ds(struct semid64_ds *s64,
  170. struct compat_semid64_ds __user *up64)
  171. {
  172. if (!access_ok (VERIFY_READ, up64, sizeof(*up64)))
  173. return -EFAULT;
  174. return __get_compat_ipc64_perm(&s64->sem_perm, &up64->sem_perm);
  175. }
  176. static inline int get_compat_semid_ds(struct semid64_ds *s,
  177. struct compat_semid_ds __user *up)
  178. {
  179. if (!access_ok (VERIFY_READ, up, sizeof(*up)))
  180. return -EFAULT;
  181. return __get_compat_ipc_perm(&s->sem_perm, &up->sem_perm);
  182. }
  183. static inline int put_compat_semid64_ds(struct semid64_ds *s64,
  184. struct compat_semid64_ds __user *up64)
  185. {
  186. int err;
  187. if (!access_ok (VERIFY_WRITE, up64, sizeof(*up64)))
  188. return -EFAULT;
  189. err = __put_compat_ipc64_perm(&s64->sem_perm, &up64->sem_perm);
  190. err |= __put_user(s64->sem_otime, &up64->sem_otime);
  191. err |= __put_user(s64->sem_ctime, &up64->sem_ctime);
  192. err |= __put_user(s64->sem_nsems, &up64->sem_nsems);
  193. return err;
  194. }
  195. static inline int put_compat_semid_ds(struct semid64_ds *s,
  196. struct compat_semid_ds __user *up)
  197. {
  198. int err;
  199. if (!access_ok (VERIFY_WRITE, up, sizeof(*up)))
  200. return -EFAULT;
  201. err = __put_compat_ipc_perm(&s->sem_perm, &up->sem_perm);
  202. err |= __put_user(s->sem_otime, &up->sem_otime);
  203. err |= __put_user(s->sem_ctime, &up->sem_ctime);
  204. err |= __put_user(s->sem_nsems, &up->sem_nsems);
  205. return err;
  206. }
  207. long compat_sys_semctl(int first, int second, int third, void __user *uptr)
  208. {
  209. union semun fourth;
  210. u32 pad;
  211. int err, err2;
  212. struct semid64_ds s64;
  213. struct semid64_ds __user *up64;
  214. int version = compat_ipc_parse_version(&third);
  215. memset(&s64, 0, sizeof(s64));
  216. if (!uptr)
  217. return -EINVAL;
  218. if (get_user(pad, (u32 __user *) uptr))
  219. return -EFAULT;
  220. if ((third & (~IPC_64)) == SETVAL)
  221. fourth.val = (int) pad;
  222. else
  223. fourth.__pad = compat_ptr(pad);
  224. switch (third & (~IPC_64)) {
  225. case IPC_INFO:
  226. case IPC_RMID:
  227. case SEM_INFO:
  228. case GETVAL:
  229. case GETPID:
  230. case GETNCNT:
  231. case GETZCNT:
  232. case GETALL:
  233. case SETVAL:
  234. case SETALL:
  235. err = sys_semctl(first, second, third, fourth);
  236. break;
  237. case IPC_STAT:
  238. case SEM_STAT:
  239. up64 = compat_alloc_user_space(sizeof(s64));
  240. fourth.__pad = up64;
  241. err = sys_semctl(first, second, third, fourth);
  242. if (err < 0)
  243. break;
  244. if (copy_from_user(&s64, up64, sizeof(s64)))
  245. err2 = -EFAULT;
  246. else if (version == IPC_64)
  247. err2 = put_compat_semid64_ds(&s64, compat_ptr(pad));
  248. else
  249. err2 = put_compat_semid_ds(&s64, compat_ptr(pad));
  250. if (err2)
  251. err = -EFAULT;
  252. break;
  253. case IPC_SET:
  254. if (version == IPC_64) {
  255. err = get_compat_semid64_ds(&s64, compat_ptr(pad));
  256. } else {
  257. err = get_compat_semid_ds(&s64, compat_ptr(pad));
  258. }
  259. up64 = compat_alloc_user_space(sizeof(s64));
  260. if (copy_to_user(up64, &s64, sizeof(s64)))
  261. err = -EFAULT;
  262. if (err)
  263. break;
  264. fourth.__pad = up64;
  265. err = sys_semctl(first, second, third, fourth);
  266. break;
  267. default:
  268. err = -EINVAL;
  269. break;
  270. }
  271. return err;
  272. }
  273. long compat_sys_msgsnd(int first, int second, int third, void __user *uptr)
  274. {
  275. struct compat_msgbuf __user *up = uptr;
  276. long type;
  277. if (first < 0)
  278. return -EINVAL;
  279. if (second < 0)
  280. return -EINVAL;
  281. if (get_user(type, &up->mtype))
  282. return -EFAULT;
  283. return do_msgsnd(first, type, up->mtext, second, third);
  284. }
  285. long compat_sys_msgrcv(int first, int second, int msgtyp, int third,
  286. int version, void __user *uptr)
  287. {
  288. struct compat_msgbuf __user *up;
  289. long type;
  290. int err;
  291. if (first < 0)
  292. return -EINVAL;
  293. if (second < 0)
  294. return -EINVAL;
  295. if (!version) {
  296. struct compat_ipc_kludge ipck;
  297. err = -EINVAL;
  298. if (!uptr)
  299. goto out;
  300. err = -EFAULT;
  301. if (copy_from_user (&ipck, uptr, sizeof(ipck)))
  302. goto out;
  303. uptr = compat_ptr(ipck.msgp);
  304. msgtyp = ipck.msgtyp;
  305. }
  306. up = uptr;
  307. err = do_msgrcv(first, &type, up->mtext, second, msgtyp, third);
  308. if (err < 0)
  309. goto out;
  310. if (put_user(type, &up->mtype))
  311. err = -EFAULT;
  312. out:
  313. return err;
  314. }
  315. static inline int get_compat_msqid64(struct msqid64_ds *m64,
  316. struct compat_msqid64_ds __user *up64)
  317. {
  318. int err;
  319. if (!access_ok(VERIFY_READ, up64, sizeof(*up64)))
  320. return -EFAULT;
  321. err = __get_compat_ipc64_perm(&m64->msg_perm, &up64->msg_perm);
  322. err |= __get_user(m64->msg_qbytes, &up64->msg_qbytes);
  323. return err;
  324. }
  325. static inline int get_compat_msqid(struct msqid64_ds *m,
  326. struct compat_msqid_ds __user *up)
  327. {
  328. int err;
  329. if (!access_ok(VERIFY_READ, up, sizeof(*up)))
  330. return -EFAULT;
  331. err = __get_compat_ipc_perm(&m->msg_perm, &up->msg_perm);
  332. err |= __get_user(m->msg_qbytes, &up->msg_qbytes);
  333. return err;
  334. }
  335. static inline int put_compat_msqid64_ds(struct msqid64_ds *m64,
  336. struct compat_msqid64_ds __user *up64)
  337. {
  338. int err;
  339. if (!access_ok(VERIFY_WRITE, up64, sizeof(*up64)))
  340. return -EFAULT;
  341. err = __put_compat_ipc64_perm(&m64->msg_perm, &up64->msg_perm);
  342. err |= __put_user(m64->msg_stime, &up64->msg_stime);
  343. err |= __put_user(m64->msg_rtime, &up64->msg_rtime);
  344. err |= __put_user(m64->msg_ctime, &up64->msg_ctime);
  345. err |= __put_user(m64->msg_cbytes, &up64->msg_cbytes);
  346. err |= __put_user(m64->msg_qnum, &up64->msg_qnum);
  347. err |= __put_user(m64->msg_qbytes, &up64->msg_qbytes);
  348. err |= __put_user(m64->msg_lspid, &up64->msg_lspid);
  349. err |= __put_user(m64->msg_lrpid, &up64->msg_lrpid);
  350. return err;
  351. }
  352. static inline int put_compat_msqid_ds(struct msqid64_ds *m,
  353. struct compat_msqid_ds __user *up)
  354. {
  355. int err;
  356. if (!access_ok(VERIFY_WRITE, up, sizeof(*up)))
  357. return -EFAULT;
  358. err = __put_compat_ipc_perm(&m->msg_perm, &up->msg_perm);
  359. err |= __put_user(m->msg_stime, &up->msg_stime);
  360. err |= __put_user(m->msg_rtime, &up->msg_rtime);
  361. err |= __put_user(m->msg_ctime, &up->msg_ctime);
  362. err |= __put_user(m->msg_cbytes, &up->msg_cbytes);
  363. err |= __put_user(m->msg_qnum, &up->msg_qnum);
  364. err |= __put_user(m->msg_qbytes, &up->msg_qbytes);
  365. err |= __put_user(m->msg_lspid, &up->msg_lspid);
  366. err |= __put_user(m->msg_lrpid, &up->msg_lrpid);
  367. return err;
  368. }
  369. long compat_sys_msgctl(int first, int second, void __user *uptr)
  370. {
  371. int err, err2;
  372. struct msqid64_ds m64;
  373. int version = compat_ipc_parse_version(&second);
  374. void __user *p;
  375. memset(&m64, 0, sizeof(m64));
  376. switch (second & (~IPC_64)) {
  377. case IPC_INFO:
  378. case IPC_RMID:
  379. case MSG_INFO:
  380. err = sys_msgctl(first, second, uptr);
  381. break;
  382. case IPC_SET:
  383. if (version == IPC_64) {
  384. err = get_compat_msqid64(&m64, uptr);
  385. } else {
  386. err = get_compat_msqid(&m64, uptr);
  387. }
  388. if (err)
  389. break;
  390. p = compat_alloc_user_space(sizeof(m64));
  391. if (copy_to_user(p, &m64, sizeof(m64)))
  392. err = -EFAULT;
  393. else
  394. err = sys_msgctl(first, second, p);
  395. break;
  396. case IPC_STAT:
  397. case MSG_STAT:
  398. p = compat_alloc_user_space(sizeof(m64));
  399. err = sys_msgctl(first, second, p);
  400. if (err < 0)
  401. break;
  402. if (copy_from_user(&m64, p, sizeof(m64)))
  403. err2 = -EFAULT;
  404. else if (version == IPC_64)
  405. err2 = put_compat_msqid64_ds(&m64, uptr);
  406. else
  407. err2 = put_compat_msqid_ds(&m64, uptr);
  408. if (err2)
  409. err = -EFAULT;
  410. break;
  411. default:
  412. err = -EINVAL;
  413. break;
  414. }
  415. return err;
  416. }
  417. long compat_sys_shmat(int first, int second, compat_uptr_t third, int version,
  418. void __user *uptr)
  419. {
  420. int err;
  421. unsigned long raddr;
  422. compat_ulong_t __user *uaddr;
  423. if (version == 1)
  424. return -EINVAL;
  425. err = do_shmat(first, uptr, second, &raddr);
  426. if (err < 0)
  427. return err;
  428. uaddr = compat_ptr(third);
  429. return put_user(raddr, uaddr);
  430. }
  431. static inline int get_compat_shmid64_ds(struct shmid64_ds *s64,
  432. struct compat_shmid64_ds __user *up64)
  433. {
  434. if (!access_ok(VERIFY_READ, up64, sizeof(*up64)))
  435. return -EFAULT;
  436. return __get_compat_ipc64_perm(&s64->shm_perm, &up64->shm_perm);
  437. }
  438. static inline int get_compat_shmid_ds(struct shmid64_ds *s,
  439. struct compat_shmid_ds __user *up)
  440. {
  441. if (!access_ok(VERIFY_READ, up, sizeof(*up)))
  442. return -EFAULT;
  443. return __get_compat_ipc_perm(&s->shm_perm, &up->shm_perm);
  444. }
  445. static inline int put_compat_shmid64_ds(struct shmid64_ds *s64,
  446. struct compat_shmid64_ds __user *up64)
  447. {
  448. int err;
  449. if (!access_ok(VERIFY_WRITE, up64, sizeof(*up64)))
  450. return -EFAULT;
  451. err = __put_compat_ipc64_perm(&s64->shm_perm, &up64->shm_perm);
  452. err |= __put_user(s64->shm_atime, &up64->shm_atime);
  453. err |= __put_user(s64->shm_dtime, &up64->shm_dtime);
  454. err |= __put_user(s64->shm_ctime, &up64->shm_ctime);
  455. err |= __put_user(s64->shm_segsz, &up64->shm_segsz);
  456. err |= __put_user(s64->shm_nattch, &up64->shm_nattch);
  457. err |= __put_user(s64->shm_cpid, &up64->shm_cpid);
  458. err |= __put_user(s64->shm_lpid, &up64->shm_lpid);
  459. return err;
  460. }
  461. static inline int put_compat_shmid_ds(struct shmid64_ds *s,
  462. struct compat_shmid_ds __user *up)
  463. {
  464. int err;
  465. if (!access_ok(VERIFY_WRITE, up, sizeof(*up)))
  466. return -EFAULT;
  467. err = __put_compat_ipc_perm(&s->shm_perm, &up->shm_perm);
  468. err |= __put_user(s->shm_atime, &up->shm_atime);
  469. err |= __put_user(s->shm_dtime, &up->shm_dtime);
  470. err |= __put_user(s->shm_ctime, &up->shm_ctime);
  471. err |= __put_user(s->shm_segsz, &up->shm_segsz);
  472. err |= __put_user(s->shm_nattch, &up->shm_nattch);
  473. err |= __put_user(s->shm_cpid, &up->shm_cpid);
  474. err |= __put_user(s->shm_lpid, &up->shm_lpid);
  475. return err;
  476. }
  477. static inline int put_compat_shminfo64(struct shminfo64 *smi,
  478. struct compat_shminfo64 __user *up64)
  479. {
  480. int err;
  481. if (!access_ok(VERIFY_WRITE, up64, sizeof(*up64)))
  482. return -EFAULT;
  483. if (smi->shmmax > INT_MAX)
  484. smi->shmmax = INT_MAX;
  485. err = __put_user(smi->shmmax, &up64->shmmax);
  486. err |= __put_user(smi->shmmin, &up64->shmmin);
  487. err |= __put_user(smi->shmmni, &up64->shmmni);
  488. err |= __put_user(smi->shmseg, &up64->shmseg);
  489. err |= __put_user(smi->shmall, &up64->shmall);
  490. return err;
  491. }
  492. static inline int put_compat_shminfo(struct shminfo64 *smi,
  493. struct shminfo __user *up)
  494. {
  495. int err;
  496. if (!access_ok(VERIFY_WRITE, up, sizeof(*up)))
  497. return -EFAULT;
  498. if (smi->shmmax > INT_MAX)
  499. smi->shmmax = INT_MAX;
  500. err = __put_user(smi->shmmax, &up->shmmax);
  501. err |= __put_user(smi->shmmin, &up->shmmin);
  502. err |= __put_user(smi->shmmni, &up->shmmni);
  503. err |= __put_user(smi->shmseg, &up->shmseg);
  504. err |= __put_user(smi->shmall, &up->shmall);
  505. return err;
  506. }
  507. static inline int put_compat_shm_info(struct shm_info __user *ip,
  508. struct compat_shm_info __user *uip)
  509. {
  510. int err;
  511. struct shm_info si;
  512. if (!access_ok(VERIFY_WRITE, uip, sizeof(*uip)) ||
  513. copy_from_user(&si, ip, sizeof(si)))
  514. return -EFAULT;
  515. err = __put_user(si.used_ids, &uip->used_ids);
  516. err |= __put_user(si.shm_tot, &uip->shm_tot);
  517. err |= __put_user(si.shm_rss, &uip->shm_rss);
  518. err |= __put_user(si.shm_swp, &uip->shm_swp);
  519. err |= __put_user(si.swap_attempts, &uip->swap_attempts);
  520. err |= __put_user(si.swap_successes, &uip->swap_successes);
  521. return err;
  522. }
  523. long compat_sys_shmctl(int first, int second, void __user *uptr)
  524. {
  525. void __user *p;
  526. struct shmid64_ds s64;
  527. struct shminfo64 smi;
  528. int err, err2;
  529. int version = compat_ipc_parse_version(&second);
  530. memset(&s64, 0, sizeof(s64));
  531. switch (second & (~IPC_64)) {
  532. case IPC_RMID:
  533. case SHM_LOCK:
  534. case SHM_UNLOCK:
  535. err = sys_shmctl(first, second, uptr);
  536. break;
  537. case IPC_INFO:
  538. p = compat_alloc_user_space(sizeof(smi));
  539. err = sys_shmctl(first, second, p);
  540. if (err < 0)
  541. break;
  542. if (copy_from_user(&smi, p, sizeof(smi)))
  543. err2 = -EFAULT;
  544. else if (version == IPC_64)
  545. err2 = put_compat_shminfo64(&smi, uptr);
  546. else
  547. err2 = put_compat_shminfo(&smi, uptr);
  548. if (err2)
  549. err = -EFAULT;
  550. break;
  551. case IPC_SET:
  552. if (version == IPC_64) {
  553. err = get_compat_shmid64_ds(&s64, uptr);
  554. } else {
  555. err = get_compat_shmid_ds(&s64, uptr);
  556. }
  557. if (err)
  558. break;
  559. p = compat_alloc_user_space(sizeof(s64));
  560. if (copy_to_user(p, &s64, sizeof(s64)))
  561. err = -EFAULT;
  562. else
  563. err = sys_shmctl(first, second, p);
  564. break;
  565. case IPC_STAT:
  566. case SHM_STAT:
  567. p = compat_alloc_user_space(sizeof(s64));
  568. err = sys_shmctl(first, second, p);
  569. if (err < 0)
  570. break;
  571. if (copy_from_user(&s64, p, sizeof(s64)))
  572. err2 = -EFAULT;
  573. else if (version == IPC_64)
  574. err2 = put_compat_shmid64_ds(&s64, uptr);
  575. else
  576. err2 = put_compat_shmid_ds(&s64, uptr);
  577. if (err2)
  578. err = -EFAULT;
  579. break;
  580. case SHM_INFO:
  581. p = compat_alloc_user_space(sizeof(struct shm_info));
  582. err = sys_shmctl(first, second, p);
  583. if (err < 0)
  584. break;
  585. err2 = put_compat_shm_info(p, uptr);
  586. if (err2)
  587. err = -EFAULT;
  588. break;
  589. default:
  590. err = -EINVAL;
  591. break;
  592. }
  593. return err;
  594. }
  595. long compat_sys_semtimedop(int semid, struct sembuf __user *tsems,
  596. unsigned nsops, const struct compat_timespec __user *timeout)
  597. {
  598. struct timespec __user *ts64 = NULL;
  599. if (timeout) {
  600. struct timespec ts;
  601. ts64 = compat_alloc_user_space(sizeof(*ts64));
  602. if (get_compat_timespec(&ts, timeout))
  603. return -EFAULT;
  604. if (copy_to_user(ts64, &ts, sizeof(ts)))
  605. return -EFAULT;
  606. }
  607. return sys_semtimedop(semid, tsems, nsops, ts64);
  608. }