compat.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. /*
  2. * linux/kernel/compat.c
  3. *
  4. * Kernel compatibililty routines for e.g. 32 bit syscall support
  5. * on 64 bit kernels.
  6. *
  7. * Copyright (C) 2002-2003 Stephen Rothwell, IBM Corporation
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/linkage.h>
  14. #include <linux/compat.h>
  15. #include <linux/errno.h>
  16. #include <linux/time.h>
  17. #include <linux/signal.h>
  18. #include <linux/sched.h> /* for MAX_SCHEDULE_TIMEOUT */
  19. #include <linux/syscalls.h>
  20. #include <linux/unistd.h>
  21. #include <linux/security.h>
  22. #include <linux/timex.h>
  23. #include <linux/export.h>
  24. #include <linux/migrate.h>
  25. #include <linux/posix-timers.h>
  26. #include <linux/times.h>
  27. #include <linux/ptrace.h>
  28. #include <linux/gfp.h>
  29. #include <linux/uaccess.h>
  30. int compat_get_timex(struct timex *txc, const struct compat_timex __user *utp)
  31. {
  32. struct compat_timex tx32;
  33. if (copy_from_user(&tx32, utp, sizeof(struct compat_timex)))
  34. return -EFAULT;
  35. txc->modes = tx32.modes;
  36. txc->offset = tx32.offset;
  37. txc->freq = tx32.freq;
  38. txc->maxerror = tx32.maxerror;
  39. txc->esterror = tx32.esterror;
  40. txc->status = tx32.status;
  41. txc->constant = tx32.constant;
  42. txc->precision = tx32.precision;
  43. txc->tolerance = tx32.tolerance;
  44. txc->time.tv_sec = tx32.time.tv_sec;
  45. txc->time.tv_usec = tx32.time.tv_usec;
  46. txc->tick = tx32.tick;
  47. txc->ppsfreq = tx32.ppsfreq;
  48. txc->jitter = tx32.jitter;
  49. txc->shift = tx32.shift;
  50. txc->stabil = tx32.stabil;
  51. txc->jitcnt = tx32.jitcnt;
  52. txc->calcnt = tx32.calcnt;
  53. txc->errcnt = tx32.errcnt;
  54. txc->stbcnt = tx32.stbcnt;
  55. return 0;
  56. }
  57. int compat_put_timex(struct compat_timex __user *utp, const struct timex *txc)
  58. {
  59. struct compat_timex tx32;
  60. memset(&tx32, 0, sizeof(struct compat_timex));
  61. tx32.modes = txc->modes;
  62. tx32.offset = txc->offset;
  63. tx32.freq = txc->freq;
  64. tx32.maxerror = txc->maxerror;
  65. tx32.esterror = txc->esterror;
  66. tx32.status = txc->status;
  67. tx32.constant = txc->constant;
  68. tx32.precision = txc->precision;
  69. tx32.tolerance = txc->tolerance;
  70. tx32.time.tv_sec = txc->time.tv_sec;
  71. tx32.time.tv_usec = txc->time.tv_usec;
  72. tx32.tick = txc->tick;
  73. tx32.ppsfreq = txc->ppsfreq;
  74. tx32.jitter = txc->jitter;
  75. tx32.shift = txc->shift;
  76. tx32.stabil = txc->stabil;
  77. tx32.jitcnt = txc->jitcnt;
  78. tx32.calcnt = txc->calcnt;
  79. tx32.errcnt = txc->errcnt;
  80. tx32.stbcnt = txc->stbcnt;
  81. tx32.tai = txc->tai;
  82. if (copy_to_user(utp, &tx32, sizeof(struct compat_timex)))
  83. return -EFAULT;
  84. return 0;
  85. }
  86. static int __compat_get_timeval(struct timeval *tv, const struct compat_timeval __user *ctv)
  87. {
  88. return (!access_ok(VERIFY_READ, ctv, sizeof(*ctv)) ||
  89. __get_user(tv->tv_sec, &ctv->tv_sec) ||
  90. __get_user(tv->tv_usec, &ctv->tv_usec)) ? -EFAULT : 0;
  91. }
  92. static int __compat_put_timeval(const struct timeval *tv, struct compat_timeval __user *ctv)
  93. {
  94. return (!access_ok(VERIFY_WRITE, ctv, sizeof(*ctv)) ||
  95. __put_user(tv->tv_sec, &ctv->tv_sec) ||
  96. __put_user(tv->tv_usec, &ctv->tv_usec)) ? -EFAULT : 0;
  97. }
  98. static int __compat_get_timespec(struct timespec *ts, const struct compat_timespec __user *cts)
  99. {
  100. return (!access_ok(VERIFY_READ, cts, sizeof(*cts)) ||
  101. __get_user(ts->tv_sec, &cts->tv_sec) ||
  102. __get_user(ts->tv_nsec, &cts->tv_nsec)) ? -EFAULT : 0;
  103. }
  104. static int __compat_put_timespec(const struct timespec *ts, struct compat_timespec __user *cts)
  105. {
  106. return (!access_ok(VERIFY_WRITE, cts, sizeof(*cts)) ||
  107. __put_user(ts->tv_sec, &cts->tv_sec) ||
  108. __put_user(ts->tv_nsec, &cts->tv_nsec)) ? -EFAULT : 0;
  109. }
  110. static int __compat_get_timespec64(struct timespec64 *ts64,
  111. const struct compat_timespec __user *cts)
  112. {
  113. struct compat_timespec ts;
  114. int ret;
  115. ret = copy_from_user(&ts, cts, sizeof(ts));
  116. if (ret)
  117. return -EFAULT;
  118. ts64->tv_sec = ts.tv_sec;
  119. ts64->tv_nsec = ts.tv_nsec;
  120. return 0;
  121. }
  122. static int __compat_put_timespec64(const struct timespec64 *ts64,
  123. struct compat_timespec __user *cts)
  124. {
  125. struct compat_timespec ts = {
  126. .tv_sec = ts64->tv_sec,
  127. .tv_nsec = ts64->tv_nsec
  128. };
  129. return copy_to_user(cts, &ts, sizeof(ts)) ? -EFAULT : 0;
  130. }
  131. int compat_get_timespec64(struct timespec64 *ts, const void __user *uts)
  132. {
  133. if (COMPAT_USE_64BIT_TIME)
  134. return copy_from_user(ts, uts, sizeof(*ts)) ? -EFAULT : 0;
  135. else
  136. return __compat_get_timespec64(ts, uts);
  137. }
  138. EXPORT_SYMBOL_GPL(compat_get_timespec64);
  139. int compat_put_timespec64(const struct timespec64 *ts, void __user *uts)
  140. {
  141. if (COMPAT_USE_64BIT_TIME)
  142. return copy_to_user(uts, ts, sizeof(*ts)) ? -EFAULT : 0;
  143. else
  144. return __compat_put_timespec64(ts, uts);
  145. }
  146. EXPORT_SYMBOL_GPL(compat_put_timespec64);
  147. int compat_get_timeval(struct timeval *tv, const void __user *utv)
  148. {
  149. if (COMPAT_USE_64BIT_TIME)
  150. return copy_from_user(tv, utv, sizeof(*tv)) ? -EFAULT : 0;
  151. else
  152. return __compat_get_timeval(tv, utv);
  153. }
  154. EXPORT_SYMBOL_GPL(compat_get_timeval);
  155. int compat_put_timeval(const struct timeval *tv, void __user *utv)
  156. {
  157. if (COMPAT_USE_64BIT_TIME)
  158. return copy_to_user(utv, tv, sizeof(*tv)) ? -EFAULT : 0;
  159. else
  160. return __compat_put_timeval(tv, utv);
  161. }
  162. EXPORT_SYMBOL_GPL(compat_put_timeval);
  163. int compat_get_timespec(struct timespec *ts, const void __user *uts)
  164. {
  165. if (COMPAT_USE_64BIT_TIME)
  166. return copy_from_user(ts, uts, sizeof(*ts)) ? -EFAULT : 0;
  167. else
  168. return __compat_get_timespec(ts, uts);
  169. }
  170. EXPORT_SYMBOL_GPL(compat_get_timespec);
  171. int compat_put_timespec(const struct timespec *ts, void __user *uts)
  172. {
  173. if (COMPAT_USE_64BIT_TIME)
  174. return copy_to_user(uts, ts, sizeof(*ts)) ? -EFAULT : 0;
  175. else
  176. return __compat_put_timespec(ts, uts);
  177. }
  178. EXPORT_SYMBOL_GPL(compat_put_timespec);
  179. int get_compat_itimerval(struct itimerval *o, const struct compat_itimerval __user *i)
  180. {
  181. struct compat_itimerval v32;
  182. if (copy_from_user(&v32, i, sizeof(struct compat_itimerval)))
  183. return -EFAULT;
  184. o->it_interval.tv_sec = v32.it_interval.tv_sec;
  185. o->it_interval.tv_usec = v32.it_interval.tv_usec;
  186. o->it_value.tv_sec = v32.it_value.tv_sec;
  187. o->it_value.tv_usec = v32.it_value.tv_usec;
  188. return 0;
  189. }
  190. int put_compat_itimerval(struct compat_itimerval __user *o, const struct itimerval *i)
  191. {
  192. struct compat_itimerval v32;
  193. v32.it_interval.tv_sec = i->it_interval.tv_sec;
  194. v32.it_interval.tv_usec = i->it_interval.tv_usec;
  195. v32.it_value.tv_sec = i->it_value.tv_sec;
  196. v32.it_value.tv_usec = i->it_value.tv_usec;
  197. return copy_to_user(o, &v32, sizeof(struct compat_itimerval)) ? -EFAULT : 0;
  198. }
  199. #ifdef __ARCH_WANT_SYS_SIGPROCMASK
  200. /*
  201. * sys_sigprocmask SIG_SETMASK sets the first (compat) word of the
  202. * blocked set of signals to the supplied signal set
  203. */
  204. static inline void compat_sig_setmask(sigset_t *blocked, compat_sigset_word set)
  205. {
  206. memcpy(blocked->sig, &set, sizeof(set));
  207. }
  208. COMPAT_SYSCALL_DEFINE3(sigprocmask, int, how,
  209. compat_old_sigset_t __user *, nset,
  210. compat_old_sigset_t __user *, oset)
  211. {
  212. old_sigset_t old_set, new_set;
  213. sigset_t new_blocked;
  214. old_set = current->blocked.sig[0];
  215. if (nset) {
  216. if (get_user(new_set, nset))
  217. return -EFAULT;
  218. new_set &= ~(sigmask(SIGKILL) | sigmask(SIGSTOP));
  219. new_blocked = current->blocked;
  220. switch (how) {
  221. case SIG_BLOCK:
  222. sigaddsetmask(&new_blocked, new_set);
  223. break;
  224. case SIG_UNBLOCK:
  225. sigdelsetmask(&new_blocked, new_set);
  226. break;
  227. case SIG_SETMASK:
  228. compat_sig_setmask(&new_blocked, new_set);
  229. break;
  230. default:
  231. return -EINVAL;
  232. }
  233. set_current_blocked(&new_blocked);
  234. }
  235. if (oset) {
  236. if (put_user(old_set, oset))
  237. return -EFAULT;
  238. }
  239. return 0;
  240. }
  241. #endif
  242. int put_compat_rusage(const struct rusage *r, struct compat_rusage __user *ru)
  243. {
  244. struct compat_rusage r32;
  245. memset(&r32, 0, sizeof(r32));
  246. r32.ru_utime.tv_sec = r->ru_utime.tv_sec;
  247. r32.ru_utime.tv_usec = r->ru_utime.tv_usec;
  248. r32.ru_stime.tv_sec = r->ru_stime.tv_sec;
  249. r32.ru_stime.tv_usec = r->ru_stime.tv_usec;
  250. r32.ru_maxrss = r->ru_maxrss;
  251. r32.ru_ixrss = r->ru_ixrss;
  252. r32.ru_idrss = r->ru_idrss;
  253. r32.ru_isrss = r->ru_isrss;
  254. r32.ru_minflt = r->ru_minflt;
  255. r32.ru_majflt = r->ru_majflt;
  256. r32.ru_nswap = r->ru_nswap;
  257. r32.ru_inblock = r->ru_inblock;
  258. r32.ru_oublock = r->ru_oublock;
  259. r32.ru_msgsnd = r->ru_msgsnd;
  260. r32.ru_msgrcv = r->ru_msgrcv;
  261. r32.ru_nsignals = r->ru_nsignals;
  262. r32.ru_nvcsw = r->ru_nvcsw;
  263. r32.ru_nivcsw = r->ru_nivcsw;
  264. if (copy_to_user(ru, &r32, sizeof(r32)))
  265. return -EFAULT;
  266. return 0;
  267. }
  268. static int compat_get_user_cpu_mask(compat_ulong_t __user *user_mask_ptr,
  269. unsigned len, struct cpumask *new_mask)
  270. {
  271. unsigned long *k;
  272. if (len < cpumask_size())
  273. memset(new_mask, 0, cpumask_size());
  274. else if (len > cpumask_size())
  275. len = cpumask_size();
  276. k = cpumask_bits(new_mask);
  277. return compat_get_bitmap(k, user_mask_ptr, len * 8);
  278. }
  279. COMPAT_SYSCALL_DEFINE3(sched_setaffinity, compat_pid_t, pid,
  280. unsigned int, len,
  281. compat_ulong_t __user *, user_mask_ptr)
  282. {
  283. cpumask_var_t new_mask;
  284. int retval;
  285. if (!alloc_cpumask_var(&new_mask, GFP_KERNEL))
  286. return -ENOMEM;
  287. retval = compat_get_user_cpu_mask(user_mask_ptr, len, new_mask);
  288. if (retval)
  289. goto out;
  290. retval = sched_setaffinity(pid, new_mask);
  291. out:
  292. free_cpumask_var(new_mask);
  293. return retval;
  294. }
  295. COMPAT_SYSCALL_DEFINE3(sched_getaffinity, compat_pid_t, pid, unsigned int, len,
  296. compat_ulong_t __user *, user_mask_ptr)
  297. {
  298. int ret;
  299. cpumask_var_t mask;
  300. if ((len * BITS_PER_BYTE) < nr_cpu_ids)
  301. return -EINVAL;
  302. if (len & (sizeof(compat_ulong_t)-1))
  303. return -EINVAL;
  304. if (!alloc_cpumask_var(&mask, GFP_KERNEL))
  305. return -ENOMEM;
  306. ret = sched_getaffinity(pid, mask);
  307. if (ret == 0) {
  308. size_t retlen = min_t(size_t, len, cpumask_size());
  309. if (compat_put_bitmap(user_mask_ptr, cpumask_bits(mask), retlen * 8))
  310. ret = -EFAULT;
  311. else
  312. ret = retlen;
  313. }
  314. free_cpumask_var(mask);
  315. return ret;
  316. }
  317. int get_compat_itimerspec(struct itimerspec *dst,
  318. const struct compat_itimerspec __user *src)
  319. {
  320. if (__compat_get_timespec(&dst->it_interval, &src->it_interval) ||
  321. __compat_get_timespec(&dst->it_value, &src->it_value))
  322. return -EFAULT;
  323. return 0;
  324. }
  325. int put_compat_itimerspec(struct compat_itimerspec __user *dst,
  326. const struct itimerspec *src)
  327. {
  328. if (__compat_put_timespec(&src->it_interval, &dst->it_interval) ||
  329. __compat_put_timespec(&src->it_value, &dst->it_value))
  330. return -EFAULT;
  331. return 0;
  332. }
  333. int get_compat_itimerspec64(struct itimerspec64 *its,
  334. const struct compat_itimerspec __user *uits)
  335. {
  336. if (__compat_get_timespec64(&its->it_interval, &uits->it_interval) ||
  337. __compat_get_timespec64(&its->it_value, &uits->it_value))
  338. return -EFAULT;
  339. return 0;
  340. }
  341. EXPORT_SYMBOL_GPL(get_compat_itimerspec64);
  342. int put_compat_itimerspec64(const struct itimerspec64 *its,
  343. struct compat_itimerspec __user *uits)
  344. {
  345. if (__compat_put_timespec64(&its->it_interval, &uits->it_interval) ||
  346. __compat_put_timespec64(&its->it_value, &uits->it_value))
  347. return -EFAULT;
  348. return 0;
  349. }
  350. EXPORT_SYMBOL_GPL(put_compat_itimerspec64);
  351. /*
  352. * We currently only need the following fields from the sigevent
  353. * structure: sigev_value, sigev_signo, sig_notify and (sometimes
  354. * sigev_notify_thread_id). The others are handled in user mode.
  355. * We also assume that copying sigev_value.sival_int is sufficient
  356. * to keep all the bits of sigev_value.sival_ptr intact.
  357. */
  358. int get_compat_sigevent(struct sigevent *event,
  359. const struct compat_sigevent __user *u_event)
  360. {
  361. memset(event, 0, sizeof(*event));
  362. return (!access_ok(VERIFY_READ, u_event, sizeof(*u_event)) ||
  363. __get_user(event->sigev_value.sival_int,
  364. &u_event->sigev_value.sival_int) ||
  365. __get_user(event->sigev_signo, &u_event->sigev_signo) ||
  366. __get_user(event->sigev_notify, &u_event->sigev_notify) ||
  367. __get_user(event->sigev_notify_thread_id,
  368. &u_event->sigev_notify_thread_id))
  369. ? -EFAULT : 0;
  370. }
  371. long compat_get_bitmap(unsigned long *mask, const compat_ulong_t __user *umask,
  372. unsigned long bitmap_size)
  373. {
  374. unsigned long nr_compat_longs;
  375. /* align bitmap up to nearest compat_long_t boundary */
  376. bitmap_size = ALIGN(bitmap_size, BITS_PER_COMPAT_LONG);
  377. nr_compat_longs = BITS_TO_COMPAT_LONGS(bitmap_size);
  378. if (!access_ok(VERIFY_READ, umask, bitmap_size / 8))
  379. return -EFAULT;
  380. user_access_begin();
  381. while (nr_compat_longs > 1) {
  382. compat_ulong_t l1, l2;
  383. unsafe_get_user(l1, umask++, Efault);
  384. unsafe_get_user(l2, umask++, Efault);
  385. *mask++ = ((unsigned long)l2 << BITS_PER_COMPAT_LONG) | l1;
  386. nr_compat_longs -= 2;
  387. }
  388. if (nr_compat_longs)
  389. unsafe_get_user(*mask, umask++, Efault);
  390. user_access_end();
  391. return 0;
  392. Efault:
  393. user_access_end();
  394. return -EFAULT;
  395. }
  396. long compat_put_bitmap(compat_ulong_t __user *umask, unsigned long *mask,
  397. unsigned long bitmap_size)
  398. {
  399. unsigned long nr_compat_longs;
  400. /* align bitmap up to nearest compat_long_t boundary */
  401. bitmap_size = ALIGN(bitmap_size, BITS_PER_COMPAT_LONG);
  402. nr_compat_longs = BITS_TO_COMPAT_LONGS(bitmap_size);
  403. if (!access_ok(VERIFY_WRITE, umask, bitmap_size / 8))
  404. return -EFAULT;
  405. user_access_begin();
  406. while (nr_compat_longs > 1) {
  407. unsigned long m = *mask++;
  408. unsafe_put_user((compat_ulong_t)m, umask++, Efault);
  409. unsafe_put_user(m >> BITS_PER_COMPAT_LONG, umask++, Efault);
  410. nr_compat_longs -= 2;
  411. }
  412. if (nr_compat_longs)
  413. unsafe_put_user((compat_ulong_t)*mask, umask++, Efault);
  414. user_access_end();
  415. return 0;
  416. Efault:
  417. user_access_end();
  418. return -EFAULT;
  419. }
  420. void
  421. sigset_from_compat(sigset_t *set, const compat_sigset_t *compat)
  422. {
  423. switch (_NSIG_WORDS) {
  424. case 4: set->sig[3] = compat->sig[6] | (((long)compat->sig[7]) << 32 );
  425. case 3: set->sig[2] = compat->sig[4] | (((long)compat->sig[5]) << 32 );
  426. case 2: set->sig[1] = compat->sig[2] | (((long)compat->sig[3]) << 32 );
  427. case 1: set->sig[0] = compat->sig[0] | (((long)compat->sig[1]) << 32 );
  428. }
  429. }
  430. EXPORT_SYMBOL_GPL(sigset_from_compat);
  431. void
  432. sigset_to_compat(compat_sigset_t *compat, const sigset_t *set)
  433. {
  434. switch (_NSIG_WORDS) {
  435. case 4: compat->sig[7] = (set->sig[3] >> 32); compat->sig[6] = set->sig[3];
  436. case 3: compat->sig[5] = (set->sig[2] >> 32); compat->sig[4] = set->sig[2];
  437. case 2: compat->sig[3] = (set->sig[1] >> 32); compat->sig[2] = set->sig[1];
  438. case 1: compat->sig[1] = (set->sig[0] >> 32); compat->sig[0] = set->sig[0];
  439. }
  440. }
  441. #ifdef CONFIG_NUMA
  442. COMPAT_SYSCALL_DEFINE6(move_pages, pid_t, pid, compat_ulong_t, nr_pages,
  443. compat_uptr_t __user *, pages32,
  444. const int __user *, nodes,
  445. int __user *, status,
  446. int, flags)
  447. {
  448. const void __user * __user *pages;
  449. int i;
  450. pages = compat_alloc_user_space(nr_pages * sizeof(void *));
  451. for (i = 0; i < nr_pages; i++) {
  452. compat_uptr_t p;
  453. if (get_user(p, pages32 + i) ||
  454. put_user(compat_ptr(p), pages + i))
  455. return -EFAULT;
  456. }
  457. return sys_move_pages(pid, nr_pages, pages, nodes, status, flags);
  458. }
  459. COMPAT_SYSCALL_DEFINE4(migrate_pages, compat_pid_t, pid,
  460. compat_ulong_t, maxnode,
  461. const compat_ulong_t __user *, old_nodes,
  462. const compat_ulong_t __user *, new_nodes)
  463. {
  464. unsigned long __user *old = NULL;
  465. unsigned long __user *new = NULL;
  466. nodemask_t tmp_mask;
  467. unsigned long nr_bits;
  468. unsigned long size;
  469. nr_bits = min_t(unsigned long, maxnode - 1, MAX_NUMNODES);
  470. size = ALIGN(nr_bits, BITS_PER_LONG) / 8;
  471. if (old_nodes) {
  472. if (compat_get_bitmap(nodes_addr(tmp_mask), old_nodes, nr_bits))
  473. return -EFAULT;
  474. old = compat_alloc_user_space(new_nodes ? size * 2 : size);
  475. if (new_nodes)
  476. new = old + size / sizeof(unsigned long);
  477. if (copy_to_user(old, nodes_addr(tmp_mask), size))
  478. return -EFAULT;
  479. }
  480. if (new_nodes) {
  481. if (compat_get_bitmap(nodes_addr(tmp_mask), new_nodes, nr_bits))
  482. return -EFAULT;
  483. if (new == NULL)
  484. new = compat_alloc_user_space(size);
  485. if (copy_to_user(new, nodes_addr(tmp_mask), size))
  486. return -EFAULT;
  487. }
  488. return sys_migrate_pages(pid, nr_bits + 1, old, new);
  489. }
  490. #endif
  491. COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
  492. compat_pid_t, pid,
  493. struct compat_timespec __user *, interval)
  494. {
  495. struct timespec t;
  496. int ret;
  497. mm_segment_t old_fs = get_fs();
  498. set_fs(KERNEL_DS);
  499. ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
  500. set_fs(old_fs);
  501. if (compat_put_timespec(&t, interval))
  502. return -EFAULT;
  503. return ret;
  504. }
  505. /*
  506. * Allocate user-space memory for the duration of a single system call,
  507. * in order to marshall parameters inside a compat thunk.
  508. */
  509. void __user *compat_alloc_user_space(unsigned long len)
  510. {
  511. void __user *ptr;
  512. /* If len would occupy more than half of the entire compat space... */
  513. if (unlikely(len > (((compat_uptr_t)~0) >> 1)))
  514. return NULL;
  515. ptr = arch_compat_alloc_user_space(len);
  516. if (unlikely(!access_ok(VERIFY_WRITE, ptr, len)))
  517. return NULL;
  518. return ptr;
  519. }
  520. EXPORT_SYMBOL_GPL(compat_alloc_user_space);