compat.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  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 compat_convert_timespec(struct timespec __user **kts,
  180. const void __user *cts)
  181. {
  182. struct timespec ts;
  183. struct timespec __user *uts;
  184. if (!cts || COMPAT_USE_64BIT_TIME) {
  185. *kts = (struct timespec __user *)cts;
  186. return 0;
  187. }
  188. uts = compat_alloc_user_space(sizeof(ts));
  189. if (!uts)
  190. return -EFAULT;
  191. if (compat_get_timespec(&ts, cts))
  192. return -EFAULT;
  193. if (copy_to_user(uts, &ts, sizeof(ts)))
  194. return -EFAULT;
  195. *kts = uts;
  196. return 0;
  197. }
  198. int get_compat_itimerval(struct itimerval *o, const struct compat_itimerval __user *i)
  199. {
  200. struct compat_itimerval v32;
  201. if (copy_from_user(&v32, i, sizeof(struct compat_itimerval)))
  202. return -EFAULT;
  203. o->it_interval.tv_sec = v32.it_interval.tv_sec;
  204. o->it_interval.tv_usec = v32.it_interval.tv_usec;
  205. o->it_value.tv_sec = v32.it_value.tv_sec;
  206. o->it_value.tv_usec = v32.it_value.tv_usec;
  207. return 0;
  208. }
  209. int put_compat_itimerval(struct compat_itimerval __user *o, const struct itimerval *i)
  210. {
  211. struct compat_itimerval v32;
  212. v32.it_interval.tv_sec = i->it_interval.tv_sec;
  213. v32.it_interval.tv_usec = i->it_interval.tv_usec;
  214. v32.it_value.tv_sec = i->it_value.tv_sec;
  215. v32.it_value.tv_usec = i->it_value.tv_usec;
  216. return copy_to_user(o, &v32, sizeof(struct compat_itimerval)) ? -EFAULT : 0;
  217. }
  218. #ifdef __ARCH_WANT_SYS_SIGPROCMASK
  219. /*
  220. * sys_sigprocmask SIG_SETMASK sets the first (compat) word of the
  221. * blocked set of signals to the supplied signal set
  222. */
  223. static inline void compat_sig_setmask(sigset_t *blocked, compat_sigset_word set)
  224. {
  225. memcpy(blocked->sig, &set, sizeof(set));
  226. }
  227. COMPAT_SYSCALL_DEFINE3(sigprocmask, int, how,
  228. compat_old_sigset_t __user *, nset,
  229. compat_old_sigset_t __user *, oset)
  230. {
  231. old_sigset_t old_set, new_set;
  232. sigset_t new_blocked;
  233. old_set = current->blocked.sig[0];
  234. if (nset) {
  235. if (get_user(new_set, nset))
  236. return -EFAULT;
  237. new_set &= ~(sigmask(SIGKILL) | sigmask(SIGSTOP));
  238. new_blocked = current->blocked;
  239. switch (how) {
  240. case SIG_BLOCK:
  241. sigaddsetmask(&new_blocked, new_set);
  242. break;
  243. case SIG_UNBLOCK:
  244. sigdelsetmask(&new_blocked, new_set);
  245. break;
  246. case SIG_SETMASK:
  247. compat_sig_setmask(&new_blocked, new_set);
  248. break;
  249. default:
  250. return -EINVAL;
  251. }
  252. set_current_blocked(&new_blocked);
  253. }
  254. if (oset) {
  255. if (put_user(old_set, oset))
  256. return -EFAULT;
  257. }
  258. return 0;
  259. }
  260. #endif
  261. int put_compat_rusage(const struct rusage *r, struct compat_rusage __user *ru)
  262. {
  263. struct compat_rusage r32;
  264. memset(&r32, 0, sizeof(r32));
  265. r32.ru_utime.tv_sec = r->ru_utime.tv_sec;
  266. r32.ru_utime.tv_usec = r->ru_utime.tv_usec;
  267. r32.ru_stime.tv_sec = r->ru_stime.tv_sec;
  268. r32.ru_stime.tv_usec = r->ru_stime.tv_usec;
  269. r32.ru_maxrss = r->ru_maxrss;
  270. r32.ru_ixrss = r->ru_ixrss;
  271. r32.ru_idrss = r->ru_idrss;
  272. r32.ru_isrss = r->ru_isrss;
  273. r32.ru_minflt = r->ru_minflt;
  274. r32.ru_majflt = r->ru_majflt;
  275. r32.ru_nswap = r->ru_nswap;
  276. r32.ru_inblock = r->ru_inblock;
  277. r32.ru_oublock = r->ru_oublock;
  278. r32.ru_msgsnd = r->ru_msgsnd;
  279. r32.ru_msgrcv = r->ru_msgrcv;
  280. r32.ru_nsignals = r->ru_nsignals;
  281. r32.ru_nvcsw = r->ru_nvcsw;
  282. r32.ru_nivcsw = r->ru_nivcsw;
  283. if (copy_to_user(ru, &r32, sizeof(r32)))
  284. return -EFAULT;
  285. return 0;
  286. }
  287. static int compat_get_user_cpu_mask(compat_ulong_t __user *user_mask_ptr,
  288. unsigned len, struct cpumask *new_mask)
  289. {
  290. unsigned long *k;
  291. if (len < cpumask_size())
  292. memset(new_mask, 0, cpumask_size());
  293. else if (len > cpumask_size())
  294. len = cpumask_size();
  295. k = cpumask_bits(new_mask);
  296. return compat_get_bitmap(k, user_mask_ptr, len * 8);
  297. }
  298. COMPAT_SYSCALL_DEFINE3(sched_setaffinity, compat_pid_t, pid,
  299. unsigned int, len,
  300. compat_ulong_t __user *, user_mask_ptr)
  301. {
  302. cpumask_var_t new_mask;
  303. int retval;
  304. if (!alloc_cpumask_var(&new_mask, GFP_KERNEL))
  305. return -ENOMEM;
  306. retval = compat_get_user_cpu_mask(user_mask_ptr, len, new_mask);
  307. if (retval)
  308. goto out;
  309. retval = sched_setaffinity(pid, new_mask);
  310. out:
  311. free_cpumask_var(new_mask);
  312. return retval;
  313. }
  314. COMPAT_SYSCALL_DEFINE3(sched_getaffinity, compat_pid_t, pid, unsigned int, len,
  315. compat_ulong_t __user *, user_mask_ptr)
  316. {
  317. int ret;
  318. cpumask_var_t mask;
  319. if ((len * BITS_PER_BYTE) < nr_cpu_ids)
  320. return -EINVAL;
  321. if (len & (sizeof(compat_ulong_t)-1))
  322. return -EINVAL;
  323. if (!alloc_cpumask_var(&mask, GFP_KERNEL))
  324. return -ENOMEM;
  325. ret = sched_getaffinity(pid, mask);
  326. if (ret == 0) {
  327. size_t retlen = min_t(size_t, len, cpumask_size());
  328. if (compat_put_bitmap(user_mask_ptr, cpumask_bits(mask), retlen * 8))
  329. ret = -EFAULT;
  330. else
  331. ret = retlen;
  332. }
  333. free_cpumask_var(mask);
  334. return ret;
  335. }
  336. int get_compat_itimerspec(struct itimerspec *dst,
  337. const struct compat_itimerspec __user *src)
  338. {
  339. if (__compat_get_timespec(&dst->it_interval, &src->it_interval) ||
  340. __compat_get_timespec(&dst->it_value, &src->it_value))
  341. return -EFAULT;
  342. return 0;
  343. }
  344. int put_compat_itimerspec(struct compat_itimerspec __user *dst,
  345. const struct itimerspec *src)
  346. {
  347. if (__compat_put_timespec(&src->it_interval, &dst->it_interval) ||
  348. __compat_put_timespec(&src->it_value, &dst->it_value))
  349. return -EFAULT;
  350. return 0;
  351. }
  352. int get_compat_itimerspec64(struct itimerspec64 *its,
  353. const struct compat_itimerspec __user *uits)
  354. {
  355. if (__compat_get_timespec64(&its->it_interval, &uits->it_interval) ||
  356. __compat_get_timespec64(&its->it_value, &uits->it_value))
  357. return -EFAULT;
  358. return 0;
  359. }
  360. EXPORT_SYMBOL_GPL(get_compat_itimerspec64);
  361. int put_compat_itimerspec64(const struct itimerspec64 *its,
  362. struct compat_itimerspec __user *uits)
  363. {
  364. if (__compat_put_timespec64(&its->it_interval, &uits->it_interval) ||
  365. __compat_put_timespec64(&its->it_value, &uits->it_value))
  366. return -EFAULT;
  367. return 0;
  368. }
  369. EXPORT_SYMBOL_GPL(put_compat_itimerspec64);
  370. /*
  371. * We currently only need the following fields from the sigevent
  372. * structure: sigev_value, sigev_signo, sig_notify and (sometimes
  373. * sigev_notify_thread_id). The others are handled in user mode.
  374. * We also assume that copying sigev_value.sival_int is sufficient
  375. * to keep all the bits of sigev_value.sival_ptr intact.
  376. */
  377. int get_compat_sigevent(struct sigevent *event,
  378. const struct compat_sigevent __user *u_event)
  379. {
  380. memset(event, 0, sizeof(*event));
  381. return (!access_ok(VERIFY_READ, u_event, sizeof(*u_event)) ||
  382. __get_user(event->sigev_value.sival_int,
  383. &u_event->sigev_value.sival_int) ||
  384. __get_user(event->sigev_signo, &u_event->sigev_signo) ||
  385. __get_user(event->sigev_notify, &u_event->sigev_notify) ||
  386. __get_user(event->sigev_notify_thread_id,
  387. &u_event->sigev_notify_thread_id))
  388. ? -EFAULT : 0;
  389. }
  390. long compat_get_bitmap(unsigned long *mask, const compat_ulong_t __user *umask,
  391. unsigned long bitmap_size)
  392. {
  393. unsigned long nr_compat_longs;
  394. /* align bitmap up to nearest compat_long_t boundary */
  395. bitmap_size = ALIGN(bitmap_size, BITS_PER_COMPAT_LONG);
  396. nr_compat_longs = BITS_TO_COMPAT_LONGS(bitmap_size);
  397. if (!access_ok(VERIFY_READ, umask, bitmap_size / 8))
  398. return -EFAULT;
  399. user_access_begin();
  400. while (nr_compat_longs > 1) {
  401. compat_ulong_t l1, l2;
  402. unsafe_get_user(l1, umask++, Efault);
  403. unsafe_get_user(l2, umask++, Efault);
  404. *mask++ = ((unsigned long)l2 << BITS_PER_COMPAT_LONG) | l1;
  405. nr_compat_longs -= 2;
  406. }
  407. if (nr_compat_longs)
  408. unsafe_get_user(*mask, umask++, Efault);
  409. user_access_end();
  410. return 0;
  411. Efault:
  412. user_access_end();
  413. return -EFAULT;
  414. }
  415. long compat_put_bitmap(compat_ulong_t __user *umask, unsigned long *mask,
  416. unsigned long bitmap_size)
  417. {
  418. unsigned long nr_compat_longs;
  419. /* align bitmap up to nearest compat_long_t boundary */
  420. bitmap_size = ALIGN(bitmap_size, BITS_PER_COMPAT_LONG);
  421. nr_compat_longs = BITS_TO_COMPAT_LONGS(bitmap_size);
  422. if (!access_ok(VERIFY_WRITE, umask, bitmap_size / 8))
  423. return -EFAULT;
  424. user_access_begin();
  425. while (nr_compat_longs > 1) {
  426. unsigned long m = *mask++;
  427. unsafe_put_user((compat_ulong_t)m, umask++, Efault);
  428. unsafe_put_user(m >> BITS_PER_COMPAT_LONG, umask++, Efault);
  429. nr_compat_longs -= 2;
  430. }
  431. if (nr_compat_longs)
  432. unsafe_put_user((compat_ulong_t)*mask, umask++, Efault);
  433. user_access_end();
  434. return 0;
  435. Efault:
  436. user_access_end();
  437. return -EFAULT;
  438. }
  439. void
  440. sigset_from_compat(sigset_t *set, const compat_sigset_t *compat)
  441. {
  442. switch (_NSIG_WORDS) {
  443. case 4: set->sig[3] = compat->sig[6] | (((long)compat->sig[7]) << 32 );
  444. case 3: set->sig[2] = compat->sig[4] | (((long)compat->sig[5]) << 32 );
  445. case 2: set->sig[1] = compat->sig[2] | (((long)compat->sig[3]) << 32 );
  446. case 1: set->sig[0] = compat->sig[0] | (((long)compat->sig[1]) << 32 );
  447. }
  448. }
  449. EXPORT_SYMBOL_GPL(sigset_from_compat);
  450. void
  451. sigset_to_compat(compat_sigset_t *compat, const sigset_t *set)
  452. {
  453. switch (_NSIG_WORDS) {
  454. case 4: compat->sig[7] = (set->sig[3] >> 32); compat->sig[6] = set->sig[3];
  455. case 3: compat->sig[5] = (set->sig[2] >> 32); compat->sig[4] = set->sig[2];
  456. case 2: compat->sig[3] = (set->sig[1] >> 32); compat->sig[2] = set->sig[1];
  457. case 1: compat->sig[1] = (set->sig[0] >> 32); compat->sig[0] = set->sig[0];
  458. }
  459. }
  460. #ifdef CONFIG_NUMA
  461. COMPAT_SYSCALL_DEFINE6(move_pages, pid_t, pid, compat_ulong_t, nr_pages,
  462. compat_uptr_t __user *, pages32,
  463. const int __user *, nodes,
  464. int __user *, status,
  465. int, flags)
  466. {
  467. const void __user * __user *pages;
  468. int i;
  469. pages = compat_alloc_user_space(nr_pages * sizeof(void *));
  470. for (i = 0; i < nr_pages; i++) {
  471. compat_uptr_t p;
  472. if (get_user(p, pages32 + i) ||
  473. put_user(compat_ptr(p), pages + i))
  474. return -EFAULT;
  475. }
  476. return sys_move_pages(pid, nr_pages, pages, nodes, status, flags);
  477. }
  478. COMPAT_SYSCALL_DEFINE4(migrate_pages, compat_pid_t, pid,
  479. compat_ulong_t, maxnode,
  480. const compat_ulong_t __user *, old_nodes,
  481. const compat_ulong_t __user *, new_nodes)
  482. {
  483. unsigned long __user *old = NULL;
  484. unsigned long __user *new = NULL;
  485. nodemask_t tmp_mask;
  486. unsigned long nr_bits;
  487. unsigned long size;
  488. nr_bits = min_t(unsigned long, maxnode - 1, MAX_NUMNODES);
  489. size = ALIGN(nr_bits, BITS_PER_LONG) / 8;
  490. if (old_nodes) {
  491. if (compat_get_bitmap(nodes_addr(tmp_mask), old_nodes, nr_bits))
  492. return -EFAULT;
  493. old = compat_alloc_user_space(new_nodes ? size * 2 : size);
  494. if (new_nodes)
  495. new = old + size / sizeof(unsigned long);
  496. if (copy_to_user(old, nodes_addr(tmp_mask), size))
  497. return -EFAULT;
  498. }
  499. if (new_nodes) {
  500. if (compat_get_bitmap(nodes_addr(tmp_mask), new_nodes, nr_bits))
  501. return -EFAULT;
  502. if (new == NULL)
  503. new = compat_alloc_user_space(size);
  504. if (copy_to_user(new, nodes_addr(tmp_mask), size))
  505. return -EFAULT;
  506. }
  507. return sys_migrate_pages(pid, nr_bits + 1, old, new);
  508. }
  509. #endif
  510. COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
  511. compat_pid_t, pid,
  512. struct compat_timespec __user *, interval)
  513. {
  514. struct timespec t;
  515. int ret;
  516. mm_segment_t old_fs = get_fs();
  517. set_fs(KERNEL_DS);
  518. ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
  519. set_fs(old_fs);
  520. if (compat_put_timespec(&t, interval))
  521. return -EFAULT;
  522. return ret;
  523. }
  524. /*
  525. * Allocate user-space memory for the duration of a single system call,
  526. * in order to marshall parameters inside a compat thunk.
  527. */
  528. void __user *compat_alloc_user_space(unsigned long len)
  529. {
  530. void __user *ptr;
  531. /* If len would occupy more than half of the entire compat space... */
  532. if (unlikely(len > (((compat_uptr_t)~0) >> 1)))
  533. return NULL;
  534. ptr = arch_compat_alloc_user_space(len);
  535. if (unlikely(!access_ok(VERIFY_WRITE, ptr, len)))
  536. return NULL;
  537. return ptr;
  538. }
  539. EXPORT_SYMBOL_GPL(compat_alloc_user_space);