blob: c349417d2c40e07850cc45d4d8148818b11ec2d8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
14#include <linux/linkage.h>
15#include <linux/compat.h>
16#include <linux/errno.h>
17#include <linux/time.h>
18#include <linux/signal.h>
19#include <linux/sched.h> /* for MAX_SCHEDULE_TIMEOUT */
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/syscalls.h>
21#include <linux/unistd.h>
22#include <linux/security.h>
Stephen Rothwell3158e942006-03-26 01:37:29 -080023#include <linux/timex.h>
Paul Gortmaker6e5fdee2011-05-26 16:00:52 -040024#include <linux/export.h>
Christoph Lameter1b2db9f2006-06-23 02:03:56 -070025#include <linux/migrate.h>
Toyo Abe1711ef32006-09-29 02:00:28 -070026#include <linux/posix-timers.h>
Frank Mayharf06febc2008-09-12 09:54:39 -070027#include <linux/times.h>
Paul Mackerrase3d5a272009-01-06 14:41:02 -080028#include <linux/ptrace.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080031#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Al Viro3a4d44b2017-06-07 09:42:34 +010033int compat_get_timex(struct timex *txc, const struct compat_timex __user *utp)
Richard Cochran65f5d802011-02-01 13:52:23 +000034{
Al Viro3a4d44b2017-06-07 09:42:34 +010035 struct compat_timex tx32;
Richard Cochran65f5d802011-02-01 13:52:23 +000036
Al Viro3a4d44b2017-06-07 09:42:34 +010037 if (copy_from_user(&tx32, utp, sizeof(struct compat_timex)))
Richard Cochran65f5d802011-02-01 13:52:23 +000038 return -EFAULT;
39
Al Viro3a4d44b2017-06-07 09:42:34 +010040 txc->modes = tx32.modes;
41 txc->offset = tx32.offset;
42 txc->freq = tx32.freq;
43 txc->maxerror = tx32.maxerror;
44 txc->esterror = tx32.esterror;
45 txc->status = tx32.status;
46 txc->constant = tx32.constant;
47 txc->precision = tx32.precision;
48 txc->tolerance = tx32.tolerance;
49 txc->time.tv_sec = tx32.time.tv_sec;
50 txc->time.tv_usec = tx32.time.tv_usec;
51 txc->tick = tx32.tick;
52 txc->ppsfreq = tx32.ppsfreq;
53 txc->jitter = tx32.jitter;
54 txc->shift = tx32.shift;
55 txc->stabil = tx32.stabil;
56 txc->jitcnt = tx32.jitcnt;
57 txc->calcnt = tx32.calcnt;
58 txc->errcnt = tx32.errcnt;
59 txc->stbcnt = tx32.stbcnt;
60
Richard Cochran65f5d802011-02-01 13:52:23 +000061 return 0;
62}
63
Al Viro3a4d44b2017-06-07 09:42:34 +010064int compat_put_timex(struct compat_timex __user *utp, const struct timex *txc)
Richard Cochran65f5d802011-02-01 13:52:23 +000065{
Al Viro3a4d44b2017-06-07 09:42:34 +010066 struct compat_timex tx32;
67
68 memset(&tx32, 0, sizeof(struct compat_timex));
69 tx32.modes = txc->modes;
70 tx32.offset = txc->offset;
71 tx32.freq = txc->freq;
72 tx32.maxerror = txc->maxerror;
73 tx32.esterror = txc->esterror;
74 tx32.status = txc->status;
75 tx32.constant = txc->constant;
76 tx32.precision = txc->precision;
77 tx32.tolerance = txc->tolerance;
78 tx32.time.tv_sec = txc->time.tv_sec;
79 tx32.time.tv_usec = txc->time.tv_usec;
80 tx32.tick = txc->tick;
81 tx32.ppsfreq = txc->ppsfreq;
82 tx32.jitter = txc->jitter;
83 tx32.shift = txc->shift;
84 tx32.stabil = txc->stabil;
85 tx32.jitcnt = txc->jitcnt;
86 tx32.calcnt = txc->calcnt;
87 tx32.errcnt = txc->errcnt;
88 tx32.stbcnt = txc->stbcnt;
89 tx32.tai = txc->tai;
90 if (copy_to_user(utp, &tx32, sizeof(struct compat_timex)))
Richard Cochran65f5d802011-02-01 13:52:23 +000091 return -EFAULT;
92 return 0;
93}
94
Heiko Carstens62a6fa92014-03-03 16:11:13 +010095COMPAT_SYSCALL_DEFINE2(gettimeofday, struct compat_timeval __user *, tv,
96 struct timezone __user *, tz)
Christoph Hellwigb418da12008-10-15 22:02:06 -070097{
98 if (tv) {
99 struct timeval ktv;
100 do_gettimeofday(&ktv);
H. Peter Anvin81993e82014-02-01 18:54:11 -0800101 if (compat_put_timeval(&ktv, tv))
Christoph Hellwigb418da12008-10-15 22:02:06 -0700102 return -EFAULT;
103 }
104 if (tz) {
105 if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
106 return -EFAULT;
107 }
108
109 return 0;
110}
111
Heiko Carstens62a6fa92014-03-03 16:11:13 +0100112COMPAT_SYSCALL_DEFINE2(settimeofday, struct compat_timeval __user *, tv,
113 struct timezone __user *, tz)
Christoph Hellwigb418da12008-10-15 22:02:06 -0700114{
Deepa Dinamani2ac00f12017-03-26 12:04:12 -0700115 struct timespec64 new_ts;
H. Peter Anvin81993e82014-02-01 18:54:11 -0800116 struct timeval user_tv;
H. Peter Anvin81993e82014-02-01 18:54:11 -0800117 struct timezone new_tz;
Christoph Hellwigb418da12008-10-15 22:02:06 -0700118
119 if (tv) {
H. Peter Anvin81993e82014-02-01 18:54:11 -0800120 if (compat_get_timeval(&user_tv, tv))
Christoph Hellwigb418da12008-10-15 22:02:06 -0700121 return -EFAULT;
H. Peter Anvin81993e82014-02-01 18:54:11 -0800122 new_ts.tv_sec = user_tv.tv_sec;
123 new_ts.tv_nsec = user_tv.tv_usec * NSEC_PER_USEC;
Christoph Hellwigb418da12008-10-15 22:02:06 -0700124 }
125 if (tz) {
H. Peter Anvin81993e82014-02-01 18:54:11 -0800126 if (copy_from_user(&new_tz, tz, sizeof(*tz)))
Christoph Hellwigb418da12008-10-15 22:02:06 -0700127 return -EFAULT;
128 }
129
Deepa Dinamani2ac00f12017-03-26 12:04:12 -0700130 return do_sys_settimeofday64(tv ? &new_ts : NULL, tz ? &new_tz : NULL);
Christoph Hellwigb418da12008-10-15 22:02:06 -0700131}
132
H. Peter Anvin81993e82014-02-01 18:54:11 -0800133static int __compat_get_timeval(struct timeval *tv, const struct compat_timeval __user *ctv)
H. Peter Anvin6684ba22012-02-19 17:38:00 -0800134{
135 return (!access_ok(VERIFY_READ, ctv, sizeof(*ctv)) ||
136 __get_user(tv->tv_sec, &ctv->tv_sec) ||
137 __get_user(tv->tv_usec, &ctv->tv_usec)) ? -EFAULT : 0;
138}
H. Peter Anvin6684ba22012-02-19 17:38:00 -0800139
H. Peter Anvin81993e82014-02-01 18:54:11 -0800140static int __compat_put_timeval(const struct timeval *tv, struct compat_timeval __user *ctv)
H. Peter Anvin6684ba22012-02-19 17:38:00 -0800141{
142 return (!access_ok(VERIFY_WRITE, ctv, sizeof(*ctv)) ||
143 __put_user(tv->tv_sec, &ctv->tv_sec) ||
144 __put_user(tv->tv_usec, &ctv->tv_usec)) ? -EFAULT : 0;
145}
H. Peter Anvin6684ba22012-02-19 17:38:00 -0800146
H. Peter Anvin81993e82014-02-01 18:54:11 -0800147static int __compat_get_timespec(struct timespec *ts, const struct compat_timespec __user *cts)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148{
149 return (!access_ok(VERIFY_READ, cts, sizeof(*cts)) ||
150 __get_user(ts->tv_sec, &cts->tv_sec) ||
151 __get_user(ts->tv_nsec, &cts->tv_nsec)) ? -EFAULT : 0;
152}
153
H. Peter Anvin81993e82014-02-01 18:54:11 -0800154static int __compat_put_timespec(const struct timespec *ts, struct compat_timespec __user *cts)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155{
156 return (!access_ok(VERIFY_WRITE, cts, sizeof(*cts)) ||
157 __put_user(ts->tv_sec, &cts->tv_sec) ||
158 __put_user(ts->tv_nsec, &cts->tv_nsec)) ? -EFAULT : 0;
159}
160
H. Peter Anvin6684ba22012-02-19 17:38:00 -0800161int compat_get_timeval(struct timeval *tv, const void __user *utv)
162{
163 if (COMPAT_USE_64BIT_TIME)
Fabian Frederick6516a462014-06-04 16:12:02 -0700164 return copy_from_user(tv, utv, sizeof(*tv)) ? -EFAULT : 0;
H. Peter Anvin6684ba22012-02-19 17:38:00 -0800165 else
H. Peter Anvin81993e82014-02-01 18:54:11 -0800166 return __compat_get_timeval(tv, utv);
H. Peter Anvin6684ba22012-02-19 17:38:00 -0800167}
168EXPORT_SYMBOL_GPL(compat_get_timeval);
169
170int compat_put_timeval(const struct timeval *tv, void __user *utv)
171{
172 if (COMPAT_USE_64BIT_TIME)
Fabian Frederick6516a462014-06-04 16:12:02 -0700173 return copy_to_user(utv, tv, sizeof(*tv)) ? -EFAULT : 0;
H. Peter Anvin6684ba22012-02-19 17:38:00 -0800174 else
H. Peter Anvin81993e82014-02-01 18:54:11 -0800175 return __compat_put_timeval(tv, utv);
H. Peter Anvin6684ba22012-02-19 17:38:00 -0800176}
177EXPORT_SYMBOL_GPL(compat_put_timeval);
178
179int compat_get_timespec(struct timespec *ts, const void __user *uts)
180{
181 if (COMPAT_USE_64BIT_TIME)
Fabian Frederick6516a462014-06-04 16:12:02 -0700182 return copy_from_user(ts, uts, sizeof(*ts)) ? -EFAULT : 0;
H. Peter Anvin6684ba22012-02-19 17:38:00 -0800183 else
H. Peter Anvin81993e82014-02-01 18:54:11 -0800184 return __compat_get_timespec(ts, uts);
H. Peter Anvin6684ba22012-02-19 17:38:00 -0800185}
186EXPORT_SYMBOL_GPL(compat_get_timespec);
187
188int compat_put_timespec(const struct timespec *ts, void __user *uts)
189{
190 if (COMPAT_USE_64BIT_TIME)
Fabian Frederick6516a462014-06-04 16:12:02 -0700191 return copy_to_user(uts, ts, sizeof(*ts)) ? -EFAULT : 0;
H. Peter Anvin6684ba22012-02-19 17:38:00 -0800192 else
H. Peter Anvin81993e82014-02-01 18:54:11 -0800193 return __compat_put_timespec(ts, uts);
H. Peter Anvin6684ba22012-02-19 17:38:00 -0800194}
195EXPORT_SYMBOL_GPL(compat_put_timespec);
196
H. Peter Anvin81993e82014-02-01 18:54:11 -0800197int compat_convert_timespec(struct timespec __user **kts,
198 const void __user *cts)
199{
200 struct timespec ts;
201 struct timespec __user *uts;
202
203 if (!cts || COMPAT_USE_64BIT_TIME) {
204 *kts = (struct timespec __user *)cts;
205 return 0;
206 }
207
208 uts = compat_alloc_user_space(sizeof(ts));
209 if (!uts)
210 return -EFAULT;
211 if (compat_get_timespec(&ts, cts))
212 return -EFAULT;
213 if (copy_to_user(uts, &ts, sizeof(ts)))
214 return -EFAULT;
215
216 *kts = uts;
217 return 0;
218}
219
Al Viro54ad9c42017-06-07 09:42:37 +0100220int get_compat_itimerval(struct itimerval *o, const struct compat_itimerval __user *i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221{
Al Viro54ad9c42017-06-07 09:42:37 +0100222 struct compat_itimerval v32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
Al Viro54ad9c42017-06-07 09:42:37 +0100224 if (copy_from_user(&v32, i, sizeof(struct compat_itimerval)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 return -EFAULT;
Al Viro54ad9c42017-06-07 09:42:37 +0100226 o->it_interval.tv_sec = v32.it_interval.tv_sec;
227 o->it_interval.tv_usec = v32.it_interval.tv_usec;
228 o->it_value.tv_sec = v32.it_value.tv_sec;
229 o->it_value.tv_usec = v32.it_value.tv_usec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 return 0;
231}
232
Al Viro54ad9c42017-06-07 09:42:37 +0100233int put_compat_itimerval(struct compat_itimerval __user *o, const struct itimerval *i)
234{
235 struct compat_itimerval v32;
236
237 v32.it_interval.tv_sec = i->it_interval.tv_sec;
238 v32.it_interval.tv_usec = i->it_interval.tv_usec;
239 v32.it_value.tv_sec = i->it_value.tv_sec;
240 v32.it_value.tv_usec = i->it_value.tv_usec;
241 return copy_to_user(o, &v32, sizeof(struct compat_itimerval)) ? -EFAULT : 0;
242}
243
Frank Mayharf06febc2008-09-12 09:54:39 -0700244static compat_clock_t clock_t_to_compat_clock_t(clock_t x)
245{
246 return compat_jiffies_to_clock_t(clock_t_to_jiffies(x));
247}
248
Heiko Carstens62a6fa92014-03-03 16:11:13 +0100249COMPAT_SYSCALL_DEFINE1(times, struct compat_tms __user *, tbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 if (tbuf) {
Frank Mayharf06febc2008-09-12 09:54:39 -0700252 struct tms tms;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 struct compat_tms tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
Frank Mayharf06febc2008-09-12 09:54:39 -0700255 do_sys_times(&tms);
256 /* Convert our struct tms to the compat version. */
257 tmp.tms_utime = clock_t_to_compat_clock_t(tms.tms_utime);
258 tmp.tms_stime = clock_t_to_compat_clock_t(tms.tms_stime);
259 tmp.tms_cutime = clock_t_to_compat_clock_t(tms.tms_cutime);
260 tmp.tms_cstime = clock_t_to_compat_clock_t(tms.tms_cstime);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 if (copy_to_user(tbuf, &tmp, sizeof(tmp)))
262 return -EFAULT;
263 }
Paul Mackerrase3d5a272009-01-06 14:41:02 -0800264 force_successful_syscall_return();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 return compat_jiffies_to_clock_t(jiffies);
266}
267
Chris Metcalfbe84cb42011-05-09 13:12:30 -0400268#ifdef __ARCH_WANT_SYS_SIGPENDING
269
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270/*
271 * Assumption: old_sigset_t and compat_old_sigset_t are both
272 * types that can be passed to put_user()/get_user().
273 */
274
Heiko Carstens62a6fa92014-03-03 16:11:13 +0100275COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276{
277 old_sigset_t s;
278 long ret;
279 mm_segment_t old_fs = get_fs();
280
281 set_fs(KERNEL_DS);
282 ret = sys_sigpending((old_sigset_t __user *) &s);
283 set_fs(old_fs);
284 if (ret == 0)
285 ret = put_user(s, set);
286 return ret;
287}
288
Chris Metcalfbe84cb42011-05-09 13:12:30 -0400289#endif
290
291#ifdef __ARCH_WANT_SYS_SIGPROCMASK
292
Jan Kiszkab7dafa02012-05-10 10:04:36 -0300293/*
294 * sys_sigprocmask SIG_SETMASK sets the first (compat) word of the
295 * blocked set of signals to the supplied signal set
296 */
297static inline void compat_sig_setmask(sigset_t *blocked, compat_sigset_word set)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298{
Jan Kiszkab7dafa02012-05-10 10:04:36 -0300299 memcpy(blocked->sig, &set, sizeof(set));
300}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
Al Viro5cf22102012-11-25 19:41:01 -0500302COMPAT_SYSCALL_DEFINE3(sigprocmask, int, how,
303 compat_old_sigset_t __user *, nset,
304 compat_old_sigset_t __user *, oset)
Jan Kiszkab7dafa02012-05-10 10:04:36 -0300305{
306 old_sigset_t old_set, new_set;
307 sigset_t new_blocked;
308
309 old_set = current->blocked.sig[0];
310
311 if (nset) {
312 if (get_user(new_set, nset))
313 return -EFAULT;
314 new_set &= ~(sigmask(SIGKILL) | sigmask(SIGSTOP));
315
316 new_blocked = current->blocked;
317
318 switch (how) {
319 case SIG_BLOCK:
320 sigaddsetmask(&new_blocked, new_set);
321 break;
322 case SIG_UNBLOCK:
323 sigdelsetmask(&new_blocked, new_set);
324 break;
325 case SIG_SETMASK:
326 compat_sig_setmask(&new_blocked, new_set);
327 break;
328 default:
329 return -EINVAL;
330 }
331
332 set_current_blocked(&new_blocked);
333 }
334
335 if (oset) {
336 if (put_user(old_set, oset))
337 return -EFAULT;
338 }
339
340 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341}
342
Chris Metcalfbe84cb42011-05-09 13:12:30 -0400343#endif
344
Heiko Carstens62a6fa92014-03-03 16:11:13 +0100345COMPAT_SYSCALL_DEFINE2(setrlimit, unsigned int, resource,
346 struct compat_rlimit __user *, rlim)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347{
348 struct rlimit r;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
350 if (!access_ok(VERIFY_READ, rlim, sizeof(*rlim)) ||
351 __get_user(r.rlim_cur, &rlim->rlim_cur) ||
352 __get_user(r.rlim_max, &rlim->rlim_max))
353 return -EFAULT;
354
355 if (r.rlim_cur == COMPAT_RLIM_INFINITY)
356 r.rlim_cur = RLIM_INFINITY;
357 if (r.rlim_max == COMPAT_RLIM_INFINITY)
358 r.rlim_max = RLIM_INFINITY;
Jiri Slabyb9518342010-05-04 11:28:25 +0200359 return do_prlimit(current, resource, &r, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360}
361
362#ifdef COMPAT_RLIM_OLD_INFINITY
363
Heiko Carstens62a6fa92014-03-03 16:11:13 +0100364COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
365 struct compat_rlimit __user *, rlim)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366{
367 struct rlimit r;
368 int ret;
369 mm_segment_t old_fs = get_fs();
370
371 set_fs(KERNEL_DS);
H. Peter Anvindce44e02014-02-02 17:57:28 -0800372 ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 set_fs(old_fs);
374
375 if (!ret) {
376 if (r.rlim_cur > COMPAT_RLIM_OLD_INFINITY)
377 r.rlim_cur = COMPAT_RLIM_INFINITY;
378 if (r.rlim_max > COMPAT_RLIM_OLD_INFINITY)
379 r.rlim_max = COMPAT_RLIM_INFINITY;
380
381 if (!access_ok(VERIFY_WRITE, rlim, sizeof(*rlim)) ||
382 __put_user(r.rlim_cur, &rlim->rlim_cur) ||
383 __put_user(r.rlim_max, &rlim->rlim_max))
384 return -EFAULT;
385 }
386 return ret;
387}
388
389#endif
390
Heiko Carstens62a6fa92014-03-03 16:11:13 +0100391COMPAT_SYSCALL_DEFINE2(getrlimit, unsigned int, resource,
392 struct compat_rlimit __user *, rlim)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393{
394 struct rlimit r;
395 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Jiri Slabyb9518342010-05-04 11:28:25 +0200397 ret = do_prlimit(current, resource, NULL, &r);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 if (!ret) {
399 if (r.rlim_cur > COMPAT_RLIM_INFINITY)
400 r.rlim_cur = COMPAT_RLIM_INFINITY;
401 if (r.rlim_max > COMPAT_RLIM_INFINITY)
402 r.rlim_max = COMPAT_RLIM_INFINITY;
403
404 if (!access_ok(VERIFY_WRITE, rlim, sizeof(*rlim)) ||
405 __put_user(r.rlim_cur, &rlim->rlim_cur) ||
406 __put_user(r.rlim_max, &rlim->rlim_max))
407 return -EFAULT;
408 }
409 return ret;
410}
411
412int put_compat_rusage(const struct rusage *r, struct compat_rusage __user *ru)
413{
414 if (!access_ok(VERIFY_WRITE, ru, sizeof(*ru)) ||
415 __put_user(r->ru_utime.tv_sec, &ru->ru_utime.tv_sec) ||
416 __put_user(r->ru_utime.tv_usec, &ru->ru_utime.tv_usec) ||
417 __put_user(r->ru_stime.tv_sec, &ru->ru_stime.tv_sec) ||
418 __put_user(r->ru_stime.tv_usec, &ru->ru_stime.tv_usec) ||
419 __put_user(r->ru_maxrss, &ru->ru_maxrss) ||
420 __put_user(r->ru_ixrss, &ru->ru_ixrss) ||
421 __put_user(r->ru_idrss, &ru->ru_idrss) ||
422 __put_user(r->ru_isrss, &ru->ru_isrss) ||
423 __put_user(r->ru_minflt, &ru->ru_minflt) ||
424 __put_user(r->ru_majflt, &ru->ru_majflt) ||
425 __put_user(r->ru_nswap, &ru->ru_nswap) ||
426 __put_user(r->ru_inblock, &ru->ru_inblock) ||
427 __put_user(r->ru_oublock, &ru->ru_oublock) ||
428 __put_user(r->ru_msgsnd, &ru->ru_msgsnd) ||
429 __put_user(r->ru_msgrcv, &ru->ru_msgrcv) ||
430 __put_user(r->ru_nsignals, &ru->ru_nsignals) ||
431 __put_user(r->ru_nvcsw, &ru->ru_nvcsw) ||
432 __put_user(r->ru_nivcsw, &ru->ru_nivcsw))
433 return -EFAULT;
434 return 0;
435}
436
Al Viro8d9807b2012-12-23 14:56:40 -0500437COMPAT_SYSCALL_DEFINE4(wait4,
438 compat_pid_t, pid,
439 compat_uint_t __user *, stat_addr,
440 int, options,
441 struct compat_rusage __user *, ru)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442{
443 if (!ru) {
444 return sys_wait4(pid, stat_addr, options, NULL);
445 } else {
446 struct rusage r;
447 int ret;
448 unsigned int status;
449 mm_segment_t old_fs = get_fs();
450
451 set_fs (KERNEL_DS);
452 ret = sys_wait4(pid,
453 (stat_addr ?
454 (unsigned int __user *) &status : NULL),
455 options, (struct rusage __user *) &r);
456 set_fs (old_fs);
457
458 if (ret > 0) {
459 if (put_compat_rusage(&r, ru))
460 return -EFAULT;
461 if (stat_addr && put_user(status, stat_addr))
462 return -EFAULT;
463 }
464 return ret;
465 }
466}
467
Al Viro8d9807b2012-12-23 14:56:40 -0500468COMPAT_SYSCALL_DEFINE5(waitid,
469 int, which, compat_pid_t, pid,
470 struct compat_siginfo __user *, uinfo, int, options,
471 struct compat_rusage __user *, uru)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472{
473 siginfo_t info;
474 struct rusage ru;
475 long ret;
476 mm_segment_t old_fs = get_fs();
477
478 memset(&info, 0, sizeof(info));
479
480 set_fs(KERNEL_DS);
481 ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
482 uru ? (struct rusage __user *)&ru : NULL);
483 set_fs(old_fs);
484
485 if ((ret < 0) || (info.si_signo == 0))
486 return ret;
487
488 if (uru) {
Al Viroa566c282012-12-23 23:14:49 -0500489 /* sys_waitid() overwrites everything in ru */
490 if (COMPAT_USE_64BIT_TIME)
491 ret = copy_to_user(uru, &ru, sizeof(ru));
492 else
493 ret = put_compat_rusage(&ru, uru);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 if (ret)
Dan Carpenterbffea772013-02-21 16:41:57 -0800495 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 }
497
498 BUG_ON(info.si_code & __SI_MASK);
499 info.si_code |= __SI_CHLD;
500 return copy_siginfo_to_user32(uinfo, &info);
501}
502
503static int compat_get_user_cpu_mask(compat_ulong_t __user *user_mask_ptr,
Rusty Russella45185d2009-01-01 10:12:24 +1030504 unsigned len, struct cpumask *new_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505{
506 unsigned long *k;
507
Rusty Russella45185d2009-01-01 10:12:24 +1030508 if (len < cpumask_size())
509 memset(new_mask, 0, cpumask_size());
510 else if (len > cpumask_size())
511 len = cpumask_size();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
Rusty Russella45185d2009-01-01 10:12:24 +1030513 k = cpumask_bits(new_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 return compat_get_bitmap(k, user_mask_ptr, len * 8);
515}
516
Heiko Carstens62a6fa92014-03-03 16:11:13 +0100517COMPAT_SYSCALL_DEFINE3(sched_setaffinity, compat_pid_t, pid,
518 unsigned int, len,
519 compat_ulong_t __user *, user_mask_ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520{
Rusty Russella45185d2009-01-01 10:12:24 +1030521 cpumask_var_t new_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 int retval;
523
Rusty Russella45185d2009-01-01 10:12:24 +1030524 if (!alloc_cpumask_var(&new_mask, GFP_KERNEL))
525 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
Rusty Russella45185d2009-01-01 10:12:24 +1030527 retval = compat_get_user_cpu_mask(user_mask_ptr, len, new_mask);
528 if (retval)
529 goto out;
530
531 retval = sched_setaffinity(pid, new_mask);
532out:
533 free_cpumask_var(new_mask);
534 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535}
536
Heiko Carstens62a6fa92014-03-03 16:11:13 +0100537COMPAT_SYSCALL_DEFINE3(sched_getaffinity, compat_pid_t, pid, unsigned int, len,
538 compat_ulong_t __user *, user_mask_ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539{
540 int ret;
Rusty Russella45185d2009-01-01 10:12:24 +1030541 cpumask_var_t mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
KOSAKI Motohirofa9dc262010-05-19 09:37:41 +0900543 if ((len * BITS_PER_BYTE) < nr_cpu_ids)
544 return -EINVAL;
545 if (len & (sizeof(compat_ulong_t)-1))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 return -EINVAL;
547
Rusty Russella45185d2009-01-01 10:12:24 +1030548 if (!alloc_cpumask_var(&mask, GFP_KERNEL))
549 return -ENOMEM;
550
551 ret = sched_getaffinity(pid, mask);
KOSAKI Motohirofa9dc262010-05-19 09:37:41 +0900552 if (ret == 0) {
553 size_t retlen = min_t(size_t, len, cpumask_size());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
KOSAKI Motohirofa9dc262010-05-19 09:37:41 +0900555 if (compat_put_bitmap(user_mask_ptr, cpumask_bits(mask), retlen * 8))
556 ret = -EFAULT;
557 else
558 ret = retlen;
559 }
Rusty Russella45185d2009-01-01 10:12:24 +1030560 free_cpumask_var(mask);
KOSAKI Motohirofa9dc262010-05-19 09:37:41 +0900561
Rusty Russella45185d2009-01-01 10:12:24 +1030562 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563}
564
Davide Libenzi83f5d122007-05-10 22:23:18 -0700565int get_compat_itimerspec(struct itimerspec *dst,
566 const struct compat_itimerspec __user *src)
Daniel Walkerbd3a8492007-10-18 03:06:09 -0700567{
H. Peter Anvin81993e82014-02-01 18:54:11 -0800568 if (__compat_get_timespec(&dst->it_interval, &src->it_interval) ||
569 __compat_get_timespec(&dst->it_value, &src->it_value))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 return -EFAULT;
571 return 0;
Daniel Walkerbd3a8492007-10-18 03:06:09 -0700572}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
Davide Libenzi83f5d122007-05-10 22:23:18 -0700574int put_compat_itimerspec(struct compat_itimerspec __user *dst,
575 const struct itimerspec *src)
Daniel Walkerbd3a8492007-10-18 03:06:09 -0700576{
H. Peter Anvin81993e82014-02-01 18:54:11 -0800577 if (__compat_put_timespec(&src->it_interval, &dst->it_interval) ||
578 __compat_put_timespec(&src->it_value, &dst->it_value))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 return -EFAULT;
580 return 0;
Daniel Walkerbd3a8492007-10-18 03:06:09 -0700581}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
Heiko Carstens62a6fa92014-03-03 16:11:13 +0100583COMPAT_SYSCALL_DEFINE3(timer_create, clockid_t, which_clock,
584 struct compat_sigevent __user *, timer_event_spec,
585 timer_t __user *, created_timer_id)
Christoph Hellwig3a0f69d2006-01-09 20:52:08 -0800586{
587 struct sigevent __user *event = NULL;
588
589 if (timer_event_spec) {
590 struct sigevent kevent;
591
592 event = compat_alloc_user_space(sizeof(*event));
593 if (get_compat_sigevent(&kevent, timer_event_spec) ||
594 copy_to_user(event, &kevent, sizeof(*event)))
595 return -EFAULT;
596 }
597
598 return sys_timer_create(which_clock, event, created_timer_id);
599}
600
Heiko Carstens62a6fa92014-03-03 16:11:13 +0100601COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
602 struct compat_timespec __user *, tp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603{
604 long err;
605 mm_segment_t oldfs;
Daniel Walkerbd3a8492007-10-18 03:06:09 -0700606 struct timespec ts;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
H. Peter Anvin81993e82014-02-01 18:54:11 -0800608 if (compat_get_timespec(&ts, tp))
Daniel Walkerbd3a8492007-10-18 03:06:09 -0700609 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 oldfs = get_fs();
Daniel Walkerbd3a8492007-10-18 03:06:09 -0700611 set_fs(KERNEL_DS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 err = sys_clock_settime(which_clock,
613 (struct timespec __user *) &ts);
614 set_fs(oldfs);
615 return err;
Daniel Walkerbd3a8492007-10-18 03:06:09 -0700616}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
Heiko Carstens62a6fa92014-03-03 16:11:13 +0100618COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
619 struct compat_timespec __user *, tp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620{
621 long err;
622 mm_segment_t oldfs;
Daniel Walkerbd3a8492007-10-18 03:06:09 -0700623 struct timespec ts;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
625 oldfs = get_fs();
626 set_fs(KERNEL_DS);
627 err = sys_clock_gettime(which_clock,
628 (struct timespec __user *) &ts);
629 set_fs(oldfs);
H. Peter Anvin81993e82014-02-01 18:54:11 -0800630 if (!err && compat_put_timespec(&ts, tp))
Daniel Walkerbd3a8492007-10-18 03:06:09 -0700631 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 return err;
Daniel Walkerbd3a8492007-10-18 03:06:09 -0700633}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
Heiko Carstens62a6fa92014-03-03 16:11:13 +0100635COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
636 struct compat_timespec __user *, tp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637{
638 long err;
639 mm_segment_t oldfs;
Daniel Walkerbd3a8492007-10-18 03:06:09 -0700640 struct timespec ts;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
642 oldfs = get_fs();
643 set_fs(KERNEL_DS);
644 err = sys_clock_getres(which_clock,
645 (struct timespec __user *) &ts);
646 set_fs(oldfs);
H. Peter Anvin81993e82014-02-01 18:54:11 -0800647 if (!err && tp && compat_put_timespec(&ts, tp))
Daniel Walkerbd3a8492007-10-18 03:06:09 -0700648 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 return err;
Daniel Walkerbd3a8492007-10-18 03:06:09 -0700650}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652/*
653 * We currently only need the following fields from the sigevent
654 * structure: sigev_value, sigev_signo, sig_notify and (sometimes
655 * sigev_notify_thread_id). The others are handled in user mode.
656 * We also assume that copying sigev_value.sival_int is sufficient
657 * to keep all the bits of sigev_value.sival_ptr intact.
658 */
659int get_compat_sigevent(struct sigevent *event,
660 const struct compat_sigevent __user *u_event)
661{
David S. Miller51410d32005-04-16 15:24:01 -0700662 memset(event, 0, sizeof(*event));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 return (!access_ok(VERIFY_READ, u_event, sizeof(*u_event)) ||
664 __get_user(event->sigev_value.sival_int,
665 &u_event->sigev_value.sival_int) ||
666 __get_user(event->sigev_signo, &u_event->sigev_signo) ||
667 __get_user(event->sigev_notify, &u_event->sigev_notify) ||
668 __get_user(event->sigev_notify_thread_id,
669 &u_event->sigev_notify_thread_id))
670 ? -EFAULT : 0;
671}
672
Stephen Rothwell5fa38392006-10-28 10:38:46 -0700673long compat_get_bitmap(unsigned long *mask, const compat_ulong_t __user *umask,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 unsigned long bitmap_size)
675{
676 int i, j;
677 unsigned long m;
678 compat_ulong_t um;
679 unsigned long nr_compat_longs;
680
681 /* align bitmap up to nearest compat_long_t boundary */
682 bitmap_size = ALIGN(bitmap_size, BITS_PER_COMPAT_LONG);
683
684 if (!access_ok(VERIFY_READ, umask, bitmap_size / 8))
685 return -EFAULT;
686
687 nr_compat_longs = BITS_TO_COMPAT_LONGS(bitmap_size);
688
689 for (i = 0; i < BITS_TO_LONGS(bitmap_size); i++) {
690 m = 0;
691
692 for (j = 0; j < sizeof(m)/sizeof(um); j++) {
693 /*
694 * We dont want to read past the end of the userspace
695 * bitmap. We must however ensure the end of the
696 * kernel bitmap is zeroed.
697 */
Helge Deller9b7b8192015-06-04 23:57:18 +0200698 if (nr_compat_longs) {
699 nr_compat_longs--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 if (__get_user(um, umask))
701 return -EFAULT;
702 } else {
703 um = 0;
704 }
705
706 umask++;
707 m |= (long)um << (j * BITS_PER_COMPAT_LONG);
708 }
709 *mask++ = m;
710 }
711
712 return 0;
713}
714
715long compat_put_bitmap(compat_ulong_t __user *umask, unsigned long *mask,
716 unsigned long bitmap_size)
717{
718 int i, j;
719 unsigned long m;
720 compat_ulong_t um;
721 unsigned long nr_compat_longs;
722
723 /* align bitmap up to nearest compat_long_t boundary */
724 bitmap_size = ALIGN(bitmap_size, BITS_PER_COMPAT_LONG);
725
726 if (!access_ok(VERIFY_WRITE, umask, bitmap_size / 8))
727 return -EFAULT;
728
729 nr_compat_longs = BITS_TO_COMPAT_LONGS(bitmap_size);
730
731 for (i = 0; i < BITS_TO_LONGS(bitmap_size); i++) {
732 m = *mask++;
733
734 for (j = 0; j < sizeof(m)/sizeof(um); j++) {
735 um = m;
736
737 /*
738 * We dont want to write past the end of the userspace
739 * bitmap.
740 */
Helge Deller9b7b8192015-06-04 23:57:18 +0200741 if (nr_compat_longs) {
742 nr_compat_longs--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 if (__put_user(um, umask))
744 return -EFAULT;
745 }
746
747 umask++;
748 m >>= 4*sizeof(um);
749 m >>= 4*sizeof(um);
750 }
751 }
752
753 return 0;
754}
755
756void
Al Viro322a56c2012-12-25 13:32:58 -0500757sigset_from_compat(sigset_t *set, const compat_sigset_t *compat)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758{
759 switch (_NSIG_WORDS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 case 4: set->sig[3] = compat->sig[6] | (((long)compat->sig[7]) << 32 );
761 case 3: set->sig[2] = compat->sig[4] | (((long)compat->sig[5]) << 32 );
762 case 2: set->sig[1] = compat->sig[2] | (((long)compat->sig[3]) << 32 );
763 case 1: set->sig[0] = compat->sig[0] | (((long)compat->sig[1]) << 32 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 }
765}
Alexander Graf1dda6062011-06-08 02:45:37 +0200766EXPORT_SYMBOL_GPL(sigset_from_compat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
Al Viro322a56c2012-12-25 13:32:58 -0500768void
769sigset_to_compat(compat_sigset_t *compat, const sigset_t *set)
770{
771 switch (_NSIG_WORDS) {
772 case 4: compat->sig[7] = (set->sig[3] >> 32); compat->sig[6] = set->sig[3];
773 case 3: compat->sig[5] = (set->sig[2] >> 32); compat->sig[4] = set->sig[2];
774 case 2: compat->sig[3] = (set->sig[1] >> 32); compat->sig[2] = set->sig[1];
775 case 1: compat->sig[1] = (set->sig[0] >> 32); compat->sig[0] = set->sig[0];
776 }
777}
778
Al Viro28d27f22012-11-25 19:32:25 -0500779COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait, compat_sigset_t __user *, uthese,
780 struct compat_siginfo __user *, uinfo,
781 struct compat_timespec __user *, uts, compat_size_t, sigsetsize)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782{
783 compat_sigset_t s32;
784 sigset_t s;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 struct timespec t;
786 siginfo_t info;
Oleg Nesterov943df142011-04-27 21:44:14 +0200787 long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
789 if (sigsetsize != sizeof(sigset_t))
790 return -EINVAL;
791
792 if (copy_from_user(&s32, uthese, sizeof(compat_sigset_t)))
793 return -EFAULT;
794 sigset_from_compat(&s, &s32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
796 if (uts) {
Al Virob2ddedc2012-12-24 12:31:00 -0500797 if (compat_get_timespec(&t, uts))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 }
800
Oleg Nesterov943df142011-04-27 21:44:14 +0200801 ret = do_sigtimedwait(&s, &info, uts ? &t : NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
Oleg Nesterov943df142011-04-27 21:44:14 +0200803 if (ret > 0 && uinfo) {
804 if (copy_siginfo_to_user32(uinfo, &info))
805 ret = -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 return ret;
Thomas Gleixner62ab4502009-04-04 21:01:06 +0000809}
810
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811#ifdef __ARCH_WANT_COMPAT_SYS_TIME
812
813/* compat_time_t is a 32 bit "long" and needs to get converted. */
814
Heiko Carstens62a6fa92014-03-03 16:11:13 +0100815COMPAT_SYSCALL_DEFINE1(time, compat_time_t __user *, tloc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816{
817 compat_time_t i;
818 struct timeval tv;
819
820 do_gettimeofday(&tv);
821 i = tv.tv_sec;
822
823 if (tloc) {
824 if (put_user(i,tloc))
Paul Mackerrase3d5a272009-01-06 14:41:02 -0800825 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 }
Paul Mackerrase3d5a272009-01-06 14:41:02 -0800827 force_successful_syscall_return();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 return i;
829}
830
Heiko Carstens62a6fa92014-03-03 16:11:13 +0100831COMPAT_SYSCALL_DEFINE1(stime, compat_time_t __user *, tptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832{
833 struct timespec tv;
834 int err;
835
836 if (get_user(tv.tv_sec, tptr))
837 return -EFAULT;
838
839 tv.tv_nsec = 0;
840
841 err = security_settime(&tv, NULL);
842 if (err)
843 return err;
844
845 do_settimeofday(&tv);
846 return 0;
847}
848
849#endif /* __ARCH_WANT_COMPAT_SYS_TIME */
David Woodhouse150256d2006-01-18 17:43:57 -0800850
Christoph Lameter1b2db9f2006-06-23 02:03:56 -0700851#ifdef CONFIG_NUMA
Heiko Carstens2f2728f2014-03-04 17:18:23 +0100852COMPAT_SYSCALL_DEFINE6(move_pages, pid_t, pid, compat_ulong_t, nr_pages,
853 compat_uptr_t __user *, pages32,
854 const int __user *, nodes,
855 int __user *, status,
856 int, flags)
Christoph Lameter1b2db9f2006-06-23 02:03:56 -0700857{
858 const void __user * __user *pages;
859 int i;
860
861 pages = compat_alloc_user_space(nr_pages * sizeof(void *));
862 for (i = 0; i < nr_pages; i++) {
863 compat_uptr_t p;
864
Christoph Lameter9216dfa2006-06-23 02:03:57 -0700865 if (get_user(p, pages32 + i) ||
Christoph Lameter1b2db9f2006-06-23 02:03:56 -0700866 put_user(compat_ptr(p), pages + i))
867 return -EFAULT;
868 }
869 return sys_move_pages(pid, nr_pages, pages, nodes, status, flags);
870}
Stephen Rothwell3fd59392006-11-02 22:07:24 -0800871
Heiko Carstens62a6fa92014-03-03 16:11:13 +0100872COMPAT_SYSCALL_DEFINE4(migrate_pages, compat_pid_t, pid,
873 compat_ulong_t, maxnode,
874 const compat_ulong_t __user *, old_nodes,
875 const compat_ulong_t __user *, new_nodes)
Stephen Rothwell3fd59392006-11-02 22:07:24 -0800876{
877 unsigned long __user *old = NULL;
878 unsigned long __user *new = NULL;
879 nodemask_t tmp_mask;
880 unsigned long nr_bits;
881 unsigned long size;
882
883 nr_bits = min_t(unsigned long, maxnode - 1, MAX_NUMNODES);
884 size = ALIGN(nr_bits, BITS_PER_LONG) / 8;
885 if (old_nodes) {
886 if (compat_get_bitmap(nodes_addr(tmp_mask), old_nodes, nr_bits))
887 return -EFAULT;
888 old = compat_alloc_user_space(new_nodes ? size * 2 : size);
889 if (new_nodes)
890 new = old + size / sizeof(unsigned long);
891 if (copy_to_user(old, nodes_addr(tmp_mask), size))
892 return -EFAULT;
893 }
894 if (new_nodes) {
895 if (compat_get_bitmap(nodes_addr(tmp_mask), new_nodes, nr_bits))
896 return -EFAULT;
897 if (new == NULL)
898 new = compat_alloc_user_space(size);
899 if (copy_to_user(new, nodes_addr(tmp_mask), size))
900 return -EFAULT;
901 }
902 return sys_migrate_pages(pid, nr_bits + 1, old, new);
903}
Christoph Lameter1b2db9f2006-06-23 02:03:56 -0700904#endif
Kyle McMartind4d23ad2007-02-10 01:46:00 -0800905
Al Viro6883da8c2012-12-25 16:59:28 -0500906COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
907 compat_pid_t, pid,
908 struct compat_timespec __user *, interval)
Catalin Marinas0ad50c32012-12-17 16:01:45 -0800909{
910 struct timespec t;
911 int ret;
912 mm_segment_t old_fs = get_fs();
913
914 set_fs(KERNEL_DS);
915 ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
916 set_fs(old_fs);
H. Peter Anvin81993e82014-02-01 18:54:11 -0800917 if (compat_put_timespec(&t, interval))
Catalin Marinas0ad50c32012-12-17 16:01:45 -0800918 return -EFAULT;
919 return ret;
920}
Catalin Marinas0ad50c32012-12-17 16:01:45 -0800921
H. Peter Anvinc41d68a2010-09-07 16:16:18 -0700922/*
923 * Allocate user-space memory for the duration of a single system call,
924 * in order to marshall parameters inside a compat thunk.
925 */
926void __user *compat_alloc_user_space(unsigned long len)
927{
928 void __user *ptr;
929
930 /* If len would occupy more than half of the entire compat space... */
931 if (unlikely(len > (((compat_uptr_t)~0) >> 1)))
932 return NULL;
933
934 ptr = arch_compat_alloc_user_space(len);
935
936 if (unlikely(!access_ok(VERIFY_WRITE, ptr, len)))
937 return NULL;
938
939 return ptr;
940}
941EXPORT_SYMBOL_GPL(compat_alloc_user_space);