compat_linux.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972
  1. /*
  2. * arch/s390x/kernel/linux32.c
  3. *
  4. * S390 version
  5. * Copyright (C) 2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
  6. * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
  7. * Gerhard Tonn (ton@de.ibm.com)
  8. * Thomas Spatzier (tspat@de.ibm.com)
  9. *
  10. * Conversion between 31bit and 64bit native syscalls.
  11. *
  12. * Heavily inspired by the 32-bit Sparc compat code which is
  13. * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  14. * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
  15. *
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/sched.h>
  19. #include <linux/fs.h>
  20. #include <linux/mm.h>
  21. #include <linux/file.h>
  22. #include <linux/signal.h>
  23. #include <linux/resource.h>
  24. #include <linux/times.h>
  25. #include <linux/utsname.h>
  26. #include <linux/smp.h>
  27. #include <linux/smp_lock.h>
  28. #include <linux/sem.h>
  29. #include <linux/msg.h>
  30. #include <linux/shm.h>
  31. #include <linux/slab.h>
  32. #include <linux/uio.h>
  33. #include <linux/nfs_fs.h>
  34. #include <linux/quota.h>
  35. #include <linux/module.h>
  36. #include <linux/sunrpc/svc.h>
  37. #include <linux/nfsd/nfsd.h>
  38. #include <linux/nfsd/cache.h>
  39. #include <linux/nfsd/xdr.h>
  40. #include <linux/nfsd/syscall.h>
  41. #include <linux/poll.h>
  42. #include <linux/personality.h>
  43. #include <linux/stat.h>
  44. #include <linux/filter.h>
  45. #include <linux/highmem.h>
  46. #include <linux/highuid.h>
  47. #include <linux/mman.h>
  48. #include <linux/ipv6.h>
  49. #include <linux/in.h>
  50. #include <linux/icmpv6.h>
  51. #include <linux/syscalls.h>
  52. #include <linux/sysctl.h>
  53. #include <linux/binfmts.h>
  54. #include <linux/capability.h>
  55. #include <linux/compat.h>
  56. #include <linux/vfs.h>
  57. #include <linux/ptrace.h>
  58. #include <linux/fadvise.h>
  59. #include <asm/types.h>
  60. #include <asm/ipc.h>
  61. #include <asm/uaccess.h>
  62. #include <asm/semaphore.h>
  63. #include <net/scm.h>
  64. #include <net/sock.h>
  65. #include "compat_linux.h"
  66. long psw_user32_bits = (PSW_BASE32_BITS | PSW_MASK_DAT | PSW_ASC_HOME |
  67. PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK |
  68. PSW_MASK_PSTATE | PSW_DEFAULT_KEY);
  69. long psw32_user_bits = (PSW32_BASE_BITS | PSW32_MASK_DAT | PSW32_ASC_HOME |
  70. PSW32_MASK_IO | PSW32_MASK_EXT | PSW32_MASK_MCHECK |
  71. PSW32_MASK_PSTATE);
  72. /* For this source file, we want overflow handling. */
  73. #undef high2lowuid
  74. #undef high2lowgid
  75. #undef low2highuid
  76. #undef low2highgid
  77. #undef SET_UID16
  78. #undef SET_GID16
  79. #undef NEW_TO_OLD_UID
  80. #undef NEW_TO_OLD_GID
  81. #undef SET_OLDSTAT_UID
  82. #undef SET_OLDSTAT_GID
  83. #undef SET_STAT_UID
  84. #undef SET_STAT_GID
  85. #define high2lowuid(uid) ((uid) > 65535) ? (u16)overflowuid : (u16)(uid)
  86. #define high2lowgid(gid) ((gid) > 65535) ? (u16)overflowgid : (u16)(gid)
  87. #define low2highuid(uid) ((uid) == (u16)-1) ? (uid_t)-1 : (uid_t)(uid)
  88. #define low2highgid(gid) ((gid) == (u16)-1) ? (gid_t)-1 : (gid_t)(gid)
  89. #define SET_UID16(var, uid) var = high2lowuid(uid)
  90. #define SET_GID16(var, gid) var = high2lowgid(gid)
  91. #define NEW_TO_OLD_UID(uid) high2lowuid(uid)
  92. #define NEW_TO_OLD_GID(gid) high2lowgid(gid)
  93. #define SET_OLDSTAT_UID(stat, uid) (stat).st_uid = high2lowuid(uid)
  94. #define SET_OLDSTAT_GID(stat, gid) (stat).st_gid = high2lowgid(gid)
  95. #define SET_STAT_UID(stat, uid) (stat).st_uid = high2lowuid(uid)
  96. #define SET_STAT_GID(stat, gid) (stat).st_gid = high2lowgid(gid)
  97. asmlinkage long sys32_chown16(const char __user * filename, u16 user, u16 group)
  98. {
  99. return sys_chown(filename, low2highuid(user), low2highgid(group));
  100. }
  101. asmlinkage long sys32_lchown16(const char __user * filename, u16 user, u16 group)
  102. {
  103. return sys_lchown(filename, low2highuid(user), low2highgid(group));
  104. }
  105. asmlinkage long sys32_fchown16(unsigned int fd, u16 user, u16 group)
  106. {
  107. return sys_fchown(fd, low2highuid(user), low2highgid(group));
  108. }
  109. asmlinkage long sys32_setregid16(u16 rgid, u16 egid)
  110. {
  111. return sys_setregid(low2highgid(rgid), low2highgid(egid));
  112. }
  113. asmlinkage long sys32_setgid16(u16 gid)
  114. {
  115. return sys_setgid((gid_t)gid);
  116. }
  117. asmlinkage long sys32_setreuid16(u16 ruid, u16 euid)
  118. {
  119. return sys_setreuid(low2highuid(ruid), low2highuid(euid));
  120. }
  121. asmlinkage long sys32_setuid16(u16 uid)
  122. {
  123. return sys_setuid((uid_t)uid);
  124. }
  125. asmlinkage long sys32_setresuid16(u16 ruid, u16 euid, u16 suid)
  126. {
  127. return sys_setresuid(low2highuid(ruid), low2highuid(euid),
  128. low2highuid(suid));
  129. }
  130. asmlinkage long sys32_getresuid16(u16 __user *ruid, u16 __user *euid, u16 __user *suid)
  131. {
  132. int retval;
  133. if (!(retval = put_user(high2lowuid(current->uid), ruid)) &&
  134. !(retval = put_user(high2lowuid(current->euid), euid)))
  135. retval = put_user(high2lowuid(current->suid), suid);
  136. return retval;
  137. }
  138. asmlinkage long sys32_setresgid16(u16 rgid, u16 egid, u16 sgid)
  139. {
  140. return sys_setresgid(low2highgid(rgid), low2highgid(egid),
  141. low2highgid(sgid));
  142. }
  143. asmlinkage long sys32_getresgid16(u16 __user *rgid, u16 __user *egid, u16 __user *sgid)
  144. {
  145. int retval;
  146. if (!(retval = put_user(high2lowgid(current->gid), rgid)) &&
  147. !(retval = put_user(high2lowgid(current->egid), egid)))
  148. retval = put_user(high2lowgid(current->sgid), sgid);
  149. return retval;
  150. }
  151. asmlinkage long sys32_setfsuid16(u16 uid)
  152. {
  153. return sys_setfsuid((uid_t)uid);
  154. }
  155. asmlinkage long sys32_setfsgid16(u16 gid)
  156. {
  157. return sys_setfsgid((gid_t)gid);
  158. }
  159. static int groups16_to_user(u16 __user *grouplist, struct group_info *group_info)
  160. {
  161. int i;
  162. u16 group;
  163. for (i = 0; i < group_info->ngroups; i++) {
  164. group = (u16)GROUP_AT(group_info, i);
  165. if (put_user(group, grouplist+i))
  166. return -EFAULT;
  167. }
  168. return 0;
  169. }
  170. static int groups16_from_user(struct group_info *group_info, u16 __user *grouplist)
  171. {
  172. int i;
  173. u16 group;
  174. for (i = 0; i < group_info->ngroups; i++) {
  175. if (get_user(group, grouplist+i))
  176. return -EFAULT;
  177. GROUP_AT(group_info, i) = (gid_t)group;
  178. }
  179. return 0;
  180. }
  181. asmlinkage long sys32_getgroups16(int gidsetsize, u16 __user *grouplist)
  182. {
  183. int i;
  184. if (gidsetsize < 0)
  185. return -EINVAL;
  186. get_group_info(current->group_info);
  187. i = current->group_info->ngroups;
  188. if (gidsetsize) {
  189. if (i > gidsetsize) {
  190. i = -EINVAL;
  191. goto out;
  192. }
  193. if (groups16_to_user(grouplist, current->group_info)) {
  194. i = -EFAULT;
  195. goto out;
  196. }
  197. }
  198. out:
  199. put_group_info(current->group_info);
  200. return i;
  201. }
  202. asmlinkage long sys32_setgroups16(int gidsetsize, u16 __user *grouplist)
  203. {
  204. struct group_info *group_info;
  205. int retval;
  206. if (!capable(CAP_SETGID))
  207. return -EPERM;
  208. if ((unsigned)gidsetsize > NGROUPS_MAX)
  209. return -EINVAL;
  210. group_info = groups_alloc(gidsetsize);
  211. if (!group_info)
  212. return -ENOMEM;
  213. retval = groups16_from_user(group_info, grouplist);
  214. if (retval) {
  215. put_group_info(group_info);
  216. return retval;
  217. }
  218. retval = set_current_groups(group_info);
  219. put_group_info(group_info);
  220. return retval;
  221. }
  222. asmlinkage long sys32_getuid16(void)
  223. {
  224. return high2lowuid(current->uid);
  225. }
  226. asmlinkage long sys32_geteuid16(void)
  227. {
  228. return high2lowuid(current->euid);
  229. }
  230. asmlinkage long sys32_getgid16(void)
  231. {
  232. return high2lowgid(current->gid);
  233. }
  234. asmlinkage long sys32_getegid16(void)
  235. {
  236. return high2lowgid(current->egid);
  237. }
  238. /* 32-bit timeval and related flotsam. */
  239. static inline long get_tv32(struct timeval *o, struct compat_timeval __user *i)
  240. {
  241. return (!access_ok(VERIFY_READ, o, sizeof(*o)) ||
  242. (__get_user(o->tv_sec, &i->tv_sec) ||
  243. __get_user(o->tv_usec, &i->tv_usec)));
  244. }
  245. static inline long put_tv32(struct compat_timeval __user *o, struct timeval *i)
  246. {
  247. return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
  248. (__put_user(i->tv_sec, &o->tv_sec) ||
  249. __put_user(i->tv_usec, &o->tv_usec)));
  250. }
  251. /*
  252. * sys32_ipc() is the de-multiplexer for the SysV IPC calls in 32bit emulation.
  253. *
  254. * This is really horribly ugly.
  255. */
  256. #ifdef CONFIG_SYSVIPC
  257. asmlinkage long sys32_ipc(u32 call, int first, int second, int third, u32 ptr)
  258. {
  259. if (call >> 16) /* hack for backward compatibility */
  260. return -EINVAL;
  261. call &= 0xffff;
  262. switch (call) {
  263. case SEMTIMEDOP:
  264. return compat_sys_semtimedop(first, compat_ptr(ptr),
  265. second, compat_ptr(third));
  266. case SEMOP:
  267. /* struct sembuf is the same on 32 and 64bit :)) */
  268. return sys_semtimedop(first, compat_ptr(ptr),
  269. second, NULL);
  270. case SEMGET:
  271. return sys_semget(first, second, third);
  272. case SEMCTL:
  273. return compat_sys_semctl(first, second, third,
  274. compat_ptr(ptr));
  275. case MSGSND:
  276. return compat_sys_msgsnd(first, second, third,
  277. compat_ptr(ptr));
  278. case MSGRCV:
  279. return compat_sys_msgrcv(first, second, 0, third,
  280. 0, compat_ptr(ptr));
  281. case MSGGET:
  282. return sys_msgget((key_t) first, second);
  283. case MSGCTL:
  284. return compat_sys_msgctl(first, second, compat_ptr(ptr));
  285. case SHMAT:
  286. return compat_sys_shmat(first, second, third,
  287. 0, compat_ptr(ptr));
  288. case SHMDT:
  289. return sys_shmdt(compat_ptr(ptr));
  290. case SHMGET:
  291. return sys_shmget(first, (unsigned)second, third);
  292. case SHMCTL:
  293. return compat_sys_shmctl(first, second, compat_ptr(ptr));
  294. }
  295. return -ENOSYS;
  296. }
  297. #endif
  298. asmlinkage long sys32_truncate64(const char __user * path, unsigned long high, unsigned long low)
  299. {
  300. if ((int)high < 0)
  301. return -EINVAL;
  302. else
  303. return sys_truncate(path, (high << 32) | low);
  304. }
  305. asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long high, unsigned long low)
  306. {
  307. if ((int)high < 0)
  308. return -EINVAL;
  309. else
  310. return sys_ftruncate(fd, (high << 32) | low);
  311. }
  312. int cp_compat_stat(struct kstat *stat, struct compat_stat __user *statbuf)
  313. {
  314. compat_ino_t ino;
  315. int err;
  316. if (!old_valid_dev(stat->dev) || !old_valid_dev(stat->rdev))
  317. return -EOVERFLOW;
  318. ino = stat->ino;
  319. if (sizeof(ino) < sizeof(stat->ino) && ino != stat->ino)
  320. return -EOVERFLOW;
  321. err = put_user(old_encode_dev(stat->dev), &statbuf->st_dev);
  322. err |= put_user(stat->ino, &statbuf->st_ino);
  323. err |= put_user(stat->mode, &statbuf->st_mode);
  324. err |= put_user(stat->nlink, &statbuf->st_nlink);
  325. err |= put_user(high2lowuid(stat->uid), &statbuf->st_uid);
  326. err |= put_user(high2lowgid(stat->gid), &statbuf->st_gid);
  327. err |= put_user(old_encode_dev(stat->rdev), &statbuf->st_rdev);
  328. err |= put_user(stat->size, &statbuf->st_size);
  329. err |= put_user(stat->atime.tv_sec, &statbuf->st_atime);
  330. err |= put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
  331. err |= put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
  332. err |= put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
  333. err |= put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
  334. err |= put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
  335. err |= put_user(stat->blksize, &statbuf->st_blksize);
  336. err |= put_user(stat->blocks, &statbuf->st_blocks);
  337. /* fixme
  338. err |= put_user(0, &statbuf->__unused4[0]);
  339. err |= put_user(0, &statbuf->__unused4[1]);
  340. */
  341. return err;
  342. }
  343. asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
  344. struct compat_timespec __user *interval)
  345. {
  346. struct timespec t;
  347. int ret;
  348. mm_segment_t old_fs = get_fs ();
  349. set_fs (KERNEL_DS);
  350. ret = sys_sched_rr_get_interval(pid,
  351. (struct timespec __force __user *) &t);
  352. set_fs (old_fs);
  353. if (put_compat_timespec(&t, interval))
  354. return -EFAULT;
  355. return ret;
  356. }
  357. asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
  358. compat_sigset_t __user *oset, size_t sigsetsize)
  359. {
  360. sigset_t s;
  361. compat_sigset_t s32;
  362. int ret;
  363. mm_segment_t old_fs = get_fs();
  364. if (set) {
  365. if (copy_from_user (&s32, set, sizeof(compat_sigset_t)))
  366. return -EFAULT;
  367. switch (_NSIG_WORDS) {
  368. case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
  369. case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
  370. case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
  371. case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
  372. }
  373. }
  374. set_fs (KERNEL_DS);
  375. ret = sys_rt_sigprocmask(how,
  376. set ? (sigset_t __force __user *) &s : NULL,
  377. oset ? (sigset_t __force __user *) &s : NULL,
  378. sigsetsize);
  379. set_fs (old_fs);
  380. if (ret) return ret;
  381. if (oset) {
  382. switch (_NSIG_WORDS) {
  383. case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
  384. case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
  385. case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
  386. case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
  387. }
  388. if (copy_to_user (oset, &s32, sizeof(compat_sigset_t)))
  389. return -EFAULT;
  390. }
  391. return 0;
  392. }
  393. asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
  394. size_t sigsetsize)
  395. {
  396. sigset_t s;
  397. compat_sigset_t s32;
  398. int ret;
  399. mm_segment_t old_fs = get_fs();
  400. set_fs (KERNEL_DS);
  401. ret = sys_rt_sigpending((sigset_t __force __user *) &s, sigsetsize);
  402. set_fs (old_fs);
  403. if (!ret) {
  404. switch (_NSIG_WORDS) {
  405. case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
  406. case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
  407. case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
  408. case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
  409. }
  410. if (copy_to_user (set, &s32, sizeof(compat_sigset_t)))
  411. return -EFAULT;
  412. }
  413. return ret;
  414. }
  415. asmlinkage long
  416. sys32_rt_sigqueueinfo(int pid, int sig, compat_siginfo_t __user *uinfo)
  417. {
  418. siginfo_t info;
  419. int ret;
  420. mm_segment_t old_fs = get_fs();
  421. if (copy_siginfo_from_user32(&info, uinfo))
  422. return -EFAULT;
  423. set_fs (KERNEL_DS);
  424. ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force __user *) &info);
  425. set_fs (old_fs);
  426. return ret;
  427. }
  428. /*
  429. * sys32_execve() executes a new program after the asm stub has set
  430. * things up for us. This should basically do what I want it to.
  431. */
  432. asmlinkage long
  433. sys32_execve(struct pt_regs regs)
  434. {
  435. int error;
  436. char * filename;
  437. filename = getname(compat_ptr(regs.orig_gpr2));
  438. error = PTR_ERR(filename);
  439. if (IS_ERR(filename))
  440. goto out;
  441. error = compat_do_execve(filename, compat_ptr(regs.gprs[3]),
  442. compat_ptr(regs.gprs[4]), &regs);
  443. if (error == 0)
  444. {
  445. task_lock(current);
  446. current->ptrace &= ~PT_DTRACE;
  447. task_unlock(current);
  448. current->thread.fp_regs.fpc=0;
  449. asm volatile("sfpc %0,0" : : "d" (0));
  450. }
  451. putname(filename);
  452. out:
  453. return error;
  454. }
  455. #ifdef CONFIG_MODULES
  456. asmlinkage long
  457. sys32_init_module(void __user *umod, unsigned long len,
  458. const char __user *uargs)
  459. {
  460. return sys_init_module(umod, len, uargs);
  461. }
  462. asmlinkage long
  463. sys32_delete_module(const char __user *name_user, unsigned int flags)
  464. {
  465. return sys_delete_module(name_user, flags);
  466. }
  467. #else /* CONFIG_MODULES */
  468. asmlinkage long
  469. sys32_init_module(void __user *umod, unsigned long len,
  470. const char __user *uargs)
  471. {
  472. return -ENOSYS;
  473. }
  474. asmlinkage long
  475. sys32_delete_module(const char __user *name_user, unsigned int flags)
  476. {
  477. return -ENOSYS;
  478. }
  479. #endif /* CONFIG_MODULES */
  480. /* Translations due to time_t size differences. Which affects all
  481. sorts of things, like timeval and itimerval. */
  482. extern struct timezone sys_tz;
  483. asmlinkage long sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
  484. {
  485. if (tv) {
  486. struct timeval ktv;
  487. do_gettimeofday(&ktv);
  488. if (put_tv32(tv, &ktv))
  489. return -EFAULT;
  490. }
  491. if (tz) {
  492. if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
  493. return -EFAULT;
  494. }
  495. return 0;
  496. }
  497. static inline long get_ts32(struct timespec *o, struct compat_timeval __user *i)
  498. {
  499. long usec;
  500. if (!access_ok(VERIFY_READ, i, sizeof(*i)))
  501. return -EFAULT;
  502. if (__get_user(o->tv_sec, &i->tv_sec))
  503. return -EFAULT;
  504. if (__get_user(usec, &i->tv_usec))
  505. return -EFAULT;
  506. o->tv_nsec = usec * 1000;
  507. return 0;
  508. }
  509. asmlinkage long sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
  510. {
  511. struct timespec kts;
  512. struct timezone ktz;
  513. if (tv) {
  514. if (get_ts32(&kts, tv))
  515. return -EFAULT;
  516. }
  517. if (tz) {
  518. if (copy_from_user(&ktz, tz, sizeof(ktz)))
  519. return -EFAULT;
  520. }
  521. return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
  522. }
  523. /* These are here just in case some old sparc32 binary calls it. */
  524. asmlinkage long sys32_pause(void)
  525. {
  526. current->state = TASK_INTERRUPTIBLE;
  527. schedule();
  528. return -ERESTARTNOHAND;
  529. }
  530. asmlinkage long sys32_pread64(unsigned int fd, char __user *ubuf,
  531. size_t count, u32 poshi, u32 poslo)
  532. {
  533. if ((compat_ssize_t) count < 0)
  534. return -EINVAL;
  535. return sys_pread64(fd, ubuf, count, ((loff_t)AA(poshi) << 32) | AA(poslo));
  536. }
  537. asmlinkage long sys32_pwrite64(unsigned int fd, const char __user *ubuf,
  538. size_t count, u32 poshi, u32 poslo)
  539. {
  540. if ((compat_ssize_t) count < 0)
  541. return -EINVAL;
  542. return sys_pwrite64(fd, ubuf, count, ((loff_t)AA(poshi) << 32) | AA(poslo));
  543. }
  544. asmlinkage compat_ssize_t sys32_readahead(int fd, u32 offhi, u32 offlo, s32 count)
  545. {
  546. return sys_readahead(fd, ((loff_t)AA(offhi) << 32) | AA(offlo), count);
  547. }
  548. asmlinkage long sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset, size_t count)
  549. {
  550. mm_segment_t old_fs = get_fs();
  551. int ret;
  552. off_t of;
  553. if (offset && get_user(of, offset))
  554. return -EFAULT;
  555. set_fs(KERNEL_DS);
  556. ret = sys_sendfile(out_fd, in_fd,
  557. offset ? (off_t __force __user *) &of : NULL, count);
  558. set_fs(old_fs);
  559. if (offset && put_user(of, offset))
  560. return -EFAULT;
  561. return ret;
  562. }
  563. asmlinkage long sys32_sendfile64(int out_fd, int in_fd,
  564. compat_loff_t __user *offset, s32 count)
  565. {
  566. mm_segment_t old_fs = get_fs();
  567. int ret;
  568. loff_t lof;
  569. if (offset && get_user(lof, offset))
  570. return -EFAULT;
  571. set_fs(KERNEL_DS);
  572. ret = sys_sendfile64(out_fd, in_fd,
  573. offset ? (loff_t __force __user *) &lof : NULL,
  574. count);
  575. set_fs(old_fs);
  576. if (offset && put_user(lof, offset))
  577. return -EFAULT;
  578. return ret;
  579. }
  580. #ifdef CONFIG_SYSCTL_SYSCALL
  581. struct __sysctl_args32 {
  582. u32 name;
  583. int nlen;
  584. u32 oldval;
  585. u32 oldlenp;
  586. u32 newval;
  587. u32 newlen;
  588. u32 __unused[4];
  589. };
  590. asmlinkage long sys32_sysctl(struct __sysctl_args32 __user *args)
  591. {
  592. struct __sysctl_args32 tmp;
  593. int error;
  594. size_t oldlen;
  595. size_t __user *oldlenp = NULL;
  596. unsigned long addr = (((unsigned long)&args->__unused[0]) + 7) & ~7;
  597. if (copy_from_user(&tmp, args, sizeof(tmp)))
  598. return -EFAULT;
  599. if (tmp.oldval && tmp.oldlenp) {
  600. /* Duh, this is ugly and might not work if sysctl_args
  601. is in read-only memory, but do_sysctl does indirectly
  602. a lot of uaccess in both directions and we'd have to
  603. basically copy the whole sysctl.c here, and
  604. glibc's __sysctl uses rw memory for the structure
  605. anyway. */
  606. if (get_user(oldlen, (u32 __user *)compat_ptr(tmp.oldlenp)) ||
  607. put_user(oldlen, (size_t __user *)addr))
  608. return -EFAULT;
  609. oldlenp = (size_t __user *)addr;
  610. }
  611. lock_kernel();
  612. error = do_sysctl(compat_ptr(tmp.name), tmp.nlen, compat_ptr(tmp.oldval),
  613. oldlenp, compat_ptr(tmp.newval), tmp.newlen);
  614. unlock_kernel();
  615. if (oldlenp) {
  616. if (!error) {
  617. if (get_user(oldlen, (size_t __user *)addr) ||
  618. put_user(oldlen, (u32 __user *)compat_ptr(tmp.oldlenp)))
  619. error = -EFAULT;
  620. }
  621. if (copy_to_user(args->__unused, tmp.__unused,
  622. sizeof(tmp.__unused)))
  623. error = -EFAULT;
  624. }
  625. return error;
  626. }
  627. #endif
  628. struct stat64_emu31 {
  629. unsigned long long st_dev;
  630. unsigned int __pad1;
  631. #define STAT64_HAS_BROKEN_ST_INO 1
  632. u32 __st_ino;
  633. unsigned int st_mode;
  634. unsigned int st_nlink;
  635. u32 st_uid;
  636. u32 st_gid;
  637. unsigned long long st_rdev;
  638. unsigned int __pad3;
  639. long st_size;
  640. u32 st_blksize;
  641. unsigned char __pad4[4];
  642. u32 __pad5; /* future possible st_blocks high bits */
  643. u32 st_blocks; /* Number 512-byte blocks allocated. */
  644. u32 st_atime;
  645. u32 __pad6;
  646. u32 st_mtime;
  647. u32 __pad7;
  648. u32 st_ctime;
  649. u32 __pad8; /* will be high 32 bits of ctime someday */
  650. unsigned long st_ino;
  651. };
  652. static int cp_stat64(struct stat64_emu31 __user *ubuf, struct kstat *stat)
  653. {
  654. struct stat64_emu31 tmp;
  655. memset(&tmp, 0, sizeof(tmp));
  656. tmp.st_dev = huge_encode_dev(stat->dev);
  657. tmp.st_ino = stat->ino;
  658. tmp.__st_ino = (u32)stat->ino;
  659. tmp.st_mode = stat->mode;
  660. tmp.st_nlink = (unsigned int)stat->nlink;
  661. tmp.st_uid = stat->uid;
  662. tmp.st_gid = stat->gid;
  663. tmp.st_rdev = huge_encode_dev(stat->rdev);
  664. tmp.st_size = stat->size;
  665. tmp.st_blksize = (u32)stat->blksize;
  666. tmp.st_blocks = (u32)stat->blocks;
  667. tmp.st_atime = (u32)stat->atime.tv_sec;
  668. tmp.st_mtime = (u32)stat->mtime.tv_sec;
  669. tmp.st_ctime = (u32)stat->ctime.tv_sec;
  670. return copy_to_user(ubuf,&tmp,sizeof(tmp)) ? -EFAULT : 0;
  671. }
  672. asmlinkage long sys32_stat64(char __user * filename, struct stat64_emu31 __user * statbuf)
  673. {
  674. struct kstat stat;
  675. int ret = vfs_stat(filename, &stat);
  676. if (!ret)
  677. ret = cp_stat64(statbuf, &stat);
  678. return ret;
  679. }
  680. asmlinkage long sys32_lstat64(char __user * filename, struct stat64_emu31 __user * statbuf)
  681. {
  682. struct kstat stat;
  683. int ret = vfs_lstat(filename, &stat);
  684. if (!ret)
  685. ret = cp_stat64(statbuf, &stat);
  686. return ret;
  687. }
  688. asmlinkage long sys32_fstat64(unsigned long fd, struct stat64_emu31 __user * statbuf)
  689. {
  690. struct kstat stat;
  691. int ret = vfs_fstat(fd, &stat);
  692. if (!ret)
  693. ret = cp_stat64(statbuf, &stat);
  694. return ret;
  695. }
  696. asmlinkage long sys32_fstatat64(unsigned int dfd, char __user *filename,
  697. struct stat64_emu31 __user* statbuf, int flag)
  698. {
  699. struct kstat stat;
  700. int error = -EINVAL;
  701. if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
  702. goto out;
  703. if (flag & AT_SYMLINK_NOFOLLOW)
  704. error = vfs_lstat_fd(dfd, filename, &stat);
  705. else
  706. error = vfs_stat_fd(dfd, filename, &stat);
  707. if (!error)
  708. error = cp_stat64(statbuf, &stat);
  709. out:
  710. return error;
  711. }
  712. /*
  713. * Linux/i386 didn't use to be able to handle more than
  714. * 4 system call parameters, so these system calls used a memory
  715. * block for parameter passing..
  716. */
  717. struct mmap_arg_struct_emu31 {
  718. u32 addr;
  719. u32 len;
  720. u32 prot;
  721. u32 flags;
  722. u32 fd;
  723. u32 offset;
  724. };
  725. /* common code for old and new mmaps */
  726. static inline long do_mmap2(
  727. unsigned long addr, unsigned long len,
  728. unsigned long prot, unsigned long flags,
  729. unsigned long fd, unsigned long pgoff)
  730. {
  731. struct file * file = NULL;
  732. unsigned long error = -EBADF;
  733. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  734. if (!(flags & MAP_ANONYMOUS)) {
  735. file = fget(fd);
  736. if (!file)
  737. goto out;
  738. }
  739. down_write(&current->mm->mmap_sem);
  740. error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  741. if (!IS_ERR((void *) error) && error + len >= 0x80000000ULL) {
  742. /* Result is out of bounds. */
  743. do_munmap(current->mm, addr, len);
  744. error = -ENOMEM;
  745. }
  746. up_write(&current->mm->mmap_sem);
  747. if (file)
  748. fput(file);
  749. out:
  750. return error;
  751. }
  752. asmlinkage unsigned long
  753. old32_mmap(struct mmap_arg_struct_emu31 __user *arg)
  754. {
  755. struct mmap_arg_struct_emu31 a;
  756. int error = -EFAULT;
  757. if (copy_from_user(&a, arg, sizeof(a)))
  758. goto out;
  759. error = -EINVAL;
  760. if (a.offset & ~PAGE_MASK)
  761. goto out;
  762. error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
  763. out:
  764. return error;
  765. }
  766. asmlinkage long
  767. sys32_mmap2(struct mmap_arg_struct_emu31 __user *arg)
  768. {
  769. struct mmap_arg_struct_emu31 a;
  770. int error = -EFAULT;
  771. if (copy_from_user(&a, arg, sizeof(a)))
  772. goto out;
  773. error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
  774. out:
  775. return error;
  776. }
  777. asmlinkage long sys32_read(unsigned int fd, char __user * buf, size_t count)
  778. {
  779. if ((compat_ssize_t) count < 0)
  780. return -EINVAL;
  781. return sys_read(fd, buf, count);
  782. }
  783. asmlinkage long sys32_write(unsigned int fd, char __user * buf, size_t count)
  784. {
  785. if ((compat_ssize_t) count < 0)
  786. return -EINVAL;
  787. return sys_write(fd, buf, count);
  788. }
  789. asmlinkage long sys32_clone(struct pt_regs regs)
  790. {
  791. unsigned long clone_flags;
  792. unsigned long newsp;
  793. int __user *parent_tidptr, *child_tidptr;
  794. clone_flags = regs.gprs[3] & 0xffffffffUL;
  795. newsp = regs.orig_gpr2 & 0x7fffffffUL;
  796. parent_tidptr = compat_ptr(regs.gprs[4]);
  797. child_tidptr = compat_ptr(regs.gprs[5]);
  798. if (!newsp)
  799. newsp = regs.gprs[15];
  800. return do_fork(clone_flags, newsp, &regs, 0,
  801. parent_tidptr, child_tidptr);
  802. }
  803. /*
  804. * 31 bit emulation wrapper functions for sys_fadvise64/fadvise64_64.
  805. * These need to rewrite the advise values for POSIX_FADV_{DONTNEED,NOREUSE}
  806. * because the 31 bit values differ from the 64 bit values.
  807. */
  808. asmlinkage long
  809. sys32_fadvise64(int fd, loff_t offset, size_t len, int advise)
  810. {
  811. if (advise == 4)
  812. advise = POSIX_FADV_DONTNEED;
  813. else if (advise == 5)
  814. advise = POSIX_FADV_NOREUSE;
  815. return sys_fadvise64(fd, offset, len, advise);
  816. }
  817. struct fadvise64_64_args {
  818. int fd;
  819. long long offset;
  820. long long len;
  821. int advice;
  822. };
  823. asmlinkage long
  824. sys32_fadvise64_64(struct fadvise64_64_args __user *args)
  825. {
  826. struct fadvise64_64_args a;
  827. if ( copy_from_user(&a, args, sizeof(a)) )
  828. return -EFAULT;
  829. if (a.advice == 4)
  830. a.advice = POSIX_FADV_DONTNEED;
  831. else if (a.advice == 5)
  832. a.advice = POSIX_FADV_NOREUSE;
  833. return sys_fadvise64_64(a.fd, a.offset, a.len, a.advice);
  834. }