Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/syscalls.h> |
| 21 | #include <linux/unistd.h> |
| 22 | #include <linux/security.h> |
Stephen Rothwell | 3158e94 | 2006-03-26 01:37:29 -0800 | [diff] [blame] | 23 | #include <linux/timex.h> |
Paul Gortmaker | 6e5fdee | 2011-05-26 16:00:52 -0400 | [diff] [blame] | 24 | #include <linux/export.h> |
Christoph Lameter | 1b2db9f | 2006-06-23 02:03:56 -0700 | [diff] [blame] | 25 | #include <linux/migrate.h> |
Toyo Abe | 1711ef3 | 2006-09-29 02:00:28 -0700 | [diff] [blame] | 26 | #include <linux/posix-timers.h> |
Frank Mayhar | f06febc | 2008-09-12 09:54:39 -0700 | [diff] [blame] | 27 | #include <linux/times.h> |
Paul Mackerras | e3d5a27 | 2009-01-06 14:41:02 -0800 | [diff] [blame] | 28 | #include <linux/ptrace.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/gfp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 31 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Al Viro | 3a4d44b | 2017-06-07 09:42:34 +0100 | [diff] [blame^] | 33 | int compat_get_timex(struct timex *txc, const struct compat_timex __user *utp) |
Richard Cochran | 65f5d80 | 2011-02-01 13:52:23 +0000 | [diff] [blame] | 34 | { |
Al Viro | 3a4d44b | 2017-06-07 09:42:34 +0100 | [diff] [blame^] | 35 | struct compat_timex tx32; |
Richard Cochran | 65f5d80 | 2011-02-01 13:52:23 +0000 | [diff] [blame] | 36 | |
Al Viro | 3a4d44b | 2017-06-07 09:42:34 +0100 | [diff] [blame^] | 37 | if (copy_from_user(&tx32, utp, sizeof(struct compat_timex))) |
Richard Cochran | 65f5d80 | 2011-02-01 13:52:23 +0000 | [diff] [blame] | 38 | return -EFAULT; |
| 39 | |
Al Viro | 3a4d44b | 2017-06-07 09:42:34 +0100 | [diff] [blame^] | 40 | 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 Cochran | 65f5d80 | 2011-02-01 13:52:23 +0000 | [diff] [blame] | 61 | return 0; |
| 62 | } |
| 63 | |
Al Viro | 3a4d44b | 2017-06-07 09:42:34 +0100 | [diff] [blame^] | 64 | int compat_put_timex(struct compat_timex __user *utp, const struct timex *txc) |
Richard Cochran | 65f5d80 | 2011-02-01 13:52:23 +0000 | [diff] [blame] | 65 | { |
Al Viro | 3a4d44b | 2017-06-07 09:42:34 +0100 | [diff] [blame^] | 66 | 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 Cochran | 65f5d80 | 2011-02-01 13:52:23 +0000 | [diff] [blame] | 91 | return -EFAULT; |
| 92 | return 0; |
| 93 | } |
| 94 | |
Heiko Carstens | 62a6fa9 | 2014-03-03 16:11:13 +0100 | [diff] [blame] | 95 | COMPAT_SYSCALL_DEFINE2(gettimeofday, struct compat_timeval __user *, tv, |
| 96 | struct timezone __user *, tz) |
Christoph Hellwig | b418da1 | 2008-10-15 22:02:06 -0700 | [diff] [blame] | 97 | { |
| 98 | if (tv) { |
| 99 | struct timeval ktv; |
| 100 | do_gettimeofday(&ktv); |
H. Peter Anvin | 81993e8 | 2014-02-01 18:54:11 -0800 | [diff] [blame] | 101 | if (compat_put_timeval(&ktv, tv)) |
Christoph Hellwig | b418da1 | 2008-10-15 22:02:06 -0700 | [diff] [blame] | 102 | 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 Carstens | 62a6fa9 | 2014-03-03 16:11:13 +0100 | [diff] [blame] | 112 | COMPAT_SYSCALL_DEFINE2(settimeofday, struct compat_timeval __user *, tv, |
| 113 | struct timezone __user *, tz) |
Christoph Hellwig | b418da1 | 2008-10-15 22:02:06 -0700 | [diff] [blame] | 114 | { |
Deepa Dinamani | 2ac00f1 | 2017-03-26 12:04:12 -0700 | [diff] [blame] | 115 | struct timespec64 new_ts; |
H. Peter Anvin | 81993e8 | 2014-02-01 18:54:11 -0800 | [diff] [blame] | 116 | struct timeval user_tv; |
H. Peter Anvin | 81993e8 | 2014-02-01 18:54:11 -0800 | [diff] [blame] | 117 | struct timezone new_tz; |
Christoph Hellwig | b418da1 | 2008-10-15 22:02:06 -0700 | [diff] [blame] | 118 | |
| 119 | if (tv) { |
H. Peter Anvin | 81993e8 | 2014-02-01 18:54:11 -0800 | [diff] [blame] | 120 | if (compat_get_timeval(&user_tv, tv)) |
Christoph Hellwig | b418da1 | 2008-10-15 22:02:06 -0700 | [diff] [blame] | 121 | return -EFAULT; |
H. Peter Anvin | 81993e8 | 2014-02-01 18:54:11 -0800 | [diff] [blame] | 122 | new_ts.tv_sec = user_tv.tv_sec; |
| 123 | new_ts.tv_nsec = user_tv.tv_usec * NSEC_PER_USEC; |
Christoph Hellwig | b418da1 | 2008-10-15 22:02:06 -0700 | [diff] [blame] | 124 | } |
| 125 | if (tz) { |
H. Peter Anvin | 81993e8 | 2014-02-01 18:54:11 -0800 | [diff] [blame] | 126 | if (copy_from_user(&new_tz, tz, sizeof(*tz))) |
Christoph Hellwig | b418da1 | 2008-10-15 22:02:06 -0700 | [diff] [blame] | 127 | return -EFAULT; |
| 128 | } |
| 129 | |
Deepa Dinamani | 2ac00f1 | 2017-03-26 12:04:12 -0700 | [diff] [blame] | 130 | return do_sys_settimeofday64(tv ? &new_ts : NULL, tz ? &new_tz : NULL); |
Christoph Hellwig | b418da1 | 2008-10-15 22:02:06 -0700 | [diff] [blame] | 131 | } |
| 132 | |
H. Peter Anvin | 81993e8 | 2014-02-01 18:54:11 -0800 | [diff] [blame] | 133 | static int __compat_get_timeval(struct timeval *tv, const struct compat_timeval __user *ctv) |
H. Peter Anvin | 6684ba2 | 2012-02-19 17:38:00 -0800 | [diff] [blame] | 134 | { |
| 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 Anvin | 6684ba2 | 2012-02-19 17:38:00 -0800 | [diff] [blame] | 139 | |
H. Peter Anvin | 81993e8 | 2014-02-01 18:54:11 -0800 | [diff] [blame] | 140 | static int __compat_put_timeval(const struct timeval *tv, struct compat_timeval __user *ctv) |
H. Peter Anvin | 6684ba2 | 2012-02-19 17:38:00 -0800 | [diff] [blame] | 141 | { |
| 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 Anvin | 6684ba2 | 2012-02-19 17:38:00 -0800 | [diff] [blame] | 146 | |
H. Peter Anvin | 81993e8 | 2014-02-01 18:54:11 -0800 | [diff] [blame] | 147 | static int __compat_get_timespec(struct timespec *ts, const struct compat_timespec __user *cts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | { |
| 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 Anvin | 81993e8 | 2014-02-01 18:54:11 -0800 | [diff] [blame] | 154 | static int __compat_put_timespec(const struct timespec *ts, struct compat_timespec __user *cts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | { |
| 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 Anvin | 6684ba2 | 2012-02-19 17:38:00 -0800 | [diff] [blame] | 161 | int compat_get_timeval(struct timeval *tv, const void __user *utv) |
| 162 | { |
| 163 | if (COMPAT_USE_64BIT_TIME) |
Fabian Frederick | 6516a46 | 2014-06-04 16:12:02 -0700 | [diff] [blame] | 164 | return copy_from_user(tv, utv, sizeof(*tv)) ? -EFAULT : 0; |
H. Peter Anvin | 6684ba2 | 2012-02-19 17:38:00 -0800 | [diff] [blame] | 165 | else |
H. Peter Anvin | 81993e8 | 2014-02-01 18:54:11 -0800 | [diff] [blame] | 166 | return __compat_get_timeval(tv, utv); |
H. Peter Anvin | 6684ba2 | 2012-02-19 17:38:00 -0800 | [diff] [blame] | 167 | } |
| 168 | EXPORT_SYMBOL_GPL(compat_get_timeval); |
| 169 | |
| 170 | int compat_put_timeval(const struct timeval *tv, void __user *utv) |
| 171 | { |
| 172 | if (COMPAT_USE_64BIT_TIME) |
Fabian Frederick | 6516a46 | 2014-06-04 16:12:02 -0700 | [diff] [blame] | 173 | return copy_to_user(utv, tv, sizeof(*tv)) ? -EFAULT : 0; |
H. Peter Anvin | 6684ba2 | 2012-02-19 17:38:00 -0800 | [diff] [blame] | 174 | else |
H. Peter Anvin | 81993e8 | 2014-02-01 18:54:11 -0800 | [diff] [blame] | 175 | return __compat_put_timeval(tv, utv); |
H. Peter Anvin | 6684ba2 | 2012-02-19 17:38:00 -0800 | [diff] [blame] | 176 | } |
| 177 | EXPORT_SYMBOL_GPL(compat_put_timeval); |
| 178 | |
| 179 | int compat_get_timespec(struct timespec *ts, const void __user *uts) |
| 180 | { |
| 181 | if (COMPAT_USE_64BIT_TIME) |
Fabian Frederick | 6516a46 | 2014-06-04 16:12:02 -0700 | [diff] [blame] | 182 | return copy_from_user(ts, uts, sizeof(*ts)) ? -EFAULT : 0; |
H. Peter Anvin | 6684ba2 | 2012-02-19 17:38:00 -0800 | [diff] [blame] | 183 | else |
H. Peter Anvin | 81993e8 | 2014-02-01 18:54:11 -0800 | [diff] [blame] | 184 | return __compat_get_timespec(ts, uts); |
H. Peter Anvin | 6684ba2 | 2012-02-19 17:38:00 -0800 | [diff] [blame] | 185 | } |
| 186 | EXPORT_SYMBOL_GPL(compat_get_timespec); |
| 187 | |
| 188 | int compat_put_timespec(const struct timespec *ts, void __user *uts) |
| 189 | { |
| 190 | if (COMPAT_USE_64BIT_TIME) |
Fabian Frederick | 6516a46 | 2014-06-04 16:12:02 -0700 | [diff] [blame] | 191 | return copy_to_user(uts, ts, sizeof(*ts)) ? -EFAULT : 0; |
H. Peter Anvin | 6684ba2 | 2012-02-19 17:38:00 -0800 | [diff] [blame] | 192 | else |
H. Peter Anvin | 81993e8 | 2014-02-01 18:54:11 -0800 | [diff] [blame] | 193 | return __compat_put_timespec(ts, uts); |
H. Peter Anvin | 6684ba2 | 2012-02-19 17:38:00 -0800 | [diff] [blame] | 194 | } |
| 195 | EXPORT_SYMBOL_GPL(compat_put_timespec); |
| 196 | |
H. Peter Anvin | 81993e8 | 2014-02-01 18:54:11 -0800 | [diff] [blame] | 197 | int 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | static inline long get_compat_itimerval(struct itimerval *o, |
| 221 | struct compat_itimerval __user *i) |
| 222 | { |
| 223 | return (!access_ok(VERIFY_READ, i, sizeof(*i)) || |
| 224 | (__get_user(o->it_interval.tv_sec, &i->it_interval.tv_sec) | |
| 225 | __get_user(o->it_interval.tv_usec, &i->it_interval.tv_usec) | |
| 226 | __get_user(o->it_value.tv_sec, &i->it_value.tv_sec) | |
| 227 | __get_user(o->it_value.tv_usec, &i->it_value.tv_usec))); |
| 228 | } |
| 229 | |
| 230 | static inline long put_compat_itimerval(struct compat_itimerval __user *o, |
| 231 | struct itimerval *i) |
| 232 | { |
| 233 | return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) || |
| 234 | (__put_user(i->it_interval.tv_sec, &o->it_interval.tv_sec) | |
| 235 | __put_user(i->it_interval.tv_usec, &o->it_interval.tv_usec) | |
| 236 | __put_user(i->it_value.tv_sec, &o->it_value.tv_sec) | |
| 237 | __put_user(i->it_value.tv_usec, &o->it_value.tv_usec))); |
| 238 | } |
| 239 | |
Nicolas Pitre | baa73d9 | 2016-11-11 00:10:10 -0500 | [diff] [blame] | 240 | asmlinkage long sys_ni_posix_timers(void); |
| 241 | |
Al Viro | 3778407 | 2012-12-24 17:28:40 -0500 | [diff] [blame] | 242 | COMPAT_SYSCALL_DEFINE2(getitimer, int, which, |
| 243 | struct compat_itimerval __user *, it) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | { |
| 245 | struct itimerval kit; |
| 246 | int error; |
| 247 | |
Nicolas Pitre | baa73d9 | 2016-11-11 00:10:10 -0500 | [diff] [blame] | 248 | if (!IS_ENABLED(CONFIG_POSIX_TIMERS)) |
| 249 | return sys_ni_posix_timers(); |
| 250 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | error = do_getitimer(which, &kit); |
| 252 | if (!error && put_compat_itimerval(it, &kit)) |
| 253 | error = -EFAULT; |
| 254 | return error; |
| 255 | } |
| 256 | |
Al Viro | 3778407 | 2012-12-24 17:28:40 -0500 | [diff] [blame] | 257 | COMPAT_SYSCALL_DEFINE3(setitimer, int, which, |
| 258 | struct compat_itimerval __user *, in, |
| 259 | struct compat_itimerval __user *, out) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | { |
| 261 | struct itimerval kin, kout; |
| 262 | int error; |
| 263 | |
Nicolas Pitre | baa73d9 | 2016-11-11 00:10:10 -0500 | [diff] [blame] | 264 | if (!IS_ENABLED(CONFIG_POSIX_TIMERS)) |
| 265 | return sys_ni_posix_timers(); |
| 266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | if (in) { |
| 268 | if (get_compat_itimerval(&kin, in)) |
| 269 | return -EFAULT; |
| 270 | } else |
| 271 | memset(&kin, 0, sizeof(kin)); |
| 272 | |
| 273 | error = do_setitimer(which, &kin, out ? &kout : NULL); |
| 274 | if (error || !out) |
| 275 | return error; |
| 276 | if (put_compat_itimerval(out, &kout)) |
| 277 | return -EFAULT; |
| 278 | return 0; |
| 279 | } |
| 280 | |
Frank Mayhar | f06febc | 2008-09-12 09:54:39 -0700 | [diff] [blame] | 281 | static compat_clock_t clock_t_to_compat_clock_t(clock_t x) |
| 282 | { |
| 283 | return compat_jiffies_to_clock_t(clock_t_to_jiffies(x)); |
| 284 | } |
| 285 | |
Heiko Carstens | 62a6fa9 | 2014-03-03 16:11:13 +0100 | [diff] [blame] | 286 | COMPAT_SYSCALL_DEFINE1(times, struct compat_tms __user *, tbuf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | if (tbuf) { |
Frank Mayhar | f06febc | 2008-09-12 09:54:39 -0700 | [diff] [blame] | 289 | struct tms tms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | struct compat_tms tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
Frank Mayhar | f06febc | 2008-09-12 09:54:39 -0700 | [diff] [blame] | 292 | do_sys_times(&tms); |
| 293 | /* Convert our struct tms to the compat version. */ |
| 294 | tmp.tms_utime = clock_t_to_compat_clock_t(tms.tms_utime); |
| 295 | tmp.tms_stime = clock_t_to_compat_clock_t(tms.tms_stime); |
| 296 | tmp.tms_cutime = clock_t_to_compat_clock_t(tms.tms_cutime); |
| 297 | tmp.tms_cstime = clock_t_to_compat_clock_t(tms.tms_cstime); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | if (copy_to_user(tbuf, &tmp, sizeof(tmp))) |
| 299 | return -EFAULT; |
| 300 | } |
Paul Mackerras | e3d5a27 | 2009-01-06 14:41:02 -0800 | [diff] [blame] | 301 | force_successful_syscall_return(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | return compat_jiffies_to_clock_t(jiffies); |
| 303 | } |
| 304 | |
Chris Metcalf | be84cb4 | 2011-05-09 13:12:30 -0400 | [diff] [blame] | 305 | #ifdef __ARCH_WANT_SYS_SIGPENDING |
| 306 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | /* |
| 308 | * Assumption: old_sigset_t and compat_old_sigset_t are both |
| 309 | * types that can be passed to put_user()/get_user(). |
| 310 | */ |
| 311 | |
Heiko Carstens | 62a6fa9 | 2014-03-03 16:11:13 +0100 | [diff] [blame] | 312 | COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | { |
| 314 | old_sigset_t s; |
| 315 | long ret; |
| 316 | mm_segment_t old_fs = get_fs(); |
| 317 | |
| 318 | set_fs(KERNEL_DS); |
| 319 | ret = sys_sigpending((old_sigset_t __user *) &s); |
| 320 | set_fs(old_fs); |
| 321 | if (ret == 0) |
| 322 | ret = put_user(s, set); |
| 323 | return ret; |
| 324 | } |
| 325 | |
Chris Metcalf | be84cb4 | 2011-05-09 13:12:30 -0400 | [diff] [blame] | 326 | #endif |
| 327 | |
| 328 | #ifdef __ARCH_WANT_SYS_SIGPROCMASK |
| 329 | |
Jan Kiszka | b7dafa0 | 2012-05-10 10:04:36 -0300 | [diff] [blame] | 330 | /* |
| 331 | * sys_sigprocmask SIG_SETMASK sets the first (compat) word of the |
| 332 | * blocked set of signals to the supplied signal set |
| 333 | */ |
| 334 | static inline void compat_sig_setmask(sigset_t *blocked, compat_sigset_word set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | { |
Jan Kiszka | b7dafa0 | 2012-05-10 10:04:36 -0300 | [diff] [blame] | 336 | memcpy(blocked->sig, &set, sizeof(set)); |
| 337 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
Al Viro | 5cf2210 | 2012-11-25 19:41:01 -0500 | [diff] [blame] | 339 | COMPAT_SYSCALL_DEFINE3(sigprocmask, int, how, |
| 340 | compat_old_sigset_t __user *, nset, |
| 341 | compat_old_sigset_t __user *, oset) |
Jan Kiszka | b7dafa0 | 2012-05-10 10:04:36 -0300 | [diff] [blame] | 342 | { |
| 343 | old_sigset_t old_set, new_set; |
| 344 | sigset_t new_blocked; |
| 345 | |
| 346 | old_set = current->blocked.sig[0]; |
| 347 | |
| 348 | if (nset) { |
| 349 | if (get_user(new_set, nset)) |
| 350 | return -EFAULT; |
| 351 | new_set &= ~(sigmask(SIGKILL) | sigmask(SIGSTOP)); |
| 352 | |
| 353 | new_blocked = current->blocked; |
| 354 | |
| 355 | switch (how) { |
| 356 | case SIG_BLOCK: |
| 357 | sigaddsetmask(&new_blocked, new_set); |
| 358 | break; |
| 359 | case SIG_UNBLOCK: |
| 360 | sigdelsetmask(&new_blocked, new_set); |
| 361 | break; |
| 362 | case SIG_SETMASK: |
| 363 | compat_sig_setmask(&new_blocked, new_set); |
| 364 | break; |
| 365 | default: |
| 366 | return -EINVAL; |
| 367 | } |
| 368 | |
| 369 | set_current_blocked(&new_blocked); |
| 370 | } |
| 371 | |
| 372 | if (oset) { |
| 373 | if (put_user(old_set, oset)) |
| 374 | return -EFAULT; |
| 375 | } |
| 376 | |
| 377 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Chris Metcalf | be84cb4 | 2011-05-09 13:12:30 -0400 | [diff] [blame] | 380 | #endif |
| 381 | |
Heiko Carstens | 62a6fa9 | 2014-03-03 16:11:13 +0100 | [diff] [blame] | 382 | COMPAT_SYSCALL_DEFINE2(setrlimit, unsigned int, resource, |
| 383 | struct compat_rlimit __user *, rlim) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | { |
| 385 | struct rlimit r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | |
| 387 | if (!access_ok(VERIFY_READ, rlim, sizeof(*rlim)) || |
| 388 | __get_user(r.rlim_cur, &rlim->rlim_cur) || |
| 389 | __get_user(r.rlim_max, &rlim->rlim_max)) |
| 390 | return -EFAULT; |
| 391 | |
| 392 | if (r.rlim_cur == COMPAT_RLIM_INFINITY) |
| 393 | r.rlim_cur = RLIM_INFINITY; |
| 394 | if (r.rlim_max == COMPAT_RLIM_INFINITY) |
| 395 | r.rlim_max = RLIM_INFINITY; |
Jiri Slaby | b951834 | 2010-05-04 11:28:25 +0200 | [diff] [blame] | 396 | return do_prlimit(current, resource, &r, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | #ifdef COMPAT_RLIM_OLD_INFINITY |
| 400 | |
Heiko Carstens | 62a6fa9 | 2014-03-03 16:11:13 +0100 | [diff] [blame] | 401 | COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource, |
| 402 | struct compat_rlimit __user *, rlim) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | { |
| 404 | struct rlimit r; |
| 405 | int ret; |
| 406 | mm_segment_t old_fs = get_fs(); |
| 407 | |
| 408 | set_fs(KERNEL_DS); |
H. Peter Anvin | dce44e0 | 2014-02-02 17:57:28 -0800 | [diff] [blame] | 409 | ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | set_fs(old_fs); |
| 411 | |
| 412 | if (!ret) { |
| 413 | if (r.rlim_cur > COMPAT_RLIM_OLD_INFINITY) |
| 414 | r.rlim_cur = COMPAT_RLIM_INFINITY; |
| 415 | if (r.rlim_max > COMPAT_RLIM_OLD_INFINITY) |
| 416 | r.rlim_max = COMPAT_RLIM_INFINITY; |
| 417 | |
| 418 | if (!access_ok(VERIFY_WRITE, rlim, sizeof(*rlim)) || |
| 419 | __put_user(r.rlim_cur, &rlim->rlim_cur) || |
| 420 | __put_user(r.rlim_max, &rlim->rlim_max)) |
| 421 | return -EFAULT; |
| 422 | } |
| 423 | return ret; |
| 424 | } |
| 425 | |
| 426 | #endif |
| 427 | |
Heiko Carstens | 62a6fa9 | 2014-03-03 16:11:13 +0100 | [diff] [blame] | 428 | COMPAT_SYSCALL_DEFINE2(getrlimit, unsigned int, resource, |
| 429 | struct compat_rlimit __user *, rlim) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | { |
| 431 | struct rlimit r; |
| 432 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
Jiri Slaby | b951834 | 2010-05-04 11:28:25 +0200 | [diff] [blame] | 434 | ret = do_prlimit(current, resource, NULL, &r); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | if (!ret) { |
| 436 | if (r.rlim_cur > COMPAT_RLIM_INFINITY) |
| 437 | r.rlim_cur = COMPAT_RLIM_INFINITY; |
| 438 | if (r.rlim_max > COMPAT_RLIM_INFINITY) |
| 439 | r.rlim_max = COMPAT_RLIM_INFINITY; |
| 440 | |
| 441 | if (!access_ok(VERIFY_WRITE, rlim, sizeof(*rlim)) || |
| 442 | __put_user(r.rlim_cur, &rlim->rlim_cur) || |
| 443 | __put_user(r.rlim_max, &rlim->rlim_max)) |
| 444 | return -EFAULT; |
| 445 | } |
| 446 | return ret; |
| 447 | } |
| 448 | |
| 449 | int put_compat_rusage(const struct rusage *r, struct compat_rusage __user *ru) |
| 450 | { |
| 451 | if (!access_ok(VERIFY_WRITE, ru, sizeof(*ru)) || |
| 452 | __put_user(r->ru_utime.tv_sec, &ru->ru_utime.tv_sec) || |
| 453 | __put_user(r->ru_utime.tv_usec, &ru->ru_utime.tv_usec) || |
| 454 | __put_user(r->ru_stime.tv_sec, &ru->ru_stime.tv_sec) || |
| 455 | __put_user(r->ru_stime.tv_usec, &ru->ru_stime.tv_usec) || |
| 456 | __put_user(r->ru_maxrss, &ru->ru_maxrss) || |
| 457 | __put_user(r->ru_ixrss, &ru->ru_ixrss) || |
| 458 | __put_user(r->ru_idrss, &ru->ru_idrss) || |
| 459 | __put_user(r->ru_isrss, &ru->ru_isrss) || |
| 460 | __put_user(r->ru_minflt, &ru->ru_minflt) || |
| 461 | __put_user(r->ru_majflt, &ru->ru_majflt) || |
| 462 | __put_user(r->ru_nswap, &ru->ru_nswap) || |
| 463 | __put_user(r->ru_inblock, &ru->ru_inblock) || |
| 464 | __put_user(r->ru_oublock, &ru->ru_oublock) || |
| 465 | __put_user(r->ru_msgsnd, &ru->ru_msgsnd) || |
| 466 | __put_user(r->ru_msgrcv, &ru->ru_msgrcv) || |
| 467 | __put_user(r->ru_nsignals, &ru->ru_nsignals) || |
| 468 | __put_user(r->ru_nvcsw, &ru->ru_nvcsw) || |
| 469 | __put_user(r->ru_nivcsw, &ru->ru_nivcsw)) |
| 470 | return -EFAULT; |
| 471 | return 0; |
| 472 | } |
| 473 | |
Al Viro | 8d9807b | 2012-12-23 14:56:40 -0500 | [diff] [blame] | 474 | COMPAT_SYSCALL_DEFINE4(wait4, |
| 475 | compat_pid_t, pid, |
| 476 | compat_uint_t __user *, stat_addr, |
| 477 | int, options, |
| 478 | struct compat_rusage __user *, ru) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | { |
| 480 | if (!ru) { |
| 481 | return sys_wait4(pid, stat_addr, options, NULL); |
| 482 | } else { |
| 483 | struct rusage r; |
| 484 | int ret; |
| 485 | unsigned int status; |
| 486 | mm_segment_t old_fs = get_fs(); |
| 487 | |
| 488 | set_fs (KERNEL_DS); |
| 489 | ret = sys_wait4(pid, |
| 490 | (stat_addr ? |
| 491 | (unsigned int __user *) &status : NULL), |
| 492 | options, (struct rusage __user *) &r); |
| 493 | set_fs (old_fs); |
| 494 | |
| 495 | if (ret > 0) { |
| 496 | if (put_compat_rusage(&r, ru)) |
| 497 | return -EFAULT; |
| 498 | if (stat_addr && put_user(status, stat_addr)) |
| 499 | return -EFAULT; |
| 500 | } |
| 501 | return ret; |
| 502 | } |
| 503 | } |
| 504 | |
Al Viro | 8d9807b | 2012-12-23 14:56:40 -0500 | [diff] [blame] | 505 | COMPAT_SYSCALL_DEFINE5(waitid, |
| 506 | int, which, compat_pid_t, pid, |
| 507 | struct compat_siginfo __user *, uinfo, int, options, |
| 508 | struct compat_rusage __user *, uru) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | { |
| 510 | siginfo_t info; |
| 511 | struct rusage ru; |
| 512 | long ret; |
| 513 | mm_segment_t old_fs = get_fs(); |
| 514 | |
| 515 | memset(&info, 0, sizeof(info)); |
| 516 | |
| 517 | set_fs(KERNEL_DS); |
| 518 | ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options, |
| 519 | uru ? (struct rusage __user *)&ru : NULL); |
| 520 | set_fs(old_fs); |
| 521 | |
| 522 | if ((ret < 0) || (info.si_signo == 0)) |
| 523 | return ret; |
| 524 | |
| 525 | if (uru) { |
Al Viro | a566c28 | 2012-12-23 23:14:49 -0500 | [diff] [blame] | 526 | /* sys_waitid() overwrites everything in ru */ |
| 527 | if (COMPAT_USE_64BIT_TIME) |
| 528 | ret = copy_to_user(uru, &ru, sizeof(ru)); |
| 529 | else |
| 530 | ret = put_compat_rusage(&ru, uru); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | if (ret) |
Dan Carpenter | bffea77 | 2013-02-21 16:41:57 -0800 | [diff] [blame] | 532 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | BUG_ON(info.si_code & __SI_MASK); |
| 536 | info.si_code |= __SI_CHLD; |
| 537 | return copy_siginfo_to_user32(uinfo, &info); |
| 538 | } |
| 539 | |
| 540 | static int compat_get_user_cpu_mask(compat_ulong_t __user *user_mask_ptr, |
Rusty Russell | a45185d | 2009-01-01 10:12:24 +1030 | [diff] [blame] | 541 | unsigned len, struct cpumask *new_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | { |
| 543 | unsigned long *k; |
| 544 | |
Rusty Russell | a45185d | 2009-01-01 10:12:24 +1030 | [diff] [blame] | 545 | if (len < cpumask_size()) |
| 546 | memset(new_mask, 0, cpumask_size()); |
| 547 | else if (len > cpumask_size()) |
| 548 | len = cpumask_size(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | |
Rusty Russell | a45185d | 2009-01-01 10:12:24 +1030 | [diff] [blame] | 550 | k = cpumask_bits(new_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | return compat_get_bitmap(k, user_mask_ptr, len * 8); |
| 552 | } |
| 553 | |
Heiko Carstens | 62a6fa9 | 2014-03-03 16:11:13 +0100 | [diff] [blame] | 554 | COMPAT_SYSCALL_DEFINE3(sched_setaffinity, compat_pid_t, pid, |
| 555 | unsigned int, len, |
| 556 | compat_ulong_t __user *, user_mask_ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | { |
Rusty Russell | a45185d | 2009-01-01 10:12:24 +1030 | [diff] [blame] | 558 | cpumask_var_t new_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | int retval; |
| 560 | |
Rusty Russell | a45185d | 2009-01-01 10:12:24 +1030 | [diff] [blame] | 561 | if (!alloc_cpumask_var(&new_mask, GFP_KERNEL)) |
| 562 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | |
Rusty Russell | a45185d | 2009-01-01 10:12:24 +1030 | [diff] [blame] | 564 | retval = compat_get_user_cpu_mask(user_mask_ptr, len, new_mask); |
| 565 | if (retval) |
| 566 | goto out; |
| 567 | |
| 568 | retval = sched_setaffinity(pid, new_mask); |
| 569 | out: |
| 570 | free_cpumask_var(new_mask); |
| 571 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Heiko Carstens | 62a6fa9 | 2014-03-03 16:11:13 +0100 | [diff] [blame] | 574 | COMPAT_SYSCALL_DEFINE3(sched_getaffinity, compat_pid_t, pid, unsigned int, len, |
| 575 | compat_ulong_t __user *, user_mask_ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | { |
| 577 | int ret; |
Rusty Russell | a45185d | 2009-01-01 10:12:24 +1030 | [diff] [blame] | 578 | cpumask_var_t mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | |
KOSAKI Motohiro | fa9dc26 | 2010-05-19 09:37:41 +0900 | [diff] [blame] | 580 | if ((len * BITS_PER_BYTE) < nr_cpu_ids) |
| 581 | return -EINVAL; |
| 582 | if (len & (sizeof(compat_ulong_t)-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | return -EINVAL; |
| 584 | |
Rusty Russell | a45185d | 2009-01-01 10:12:24 +1030 | [diff] [blame] | 585 | if (!alloc_cpumask_var(&mask, GFP_KERNEL)) |
| 586 | return -ENOMEM; |
| 587 | |
| 588 | ret = sched_getaffinity(pid, mask); |
KOSAKI Motohiro | fa9dc26 | 2010-05-19 09:37:41 +0900 | [diff] [blame] | 589 | if (ret == 0) { |
| 590 | size_t retlen = min_t(size_t, len, cpumask_size()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | |
KOSAKI Motohiro | fa9dc26 | 2010-05-19 09:37:41 +0900 | [diff] [blame] | 592 | if (compat_put_bitmap(user_mask_ptr, cpumask_bits(mask), retlen * 8)) |
| 593 | ret = -EFAULT; |
| 594 | else |
| 595 | ret = retlen; |
| 596 | } |
Rusty Russell | a45185d | 2009-01-01 10:12:24 +1030 | [diff] [blame] | 597 | free_cpumask_var(mask); |
KOSAKI Motohiro | fa9dc26 | 2010-05-19 09:37:41 +0900 | [diff] [blame] | 598 | |
Rusty Russell | a45185d | 2009-01-01 10:12:24 +1030 | [diff] [blame] | 599 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | } |
| 601 | |
Davide Libenzi | 83f5d12 | 2007-05-10 22:23:18 -0700 | [diff] [blame] | 602 | int get_compat_itimerspec(struct itimerspec *dst, |
| 603 | const struct compat_itimerspec __user *src) |
Daniel Walker | bd3a849 | 2007-10-18 03:06:09 -0700 | [diff] [blame] | 604 | { |
H. Peter Anvin | 81993e8 | 2014-02-01 18:54:11 -0800 | [diff] [blame] | 605 | if (__compat_get_timespec(&dst->it_interval, &src->it_interval) || |
| 606 | __compat_get_timespec(&dst->it_value, &src->it_value)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | return -EFAULT; |
| 608 | return 0; |
Daniel Walker | bd3a849 | 2007-10-18 03:06:09 -0700 | [diff] [blame] | 609 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | |
Davide Libenzi | 83f5d12 | 2007-05-10 22:23:18 -0700 | [diff] [blame] | 611 | int put_compat_itimerspec(struct compat_itimerspec __user *dst, |
| 612 | const struct itimerspec *src) |
Daniel Walker | bd3a849 | 2007-10-18 03:06:09 -0700 | [diff] [blame] | 613 | { |
H. Peter Anvin | 81993e8 | 2014-02-01 18:54:11 -0800 | [diff] [blame] | 614 | if (__compat_put_timespec(&src->it_interval, &dst->it_interval) || |
| 615 | __compat_put_timespec(&src->it_value, &dst->it_value)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | return -EFAULT; |
| 617 | return 0; |
Daniel Walker | bd3a849 | 2007-10-18 03:06:09 -0700 | [diff] [blame] | 618 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | |
Heiko Carstens | 62a6fa9 | 2014-03-03 16:11:13 +0100 | [diff] [blame] | 620 | COMPAT_SYSCALL_DEFINE3(timer_create, clockid_t, which_clock, |
| 621 | struct compat_sigevent __user *, timer_event_spec, |
| 622 | timer_t __user *, created_timer_id) |
Christoph Hellwig | 3a0f69d | 2006-01-09 20:52:08 -0800 | [diff] [blame] | 623 | { |
| 624 | struct sigevent __user *event = NULL; |
| 625 | |
| 626 | if (timer_event_spec) { |
| 627 | struct sigevent kevent; |
| 628 | |
| 629 | event = compat_alloc_user_space(sizeof(*event)); |
| 630 | if (get_compat_sigevent(&kevent, timer_event_spec) || |
| 631 | copy_to_user(event, &kevent, sizeof(*event))) |
| 632 | return -EFAULT; |
| 633 | } |
| 634 | |
| 635 | return sys_timer_create(which_clock, event, created_timer_id); |
| 636 | } |
| 637 | |
Heiko Carstens | 62a6fa9 | 2014-03-03 16:11:13 +0100 | [diff] [blame] | 638 | COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags, |
| 639 | struct compat_itimerspec __user *, new, |
| 640 | struct compat_itimerspec __user *, old) |
Daniel Walker | bd3a849 | 2007-10-18 03:06:09 -0700 | [diff] [blame] | 641 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | long err; |
| 643 | mm_segment_t oldfs; |
| 644 | struct itimerspec newts, oldts; |
| 645 | |
| 646 | if (!new) |
| 647 | return -EINVAL; |
| 648 | if (get_compat_itimerspec(&newts, new)) |
Daniel Walker | bd3a849 | 2007-10-18 03:06:09 -0700 | [diff] [blame] | 649 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | oldfs = get_fs(); |
| 651 | set_fs(KERNEL_DS); |
| 652 | err = sys_timer_settime(timer_id, flags, |
| 653 | (struct itimerspec __user *) &newts, |
| 654 | (struct itimerspec __user *) &oldts); |
Daniel Walker | bd3a849 | 2007-10-18 03:06:09 -0700 | [diff] [blame] | 655 | set_fs(oldfs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | if (!err && old && put_compat_itimerspec(old, &oldts)) |
| 657 | return -EFAULT; |
| 658 | return err; |
Daniel Walker | bd3a849 | 2007-10-18 03:06:09 -0700 | [diff] [blame] | 659 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | |
Heiko Carstens | 62a6fa9 | 2014-03-03 16:11:13 +0100 | [diff] [blame] | 661 | COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id, |
| 662 | struct compat_itimerspec __user *, setting) |
Daniel Walker | bd3a849 | 2007-10-18 03:06:09 -0700 | [diff] [blame] | 663 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | long err; |
| 665 | mm_segment_t oldfs; |
Daniel Walker | bd3a849 | 2007-10-18 03:06:09 -0700 | [diff] [blame] | 666 | struct itimerspec ts; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | |
| 668 | oldfs = get_fs(); |
| 669 | set_fs(KERNEL_DS); |
| 670 | err = sys_timer_gettime(timer_id, |
Daniel Walker | bd3a849 | 2007-10-18 03:06:09 -0700 | [diff] [blame] | 671 | (struct itimerspec __user *) &ts); |
| 672 | set_fs(oldfs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | if (!err && put_compat_itimerspec(setting, &ts)) |
| 674 | return -EFAULT; |
| 675 | return err; |
Daniel Walker | bd3a849 | 2007-10-18 03:06:09 -0700 | [diff] [blame] | 676 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | |
Heiko Carstens | 62a6fa9 | 2014-03-03 16:11:13 +0100 | [diff] [blame] | 678 | COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock, |
| 679 | struct compat_timespec __user *, tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | { |
| 681 | long err; |
| 682 | mm_segment_t oldfs; |
Daniel Walker | bd3a849 | 2007-10-18 03:06:09 -0700 | [diff] [blame] | 683 | struct timespec ts; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | |
H. Peter Anvin | 81993e8 | 2014-02-01 18:54:11 -0800 | [diff] [blame] | 685 | if (compat_get_timespec(&ts, tp)) |
Daniel Walker | bd3a849 | 2007-10-18 03:06:09 -0700 | [diff] [blame] | 686 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | oldfs = get_fs(); |
Daniel Walker | bd3a849 | 2007-10-18 03:06:09 -0700 | [diff] [blame] | 688 | set_fs(KERNEL_DS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | err = sys_clock_settime(which_clock, |
| 690 | (struct timespec __user *) &ts); |
| 691 | set_fs(oldfs); |
| 692 | return err; |
Daniel Walker | bd3a849 | 2007-10-18 03:06:09 -0700 | [diff] [blame] | 693 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | |
Heiko Carstens | 62a6fa9 | 2014-03-03 16:11:13 +0100 | [diff] [blame] | 695 | COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock, |
| 696 | struct compat_timespec __user *, tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | { |
| 698 | long err; |
| 699 | mm_segment_t oldfs; |
Daniel Walker | bd3a849 | 2007-10-18 03:06:09 -0700 | [diff] [blame] | 700 | struct timespec ts; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | |
| 702 | oldfs = get_fs(); |
| 703 | set_fs(KERNEL_DS); |
| 704 | err = sys_clock_gettime(which_clock, |
| 705 | (struct timespec __user *) &ts); |
| 706 | set_fs(oldfs); |
H. Peter Anvin | 81993e8 | 2014-02-01 18:54:11 -0800 | [diff] [blame] | 707 | if (!err && compat_put_timespec(&ts, tp)) |
Daniel Walker | bd3a849 | 2007-10-18 03:06:09 -0700 | [diff] [blame] | 708 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | return err; |
Daniel Walker | bd3a849 | 2007-10-18 03:06:09 -0700 | [diff] [blame] | 710 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | |
Heiko Carstens | 62a6fa9 | 2014-03-03 16:11:13 +0100 | [diff] [blame] | 712 | COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock, |
| 713 | struct compat_timespec __user *, tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | { |
| 715 | long err; |
| 716 | mm_segment_t oldfs; |
Daniel Walker | bd3a849 | 2007-10-18 03:06:09 -0700 | [diff] [blame] | 717 | struct timespec ts; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | |
| 719 | oldfs = get_fs(); |
| 720 | set_fs(KERNEL_DS); |
| 721 | err = sys_clock_getres(which_clock, |
| 722 | (struct timespec __user *) &ts); |
| 723 | set_fs(oldfs); |
H. Peter Anvin | 81993e8 | 2014-02-01 18:54:11 -0800 | [diff] [blame] | 724 | if (!err && tp && compat_put_timespec(&ts, tp)) |
Daniel Walker | bd3a849 | 2007-10-18 03:06:09 -0700 | [diff] [blame] | 725 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | return err; |
Daniel Walker | bd3a849 | 2007-10-18 03:06:09 -0700 | [diff] [blame] | 727 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | /* |
| 730 | * We currently only need the following fields from the sigevent |
| 731 | * structure: sigev_value, sigev_signo, sig_notify and (sometimes |
| 732 | * sigev_notify_thread_id). The others are handled in user mode. |
| 733 | * We also assume that copying sigev_value.sival_int is sufficient |
| 734 | * to keep all the bits of sigev_value.sival_ptr intact. |
| 735 | */ |
| 736 | int get_compat_sigevent(struct sigevent *event, |
| 737 | const struct compat_sigevent __user *u_event) |
| 738 | { |
David S. Miller | 51410d3 | 2005-04-16 15:24:01 -0700 | [diff] [blame] | 739 | memset(event, 0, sizeof(*event)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | return (!access_ok(VERIFY_READ, u_event, sizeof(*u_event)) || |
| 741 | __get_user(event->sigev_value.sival_int, |
| 742 | &u_event->sigev_value.sival_int) || |
| 743 | __get_user(event->sigev_signo, &u_event->sigev_signo) || |
| 744 | __get_user(event->sigev_notify, &u_event->sigev_notify) || |
| 745 | __get_user(event->sigev_notify_thread_id, |
| 746 | &u_event->sigev_notify_thread_id)) |
| 747 | ? -EFAULT : 0; |
| 748 | } |
| 749 | |
Stephen Rothwell | 5fa3839 | 2006-10-28 10:38:46 -0700 | [diff] [blame] | 750 | long compat_get_bitmap(unsigned long *mask, const compat_ulong_t __user *umask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | unsigned long bitmap_size) |
| 752 | { |
| 753 | int i, j; |
| 754 | unsigned long m; |
| 755 | compat_ulong_t um; |
| 756 | unsigned long nr_compat_longs; |
| 757 | |
| 758 | /* align bitmap up to nearest compat_long_t boundary */ |
| 759 | bitmap_size = ALIGN(bitmap_size, BITS_PER_COMPAT_LONG); |
| 760 | |
| 761 | if (!access_ok(VERIFY_READ, umask, bitmap_size / 8)) |
| 762 | return -EFAULT; |
| 763 | |
| 764 | nr_compat_longs = BITS_TO_COMPAT_LONGS(bitmap_size); |
| 765 | |
| 766 | for (i = 0; i < BITS_TO_LONGS(bitmap_size); i++) { |
| 767 | m = 0; |
| 768 | |
| 769 | for (j = 0; j < sizeof(m)/sizeof(um); j++) { |
| 770 | /* |
| 771 | * We dont want to read past the end of the userspace |
| 772 | * bitmap. We must however ensure the end of the |
| 773 | * kernel bitmap is zeroed. |
| 774 | */ |
Helge Deller | 9b7b819 | 2015-06-04 23:57:18 +0200 | [diff] [blame] | 775 | if (nr_compat_longs) { |
| 776 | nr_compat_longs--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | if (__get_user(um, umask)) |
| 778 | return -EFAULT; |
| 779 | } else { |
| 780 | um = 0; |
| 781 | } |
| 782 | |
| 783 | umask++; |
| 784 | m |= (long)um << (j * BITS_PER_COMPAT_LONG); |
| 785 | } |
| 786 | *mask++ = m; |
| 787 | } |
| 788 | |
| 789 | return 0; |
| 790 | } |
| 791 | |
| 792 | long compat_put_bitmap(compat_ulong_t __user *umask, unsigned long *mask, |
| 793 | unsigned long bitmap_size) |
| 794 | { |
| 795 | int i, j; |
| 796 | unsigned long m; |
| 797 | compat_ulong_t um; |
| 798 | unsigned long nr_compat_longs; |
| 799 | |
| 800 | /* align bitmap up to nearest compat_long_t boundary */ |
| 801 | bitmap_size = ALIGN(bitmap_size, BITS_PER_COMPAT_LONG); |
| 802 | |
| 803 | if (!access_ok(VERIFY_WRITE, umask, bitmap_size / 8)) |
| 804 | return -EFAULT; |
| 805 | |
| 806 | nr_compat_longs = BITS_TO_COMPAT_LONGS(bitmap_size); |
| 807 | |
| 808 | for (i = 0; i < BITS_TO_LONGS(bitmap_size); i++) { |
| 809 | m = *mask++; |
| 810 | |
| 811 | for (j = 0; j < sizeof(m)/sizeof(um); j++) { |
| 812 | um = m; |
| 813 | |
| 814 | /* |
| 815 | * We dont want to write past the end of the userspace |
| 816 | * bitmap. |
| 817 | */ |
Helge Deller | 9b7b819 | 2015-06-04 23:57:18 +0200 | [diff] [blame] | 818 | if (nr_compat_longs) { |
| 819 | nr_compat_longs--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | if (__put_user(um, umask)) |
| 821 | return -EFAULT; |
| 822 | } |
| 823 | |
| 824 | umask++; |
| 825 | m >>= 4*sizeof(um); |
| 826 | m >>= 4*sizeof(um); |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | return 0; |
| 831 | } |
| 832 | |
| 833 | void |
Al Viro | 322a56c | 2012-12-25 13:32:58 -0500 | [diff] [blame] | 834 | sigset_from_compat(sigset_t *set, const compat_sigset_t *compat) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | { |
| 836 | switch (_NSIG_WORDS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | case 4: set->sig[3] = compat->sig[6] | (((long)compat->sig[7]) << 32 ); |
| 838 | case 3: set->sig[2] = compat->sig[4] | (((long)compat->sig[5]) << 32 ); |
| 839 | case 2: set->sig[1] = compat->sig[2] | (((long)compat->sig[3]) << 32 ); |
| 840 | case 1: set->sig[0] = compat->sig[0] | (((long)compat->sig[1]) << 32 ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | } |
| 842 | } |
Alexander Graf | 1dda606 | 2011-06-08 02:45:37 +0200 | [diff] [blame] | 843 | EXPORT_SYMBOL_GPL(sigset_from_compat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | |
Al Viro | 322a56c | 2012-12-25 13:32:58 -0500 | [diff] [blame] | 845 | void |
| 846 | sigset_to_compat(compat_sigset_t *compat, const sigset_t *set) |
| 847 | { |
| 848 | switch (_NSIG_WORDS) { |
| 849 | case 4: compat->sig[7] = (set->sig[3] >> 32); compat->sig[6] = set->sig[3]; |
| 850 | case 3: compat->sig[5] = (set->sig[2] >> 32); compat->sig[4] = set->sig[2]; |
| 851 | case 2: compat->sig[3] = (set->sig[1] >> 32); compat->sig[2] = set->sig[1]; |
| 852 | case 1: compat->sig[1] = (set->sig[0] >> 32); compat->sig[0] = set->sig[0]; |
| 853 | } |
| 854 | } |
| 855 | |
Al Viro | 28d27f2 | 2012-11-25 19:32:25 -0500 | [diff] [blame] | 856 | COMPAT_SYSCALL_DEFINE4(rt_sigtimedwait, compat_sigset_t __user *, uthese, |
| 857 | struct compat_siginfo __user *, uinfo, |
| 858 | struct compat_timespec __user *, uts, compat_size_t, sigsetsize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | { |
| 860 | compat_sigset_t s32; |
| 861 | sigset_t s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | struct timespec t; |
| 863 | siginfo_t info; |
Oleg Nesterov | 943df14 | 2011-04-27 21:44:14 +0200 | [diff] [blame] | 864 | long ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | |
| 866 | if (sigsetsize != sizeof(sigset_t)) |
| 867 | return -EINVAL; |
| 868 | |
| 869 | if (copy_from_user(&s32, uthese, sizeof(compat_sigset_t))) |
| 870 | return -EFAULT; |
| 871 | sigset_from_compat(&s, &s32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | |
| 873 | if (uts) { |
Al Viro | b2ddedc | 2012-12-24 12:31:00 -0500 | [diff] [blame] | 874 | if (compat_get_timespec(&t, uts)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | } |
| 877 | |
Oleg Nesterov | 943df14 | 2011-04-27 21:44:14 +0200 | [diff] [blame] | 878 | ret = do_sigtimedwait(&s, &info, uts ? &t : NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | |
Oleg Nesterov | 943df14 | 2011-04-27 21:44:14 +0200 | [diff] [blame] | 880 | if (ret > 0 && uinfo) { |
| 881 | if (copy_siginfo_to_user32(uinfo, &info)) |
| 882 | ret = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | return ret; |
Thomas Gleixner | 62ab450 | 2009-04-04 21:01:06 +0000 | [diff] [blame] | 886 | } |
| 887 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | #ifdef __ARCH_WANT_COMPAT_SYS_TIME |
| 889 | |
| 890 | /* compat_time_t is a 32 bit "long" and needs to get converted. */ |
| 891 | |
Heiko Carstens | 62a6fa9 | 2014-03-03 16:11:13 +0100 | [diff] [blame] | 892 | COMPAT_SYSCALL_DEFINE1(time, compat_time_t __user *, tloc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | { |
| 894 | compat_time_t i; |
| 895 | struct timeval tv; |
| 896 | |
| 897 | do_gettimeofday(&tv); |
| 898 | i = tv.tv_sec; |
| 899 | |
| 900 | if (tloc) { |
| 901 | if (put_user(i,tloc)) |
Paul Mackerras | e3d5a27 | 2009-01-06 14:41:02 -0800 | [diff] [blame] | 902 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | } |
Paul Mackerras | e3d5a27 | 2009-01-06 14:41:02 -0800 | [diff] [blame] | 904 | force_successful_syscall_return(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | return i; |
| 906 | } |
| 907 | |
Heiko Carstens | 62a6fa9 | 2014-03-03 16:11:13 +0100 | [diff] [blame] | 908 | COMPAT_SYSCALL_DEFINE1(stime, compat_time_t __user *, tptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | { |
| 910 | struct timespec tv; |
| 911 | int err; |
| 912 | |
| 913 | if (get_user(tv.tv_sec, tptr)) |
| 914 | return -EFAULT; |
| 915 | |
| 916 | tv.tv_nsec = 0; |
| 917 | |
| 918 | err = security_settime(&tv, NULL); |
| 919 | if (err) |
| 920 | return err; |
| 921 | |
| 922 | do_settimeofday(&tv); |
| 923 | return 0; |
| 924 | } |
| 925 | |
| 926 | #endif /* __ARCH_WANT_COMPAT_SYS_TIME */ |
David Woodhouse | 150256d | 2006-01-18 17:43:57 -0800 | [diff] [blame] | 927 | |
Christoph Lameter | 1b2db9f | 2006-06-23 02:03:56 -0700 | [diff] [blame] | 928 | #ifdef CONFIG_NUMA |
Heiko Carstens | 2f2728f | 2014-03-04 17:18:23 +0100 | [diff] [blame] | 929 | COMPAT_SYSCALL_DEFINE6(move_pages, pid_t, pid, compat_ulong_t, nr_pages, |
| 930 | compat_uptr_t __user *, pages32, |
| 931 | const int __user *, nodes, |
| 932 | int __user *, status, |
| 933 | int, flags) |
Christoph Lameter | 1b2db9f | 2006-06-23 02:03:56 -0700 | [diff] [blame] | 934 | { |
| 935 | const void __user * __user *pages; |
| 936 | int i; |
| 937 | |
| 938 | pages = compat_alloc_user_space(nr_pages * sizeof(void *)); |
| 939 | for (i = 0; i < nr_pages; i++) { |
| 940 | compat_uptr_t p; |
| 941 | |
Christoph Lameter | 9216dfa | 2006-06-23 02:03:57 -0700 | [diff] [blame] | 942 | if (get_user(p, pages32 + i) || |
Christoph Lameter | 1b2db9f | 2006-06-23 02:03:56 -0700 | [diff] [blame] | 943 | put_user(compat_ptr(p), pages + i)) |
| 944 | return -EFAULT; |
| 945 | } |
| 946 | return sys_move_pages(pid, nr_pages, pages, nodes, status, flags); |
| 947 | } |
Stephen Rothwell | 3fd5939 | 2006-11-02 22:07:24 -0800 | [diff] [blame] | 948 | |
Heiko Carstens | 62a6fa9 | 2014-03-03 16:11:13 +0100 | [diff] [blame] | 949 | COMPAT_SYSCALL_DEFINE4(migrate_pages, compat_pid_t, pid, |
| 950 | compat_ulong_t, maxnode, |
| 951 | const compat_ulong_t __user *, old_nodes, |
| 952 | const compat_ulong_t __user *, new_nodes) |
Stephen Rothwell | 3fd5939 | 2006-11-02 22:07:24 -0800 | [diff] [blame] | 953 | { |
| 954 | unsigned long __user *old = NULL; |
| 955 | unsigned long __user *new = NULL; |
| 956 | nodemask_t tmp_mask; |
| 957 | unsigned long nr_bits; |
| 958 | unsigned long size; |
| 959 | |
| 960 | nr_bits = min_t(unsigned long, maxnode - 1, MAX_NUMNODES); |
| 961 | size = ALIGN(nr_bits, BITS_PER_LONG) / 8; |
| 962 | if (old_nodes) { |
| 963 | if (compat_get_bitmap(nodes_addr(tmp_mask), old_nodes, nr_bits)) |
| 964 | return -EFAULT; |
| 965 | old = compat_alloc_user_space(new_nodes ? size * 2 : size); |
| 966 | if (new_nodes) |
| 967 | new = old + size / sizeof(unsigned long); |
| 968 | if (copy_to_user(old, nodes_addr(tmp_mask), size)) |
| 969 | return -EFAULT; |
| 970 | } |
| 971 | if (new_nodes) { |
| 972 | if (compat_get_bitmap(nodes_addr(tmp_mask), new_nodes, nr_bits)) |
| 973 | return -EFAULT; |
| 974 | if (new == NULL) |
| 975 | new = compat_alloc_user_space(size); |
| 976 | if (copy_to_user(new, nodes_addr(tmp_mask), size)) |
| 977 | return -EFAULT; |
| 978 | } |
| 979 | return sys_migrate_pages(pid, nr_bits + 1, old, new); |
| 980 | } |
Christoph Lameter | 1b2db9f | 2006-06-23 02:03:56 -0700 | [diff] [blame] | 981 | #endif |
Kyle McMartin | d4d23ad | 2007-02-10 01:46:00 -0800 | [diff] [blame] | 982 | |
Al Viro | 6883da8 | 2012-12-25 16:59:28 -0500 | [diff] [blame] | 983 | COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval, |
| 984 | compat_pid_t, pid, |
| 985 | struct compat_timespec __user *, interval) |
Catalin Marinas | 0ad50c3 | 2012-12-17 16:01:45 -0800 | [diff] [blame] | 986 | { |
| 987 | struct timespec t; |
| 988 | int ret; |
| 989 | mm_segment_t old_fs = get_fs(); |
| 990 | |
| 991 | set_fs(KERNEL_DS); |
| 992 | ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t); |
| 993 | set_fs(old_fs); |
H. Peter Anvin | 81993e8 | 2014-02-01 18:54:11 -0800 | [diff] [blame] | 994 | if (compat_put_timespec(&t, interval)) |
Catalin Marinas | 0ad50c3 | 2012-12-17 16:01:45 -0800 | [diff] [blame] | 995 | return -EFAULT; |
| 996 | return ret; |
| 997 | } |
Catalin Marinas | 0ad50c3 | 2012-12-17 16:01:45 -0800 | [diff] [blame] | 998 | |
H. Peter Anvin | c41d68a | 2010-09-07 16:16:18 -0700 | [diff] [blame] | 999 | /* |
| 1000 | * Allocate user-space memory for the duration of a single system call, |
| 1001 | * in order to marshall parameters inside a compat thunk. |
| 1002 | */ |
| 1003 | void __user *compat_alloc_user_space(unsigned long len) |
| 1004 | { |
| 1005 | void __user *ptr; |
| 1006 | |
| 1007 | /* If len would occupy more than half of the entire compat space... */ |
| 1008 | if (unlikely(len > (((compat_uptr_t)~0) >> 1))) |
| 1009 | return NULL; |
| 1010 | |
| 1011 | ptr = arch_compat_alloc_user_space(len); |
| 1012 | |
| 1013 | if (unlikely(!access_ok(VERIFY_WRITE, ptr, len))) |
| 1014 | return NULL; |
| 1015 | |
| 1016 | return ptr; |
| 1017 | } |
| 1018 | EXPORT_SYMBOL_GPL(compat_alloc_user_space); |