1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_COMPAT_H
3 #define _LINUX_COMPAT_H
4 /*
5 * These are the type definitions for the architecture specific
6 * syscall compatibility layer.
7 */
8
9 #include <linux/types.h>
10 #include <linux/time.h>
11
12 #include <linux/stat.h>
13 #include <linux/param.h> /* for HZ */
14 #include <linux/sem.h>
15 #include <linux/socket.h>
16 #include <linux/if.h>
17 #include <linux/fs.h>
18 #include <linux/aio_abi.h> /* for aio_context_t */
19 #include <linux/uaccess.h>
20 #include <linux/unistd.h>
21
22 #include <asm/compat.h>
23 #include <asm/siginfo.h>
24 #include <asm/signal.h>
25
26 #ifdef CONFIG_ARCH_HAS_SYSCALL_WRAPPER
27 /*
28 * It may be useful for an architecture to override the definitions of the
29 * COMPAT_SYSCALL_DEFINE0 and COMPAT_SYSCALL_DEFINEx() macros, in particular
30 * to use a different calling convention for syscalls. To allow for that,
31 + the prototypes for the compat_sys_*() functions below will *not* be included
32 * if CONFIG_ARCH_HAS_SYSCALL_WRAPPER is enabled.
33 */
34 #include <asm/syscall_wrapper.h>
35 #endif /* CONFIG_ARCH_HAS_SYSCALL_WRAPPER */
36
37 #ifndef COMPAT_USE_64BIT_TIME
38 #define COMPAT_USE_64BIT_TIME 0
39 #endif
40
41 #ifndef __SC_DELOUSE
42 #define __SC_DELOUSE(t,v) ((__force t)(unsigned long)(v))
43 #endif
44
45 #ifndef COMPAT_SYSCALL_DEFINE0
46 #define COMPAT_SYSCALL_DEFINE0(name) \
47 asmlinkage long compat_sys_##name(void); \
48 ALLOW_ERROR_INJECTION(compat_sys_##name, ERRNO); \
49 asmlinkage long compat_sys_##name(void)
50 #endif /* COMPAT_SYSCALL_DEFINE0 */
51
52 #define COMPAT_SYSCALL_DEFINE1(name, ...) \
53 COMPAT_SYSCALL_DEFINEx(1, _##name, __VA_ARGS__)
54 #define COMPAT_SYSCALL_DEFINE2(name, ...) \
55 COMPAT_SYSCALL_DEFINEx(2, _##name, __VA_ARGS__)
56 #define COMPAT_SYSCALL_DEFINE3(name, ...) \
57 COMPAT_SYSCALL_DEFINEx(3, _##name, __VA_ARGS__)
58 #define COMPAT_SYSCALL_DEFINE4(name, ...) \
59 COMPAT_SYSCALL_DEFINEx(4, _##name, __VA_ARGS__)
60 #define COMPAT_SYSCALL_DEFINE5(name, ...) \
61 COMPAT_SYSCALL_DEFINEx(5, _##name, __VA_ARGS__)
62 #define COMPAT_SYSCALL_DEFINE6(name, ...) \
63 COMPAT_SYSCALL_DEFINEx(6, _##name, __VA_ARGS__)
64
65 /*
66 * The asmlinkage stub is aliased to a function named __se_compat_sys_*() which
67 * sign-extends 32-bit ints to longs whenever needed. The actual work is
68 * done within __do_compat_sys_*().
69 */
70 #ifndef COMPAT_SYSCALL_DEFINEx
71 #define COMPAT_SYSCALL_DEFINEx(x, name, ...) \
72 __diag_push(); \
73 __diag_ignore(GCC, 8, "-Wattribute-alias", \
74 "Type aliasing is used to sanitize syscall arguments");\
75 __diag_ignore(clang, 23, "-Wunknown-warning-option", \
76 "Avoid breaking versions without -Wattribute-alias"); \
77 __diag_ignore(clang, 23, "-Wattribute-alias", \
78 "Type aliasing is used to sanitize syscall arguments"); \
79 asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) \
80 __attribute__((alias(__stringify(__se_compat_sys##name)))); \
81 ALLOW_ERROR_INJECTION(compat_sys##name, ERRNO); \
82 static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));\
83 asmlinkage long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)); \
84 asmlinkage long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \
85 { \
86 long ret = __do_compat_sys##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__));\
87 __MAP(x,__SC_TEST,__VA_ARGS__); \
88 return ret; \
89 } \
90 __diag_pop(); \
91 static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))
92 #endif /* COMPAT_SYSCALL_DEFINEx */
93
94 struct compat_iovec {
95 compat_uptr_t iov_base;
96 compat_size_t iov_len;
97 };
98
99 #ifndef compat_user_stack_pointer
100 #define compat_user_stack_pointer() current_user_stack_pointer()
101 #endif
102 #ifndef compat_sigaltstack /* we'll need that for MIPS */
103 typedef struct compat_sigaltstack {
104 compat_uptr_t ss_sp;
105 int ss_flags;
106 compat_size_t ss_size;
107 } compat_stack_t;
108 #endif
109 #ifndef COMPAT_MINSIGSTKSZ
110 #define COMPAT_MINSIGSTKSZ MINSIGSTKSZ
111 #endif
112
113 #define compat_jiffies_to_clock_t(x) \
114 (((unsigned long)(x) * COMPAT_USER_HZ) / HZ)
115
116 typedef __compat_uid32_t compat_uid_t;
117 typedef __compat_gid32_t compat_gid_t;
118
119 struct compat_sel_arg_struct;
120 struct rusage;
121
122 struct old_itimerval32;
123
124 struct compat_tms {
125 compat_clock_t tms_utime;
126 compat_clock_t tms_stime;
127 compat_clock_t tms_cutime;
128 compat_clock_t tms_cstime;
129 };
130
131 #define _COMPAT_NSIG_WORDS (_COMPAT_NSIG / _COMPAT_NSIG_BPW)
132
133 typedef struct {
134 compat_sigset_word sig[_COMPAT_NSIG_WORDS];
135 } compat_sigset_t;
136
137 int set_compat_user_sigmask(const compat_sigset_t __user *umask,
138 size_t sigsetsize);
139
140 struct compat_sigaction {
141 #ifndef __ARCH_HAS_IRIX_SIGACTION
142 compat_uptr_t sa_handler;
143 compat_ulong_t sa_flags;
144 #else
145 compat_uint_t sa_flags;
146 compat_uptr_t sa_handler;
147 #endif
148 #ifdef __ARCH_HAS_SA_RESTORER
149 compat_uptr_t sa_restorer;
150 #endif
151 compat_sigset_t sa_mask __packed;
152 };
153
154 typedef union compat_sigval {
155 compat_int_t sival_int;
156 compat_uptr_t sival_ptr;
157 } compat_sigval_t;
158
159 typedef struct compat_siginfo {
160 int si_signo;
161 #ifndef __ARCH_HAS_SWAPPED_SIGINFO
162 int si_errno;
163 int si_code;
164 #else
165 int si_code;
166 int si_errno;
167 #endif
168
169 union {
170 int _pad[128/sizeof(int) - 3];
171
172 /* kill() */
173 struct {
174 compat_pid_t _pid; /* sender's pid */
175 __compat_uid32_t _uid; /* sender's uid */
176 } _kill;
177
178 /* POSIX.1b timers */
179 struct {
180 compat_timer_t _tid; /* timer id */
181 int _overrun; /* overrun count */
182 compat_sigval_t _sigval; /* same as below */
183 } _timer;
184
185 /* POSIX.1b signals */
186 struct {
187 compat_pid_t _pid; /* sender's pid */
188 __compat_uid32_t _uid; /* sender's uid */
189 compat_sigval_t _sigval;
190 } _rt;
191
192 /* SIGCHLD */
193 struct {
194 compat_pid_t _pid; /* which child */
195 __compat_uid32_t _uid; /* sender's uid */
196 int _status; /* exit code */
197 compat_clock_t _utime;
198 compat_clock_t _stime;
199 } _sigchld;
200
201 #ifdef CONFIG_X86_X32_ABI
202 /* SIGCHLD (x32 version) */
203 struct {
204 compat_pid_t _pid; /* which child */
205 __compat_uid32_t _uid; /* sender's uid */
206 int _status; /* exit code */
207 compat_s64 _utime;
208 compat_s64 _stime;
209 } _sigchld_x32;
210 #endif
211
212 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */
213 struct {
214 compat_uptr_t _addr; /* faulting insn/memory ref. */
215 #define __COMPAT_ADDR_BND_PKEY_PAD (__alignof__(compat_uptr_t) < sizeof(short) ? \
216 sizeof(short) : __alignof__(compat_uptr_t))
217 union {
218 /* used on alpha and sparc */
219 int _trapno; /* TRAP # which caused the signal */
220 /*
221 * used when si_code=BUS_MCEERR_AR or
222 * used when si_code=BUS_MCEERR_AO
223 */
224 short int _addr_lsb; /* Valid LSB of the reported address. */
225 /* used when si_code=SEGV_BNDERR */
226 struct {
227 char _dummy_bnd[__COMPAT_ADDR_BND_PKEY_PAD];
228 compat_uptr_t _lower;
229 compat_uptr_t _upper;
230 } _addr_bnd;
231 /* used when si_code=SEGV_PKUERR */
232 struct {
233 char _dummy_pkey[__COMPAT_ADDR_BND_PKEY_PAD];
234 u32 _pkey;
235 } _addr_pkey;
236 /* used when si_code=TRAP_PERF */
237 struct {
238 compat_ulong_t _data;
239 u32 _type;
240 u32 _flags;
241 } _perf;
242 };
243 } _sigfault;
244
245 /* SIGPOLL */
246 struct {
247 compat_long_t _band; /* POLL_IN, POLL_OUT, POLL_MSG */
248 int _fd;
249 } _sigpoll;
250
251 struct {
252 compat_uptr_t _call_addr; /* calling user insn */
253 int _syscall; /* triggering system call number */
254 unsigned int _arch; /* AUDIT_ARCH_* of syscall */
255 } _sigsys;
256 } _sifields;
257 } compat_siginfo_t;
258
259 struct compat_rlimit {
260 compat_ulong_t rlim_cur;
261 compat_ulong_t rlim_max;
262 };
263
264 #ifdef __ARCH_NEED_COMPAT_FLOCK64_PACKED
265 #define __ARCH_COMPAT_FLOCK64_PACK __attribute__((packed))
266 #else
267 #define __ARCH_COMPAT_FLOCK64_PACK
268 #endif
269
270 struct compat_flock {
271 short l_type;
272 short l_whence;
273 compat_off_t l_start;
274 compat_off_t l_len;
275 #ifdef __ARCH_COMPAT_FLOCK_EXTRA_SYSID
276 __ARCH_COMPAT_FLOCK_EXTRA_SYSID
277 #endif
278 compat_pid_t l_pid;
279 #ifdef __ARCH_COMPAT_FLOCK_PAD
280 __ARCH_COMPAT_FLOCK_PAD
281 #endif
282 };
283
284 struct compat_flock64 {
285 short l_type;
286 short l_whence;
287 compat_loff_t l_start;
288 compat_loff_t l_len;
289 compat_pid_t l_pid;
290 #ifdef __ARCH_COMPAT_FLOCK64_PAD
291 __ARCH_COMPAT_FLOCK64_PAD
292 #endif
293 } __ARCH_COMPAT_FLOCK64_PACK;
294
295 struct compat_rusage {
296 struct old_timeval32 ru_utime;
297 struct old_timeval32 ru_stime;
298 compat_long_t ru_maxrss;
299 compat_long_t ru_ixrss;
300 compat_long_t ru_idrss;
301 compat_long_t ru_isrss;
302 compat_long_t ru_minflt;
303 compat_long_t ru_majflt;
304 compat_long_t ru_nswap;
305 compat_long_t ru_inblock;
306 compat_long_t ru_oublock;
307 compat_long_t ru_msgsnd;
308 compat_long_t ru_msgrcv;
309 compat_long_t ru_nsignals;
310 compat_long_t ru_nvcsw;
311 compat_long_t ru_nivcsw;
312 };
313
314 extern int put_compat_rusage(const struct rusage *,
315 struct compat_rusage __user *);
316
317 struct compat_siginfo;
318 struct __compat_aio_sigset;
319
320 struct compat_dirent {
321 u32 d_ino;
322 compat_off_t d_off;
323 u16 d_reclen;
324 char d_name[256];
325 };
326
327 struct compat_ustat {
328 compat_daddr_t f_tfree;
329 compat_ino_t f_tinode;
330 char f_fname[6];
331 char f_fpack[6];
332 };
333
334 #define COMPAT_SIGEV_PAD_SIZE ((SIGEV_MAX_SIZE/sizeof(int)) - 3)
335
336 typedef struct compat_sigevent {
337 compat_sigval_t sigev_value;
338 compat_int_t sigev_signo;
339 compat_int_t sigev_notify;
340 union {
341 compat_int_t _pad[COMPAT_SIGEV_PAD_SIZE];
342 compat_int_t _tid;
343
344 struct {
345 compat_uptr_t _function;
346 compat_uptr_t _attribute;
347 } _sigev_thread;
348 } _sigev_un;
349 } compat_sigevent_t;
350
351 struct compat_ifmap {
352 compat_ulong_t mem_start;
353 compat_ulong_t mem_end;
354 unsigned short base_addr;
355 unsigned char irq;
356 unsigned char dma;
357 unsigned char port;
358 };
359
360 struct compat_if_settings {
361 unsigned int type; /* Type of physical device or protocol */
362 unsigned int size; /* Size of the data allocated by the caller */
363 compat_uptr_t ifs_ifsu; /* union of pointers */
364 };
365
366 struct compat_ifreq {
367 union {
368 char ifrn_name[IFNAMSIZ]; /* if name, e.g. "en0" */
369 } ifr_ifrn;
370 union {
371 struct sockaddr ifru_addr;
372 struct sockaddr ifru_dstaddr;
373 struct sockaddr ifru_broadaddr;
374 struct sockaddr ifru_netmask;
375 struct sockaddr ifru_hwaddr;
376 short ifru_flags;
377 compat_int_t ifru_ivalue;
378 compat_int_t ifru_mtu;
379 struct compat_ifmap ifru_map;
380 char ifru_slave[IFNAMSIZ]; /* Just fits the size */
381 char ifru_newname[IFNAMSIZ];
382 compat_caddr_t ifru_data;
383 struct compat_if_settings ifru_settings;
384 } ifr_ifru;
385 };
386
387 struct compat_ifconf {
388 compat_int_t ifc_len; /* size of buffer */
389 compat_caddr_t ifcbuf;
390 };
391
392 struct compat_robust_list {
393 compat_uptr_t next;
394 };
395
396 struct compat_robust_list_head {
397 struct compat_robust_list list;
398 compat_long_t futex_offset;
399 compat_uptr_t list_op_pending;
400 };
401
402 #ifdef CONFIG_COMPAT_OLD_SIGACTION
403 struct compat_old_sigaction {
404 compat_uptr_t sa_handler;
405 compat_old_sigset_t sa_mask;
406 compat_ulong_t sa_flags;
407 compat_uptr_t sa_restorer;
408 };
409 #endif
410
411 struct compat_keyctl_kdf_params {
412 compat_uptr_t hashname;
413 compat_uptr_t otherinfo;
414 __u32 otherinfolen;
415 __u32 __spare[8];
416 };
417
418 struct compat_stat;
419 struct compat_statfs;
420 struct compat_statfs64;
421 struct compat_old_linux_dirent;
422 struct compat_linux_dirent;
423 struct linux_dirent64;
424 struct compat_msghdr;
425 struct compat_mmsghdr;
426 struct compat_sysinfo;
427 struct compat_sysctl_args;
428 struct compat_kexec_segment;
429 struct compat_mq_attr;
430 struct compat_msgbuf;
431
432 void copy_siginfo_to_external32(struct compat_siginfo *to,
433 const struct kernel_siginfo *from);
434 int copy_siginfo_from_user32(kernel_siginfo_t *to,
435 const struct compat_siginfo __user *from);
436 int __copy_siginfo_to_user32(struct compat_siginfo __user *to,
437 const kernel_siginfo_t *from);
438 #ifndef copy_siginfo_to_user32
439 #define copy_siginfo_to_user32 __copy_siginfo_to_user32
440 #endif
441 int get_compat_sigevent(struct sigevent *event,
442 const struct compat_sigevent __user *u_event);
443
444 extern int get_compat_sigset(sigset_t *set, const compat_sigset_t __user *compat);
445
446 /*
447 * Defined inline such that size can be compile time constant, which avoids
448 * CONFIG_HARDENED_USERCOPY complaining about copies from task_struct
449 */
450 static inline int
put_compat_sigset(compat_sigset_t __user * compat,const sigset_t * set,unsigned int size)451 put_compat_sigset(compat_sigset_t __user *compat, const sigset_t *set,
452 unsigned int size)
453 {
454 /* size <= sizeof(compat_sigset_t) <= sizeof(sigset_t) */
455 #if defined(__BIG_ENDIAN) && defined(CONFIG_64BIT)
456 compat_sigset_t v;
457 switch (_NSIG_WORDS) {
458 case 4: v.sig[7] = (set->sig[3] >> 32); v.sig[6] = set->sig[3];
459 fallthrough;
460 case 3: v.sig[5] = (set->sig[2] >> 32); v.sig[4] = set->sig[2];
461 fallthrough;
462 case 2: v.sig[3] = (set->sig[1] >> 32); v.sig[2] = set->sig[1];
463 fallthrough;
464 case 1: v.sig[1] = (set->sig[0] >> 32); v.sig[0] = set->sig[0];
465 }
466 return copy_to_user(compat, &v, size) ? -EFAULT : 0;
467 #else
468 return copy_to_user(compat, set, size) ? -EFAULT : 0;
469 #endif
470 }
471
472 #ifdef CONFIG_CPU_BIG_ENDIAN
473 #define unsafe_put_compat_sigset(compat, set, label) do { \
474 compat_sigset_t __user *__c = compat; \
475 const sigset_t *__s = set; \
476 \
477 switch (_NSIG_WORDS) { \
478 case 4: \
479 unsafe_put_user(__s->sig[3] >> 32, &__c->sig[7], label); \
480 unsafe_put_user(__s->sig[3], &__c->sig[6], label); \
481 fallthrough; \
482 case 3: \
483 unsafe_put_user(__s->sig[2] >> 32, &__c->sig[5], label); \
484 unsafe_put_user(__s->sig[2], &__c->sig[4], label); \
485 fallthrough; \
486 case 2: \
487 unsafe_put_user(__s->sig[1] >> 32, &__c->sig[3], label); \
488 unsafe_put_user(__s->sig[1], &__c->sig[2], label); \
489 fallthrough; \
490 case 1: \
491 unsafe_put_user(__s->sig[0] >> 32, &__c->sig[1], label); \
492 unsafe_put_user(__s->sig[0], &__c->sig[0], label); \
493 } \
494 } while (0)
495
496 #define unsafe_get_compat_sigset(set, compat, label) do { \
497 const compat_sigset_t __user *__c = compat; \
498 compat_sigset_word hi, lo; \
499 sigset_t *__s = set; \
500 \
501 switch (_NSIG_WORDS) { \
502 case 4: \
503 unsafe_get_user(lo, &__c->sig[7], label); \
504 unsafe_get_user(hi, &__c->sig[6], label); \
505 __s->sig[3] = hi | (((long)lo) << 32); \
506 fallthrough; \
507 case 3: \
508 unsafe_get_user(lo, &__c->sig[5], label); \
509 unsafe_get_user(hi, &__c->sig[4], label); \
510 __s->sig[2] = hi | (((long)lo) << 32); \
511 fallthrough; \
512 case 2: \
513 unsafe_get_user(lo, &__c->sig[3], label); \
514 unsafe_get_user(hi, &__c->sig[2], label); \
515 __s->sig[1] = hi | (((long)lo) << 32); \
516 fallthrough; \
517 case 1: \
518 unsafe_get_user(lo, &__c->sig[1], label); \
519 unsafe_get_user(hi, &__c->sig[0], label); \
520 __s->sig[0] = hi | (((long)lo) << 32); \
521 } \
522 } while (0)
523 #else
524 #define unsafe_put_compat_sigset(compat, set, label) do { \
525 compat_sigset_t __user *__c = compat; \
526 const sigset_t *__s = set; \
527 \
528 unsafe_copy_to_user(__c, __s, sizeof(*__c), label); \
529 } while (0)
530
531 #define unsafe_get_compat_sigset(set, compat, label) do { \
532 const compat_sigset_t __user *__c = compat; \
533 sigset_t *__s = set; \
534 \
535 unsafe_copy_from_user(__s, __c, sizeof(*__c), label); \
536 } while (0)
537 #endif
538
539 extern int compat_ptrace_request(struct task_struct *child,
540 compat_long_t request,
541 compat_ulong_t addr, compat_ulong_t data);
542
543 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
544 compat_ulong_t addr, compat_ulong_t data);
545
546 struct epoll_event; /* fortunately, this one is fixed-layout */
547
548 int compat_restore_altstack(const compat_stack_t __user *uss);
549 int __compat_save_altstack(compat_stack_t __user *, unsigned long);
550 #define unsafe_compat_save_altstack(uss, sp, label) do { \
551 compat_stack_t __user *__uss = uss; \
552 struct task_struct *t = current; \
553 unsafe_put_user(ptr_to_compat((void __user *)t->sas_ss_sp), \
554 &__uss->ss_sp, label); \
555 unsafe_put_user(t->sas_ss_flags, &__uss->ss_flags, label); \
556 unsafe_put_user(t->sas_ss_size, &__uss->ss_size, label); \
557 } while (0);
558
559 /*
560 * These syscall function prototypes are kept in the same order as
561 * include/uapi/asm-generic/unistd.h. Deprecated or obsolete system calls
562 * go below.
563 *
564 * Please note that these prototypes here are only provided for information
565 * purposes, for static analysis, and for linking from the syscall table.
566 * These functions should not be called elsewhere from kernel code.
567 *
568 * As the syscall calling convention may be different from the default
569 * for architectures overriding the syscall calling convention, do not
570 * include the prototypes if CONFIG_ARCH_HAS_SYSCALL_WRAPPER is enabled.
571 */
572 #ifndef CONFIG_ARCH_HAS_SYSCALL_WRAPPER
573 asmlinkage long compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p);
574 asmlinkage long compat_sys_io_submit(compat_aio_context_t ctx_id, int nr,
575 u32 __user *iocb);
576 asmlinkage long compat_sys_io_pgetevents(compat_aio_context_t ctx_id,
577 compat_long_t min_nr,
578 compat_long_t nr,
579 struct io_event __user *events,
580 struct old_timespec32 __user *timeout,
581 const struct __compat_aio_sigset __user *usig);
582 asmlinkage long compat_sys_io_pgetevents_time64(compat_aio_context_t ctx_id,
583 compat_long_t min_nr,
584 compat_long_t nr,
585 struct io_event __user *events,
586 struct __kernel_timespec __user *timeout,
587 const struct __compat_aio_sigset __user *usig);
588 asmlinkage long compat_sys_epoll_pwait(int epfd,
589 struct epoll_event __user *events,
590 int maxevents, int timeout,
591 const compat_sigset_t __user *sigmask,
592 compat_size_t sigsetsize);
593 asmlinkage long compat_sys_epoll_pwait2(int epfd,
594 struct epoll_event __user *events,
595 int maxevents,
596 const struct __kernel_timespec __user *timeout,
597 const compat_sigset_t __user *sigmask,
598 compat_size_t sigsetsize);
599 asmlinkage long compat_sys_fcntl(unsigned int fd, unsigned int cmd,
600 compat_ulong_t arg);
601 asmlinkage long compat_sys_fcntl64(unsigned int fd, unsigned int cmd,
602 compat_ulong_t arg);
603 asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
604 compat_ulong_t arg);
605 asmlinkage long compat_sys_statfs(const char __user *pathname,
606 struct compat_statfs __user *buf);
607 asmlinkage long compat_sys_statfs64(const char __user *pathname,
608 compat_size_t sz,
609 struct compat_statfs64 __user *buf);
610 asmlinkage long compat_sys_fstatfs(unsigned int fd,
611 struct compat_statfs __user *buf);
612 asmlinkage long compat_sys_fstatfs64(unsigned int fd, compat_size_t sz,
613 struct compat_statfs64 __user *buf);
614 asmlinkage long compat_sys_truncate(const char __user *, compat_off_t);
615 asmlinkage long compat_sys_ftruncate(unsigned int, compat_off_t);
616 /* No generic prototype for truncate64, ftruncate64, fallocate */
617 asmlinkage long compat_sys_openat(int dfd, const char __user *filename,
618 int flags, umode_t mode);
619 asmlinkage long compat_sys_getdents(unsigned int fd,
620 struct compat_linux_dirent __user *dirent,
621 unsigned int count);
622 asmlinkage long compat_sys_lseek(unsigned int, compat_off_t, unsigned int);
623 /* No generic prototype for pread64 and pwrite64 */
624 asmlinkage ssize_t compat_sys_preadv(compat_ulong_t fd,
625 const struct iovec __user *vec,
626 compat_ulong_t vlen, u32 pos_low, u32 pos_high);
627 asmlinkage ssize_t compat_sys_pwritev(compat_ulong_t fd,
628 const struct iovec __user *vec,
629 compat_ulong_t vlen, u32 pos_low, u32 pos_high);
630 #ifdef __ARCH_WANT_COMPAT_SYS_PREADV64
631 asmlinkage long compat_sys_preadv64(unsigned long fd,
632 const struct iovec __user *vec,
633 unsigned long vlen, loff_t pos);
634 #endif
635
636 #ifdef __ARCH_WANT_COMPAT_SYS_PWRITEV64
637 asmlinkage long compat_sys_pwritev64(unsigned long fd,
638 const struct iovec __user *vec,
639 unsigned long vlen, loff_t pos);
640 #endif
641 asmlinkage long compat_sys_sendfile(int out_fd, int in_fd,
642 compat_off_t __user *offset, compat_size_t count);
643 asmlinkage long compat_sys_sendfile64(int out_fd, int in_fd,
644 compat_loff_t __user *offset, compat_size_t count);
645 asmlinkage long compat_sys_pselect6_time32(int n, compat_ulong_t __user *inp,
646 compat_ulong_t __user *outp,
647 compat_ulong_t __user *exp,
648 struct old_timespec32 __user *tsp,
649 void __user *sig);
650 asmlinkage long compat_sys_pselect6_time64(int n, compat_ulong_t __user *inp,
651 compat_ulong_t __user *outp,
652 compat_ulong_t __user *exp,
653 struct __kernel_timespec __user *tsp,
654 void __user *sig);
655 asmlinkage long compat_sys_ppoll_time32(struct pollfd __user *ufds,
656 unsigned int nfds,
657 struct old_timespec32 __user *tsp,
658 const compat_sigset_t __user *sigmask,
659 compat_size_t sigsetsize);
660 asmlinkage long compat_sys_ppoll_time64(struct pollfd __user *ufds,
661 unsigned int nfds,
662 struct __kernel_timespec __user *tsp,
663 const compat_sigset_t __user *sigmask,
664 compat_size_t sigsetsize);
665 asmlinkage long compat_sys_signalfd4(int ufd,
666 const compat_sigset_t __user *sigmask,
667 compat_size_t sigsetsize, int flags);
668 asmlinkage long compat_sys_newfstatat(unsigned int dfd,
669 const char __user *filename,
670 struct compat_stat __user *statbuf,
671 int flag);
672 asmlinkage long compat_sys_newfstat(unsigned int fd,
673 struct compat_stat __user *statbuf);
674 /* No generic prototype for sync_file_range and sync_file_range2 */
675 asmlinkage long compat_sys_waitid(int, compat_pid_t,
676 struct compat_siginfo __user *, int,
677 struct compat_rusage __user *);
678 asmlinkage long
679 compat_sys_set_robust_list(struct compat_robust_list_head __user *head,
680 compat_size_t len);
681 asmlinkage long
682 compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
683 compat_size_t __user *len_ptr);
684 asmlinkage long compat_sys_getitimer(int which,
685 struct old_itimerval32 __user *it);
686 asmlinkage long compat_sys_setitimer(int which,
687 struct old_itimerval32 __user *in,
688 struct old_itimerval32 __user *out);
689 asmlinkage long compat_sys_kexec_load(compat_ulong_t entry,
690 compat_ulong_t nr_segments,
691 struct compat_kexec_segment __user *,
692 compat_ulong_t flags);
693 asmlinkage long compat_sys_timer_create(clockid_t which_clock,
694 struct compat_sigevent __user *timer_event_spec,
695 timer_t __user *created_timer_id);
696 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
697 compat_long_t addr, compat_long_t data);
698 asmlinkage long compat_sys_sched_setaffinity(compat_pid_t pid,
699 unsigned int len,
700 compat_ulong_t __user *user_mask_ptr);
701 asmlinkage long compat_sys_sched_getaffinity(compat_pid_t pid,
702 unsigned int len,
703 compat_ulong_t __user *user_mask_ptr);
704 asmlinkage long compat_sys_sigaltstack(const compat_stack_t __user *uss_ptr,
705 compat_stack_t __user *uoss_ptr);
706 asmlinkage long compat_sys_rt_sigsuspend(compat_sigset_t __user *unewset,
707 compat_size_t sigsetsize);
708 #ifndef CONFIG_ODD_RT_SIGACTION
709 asmlinkage long compat_sys_rt_sigaction(int,
710 const struct compat_sigaction __user *,
711 struct compat_sigaction __user *,
712 compat_size_t);
713 #endif
714 asmlinkage long compat_sys_rt_sigprocmask(int how, compat_sigset_t __user *set,
715 compat_sigset_t __user *oset,
716 compat_size_t sigsetsize);
717 asmlinkage long compat_sys_rt_sigpending(compat_sigset_t __user *uset,
718 compat_size_t sigsetsize);
719 asmlinkage long compat_sys_rt_sigtimedwait_time32(compat_sigset_t __user *uthese,
720 struct compat_siginfo __user *uinfo,
721 struct old_timespec32 __user *uts, compat_size_t sigsetsize);
722 asmlinkage long compat_sys_rt_sigtimedwait_time64(compat_sigset_t __user *uthese,
723 struct compat_siginfo __user *uinfo,
724 struct __kernel_timespec __user *uts, compat_size_t sigsetsize);
725 asmlinkage long compat_sys_rt_sigqueueinfo(compat_pid_t pid, int sig,
726 struct compat_siginfo __user *uinfo);
727 /* No generic prototype for rt_sigreturn */
728 asmlinkage long compat_sys_times(struct compat_tms __user *tbuf);
729 asmlinkage long compat_sys_getrlimit(unsigned int resource,
730 struct compat_rlimit __user *rlim);
731 asmlinkage long compat_sys_setrlimit(unsigned int resource,
732 struct compat_rlimit __user *rlim);
733 asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru);
734 asmlinkage long compat_sys_gettimeofday(struct old_timeval32 __user *tv,
735 struct timezone __user *tz);
736 asmlinkage long compat_sys_settimeofday(struct old_timeval32 __user *tv,
737 struct timezone __user *tz);
738 asmlinkage long compat_sys_sysinfo(struct compat_sysinfo __user *info);
739 asmlinkage long compat_sys_mq_open(const char __user *u_name,
740 int oflag, compat_mode_t mode,
741 struct compat_mq_attr __user *u_attr);
742 asmlinkage long compat_sys_mq_notify(mqd_t mqdes,
743 const struct compat_sigevent __user *u_notification);
744 asmlinkage long compat_sys_mq_getsetattr(mqd_t mqdes,
745 const struct compat_mq_attr __user *u_mqstat,
746 struct compat_mq_attr __user *u_omqstat);
747 asmlinkage long compat_sys_msgctl(int first, int second, void __user *uptr);
748 asmlinkage long compat_sys_msgrcv(int msqid, compat_uptr_t msgp,
749 compat_ssize_t msgsz, compat_long_t msgtyp, int msgflg);
750 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
751 compat_ssize_t msgsz, int msgflg);
752 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
753 asmlinkage long compat_sys_shmctl(int first, int second, void __user *uptr);
754 asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
755 asmlinkage long compat_sys_recvfrom(int fd, void __user *buf, compat_size_t len,
756 unsigned flags, struct sockaddr __user *addr,
757 int __user *addrlen);
758 asmlinkage long compat_sys_sendmsg(int fd, struct compat_msghdr __user *msg,
759 unsigned flags);
760 asmlinkage long compat_sys_recvmsg(int fd, struct compat_msghdr __user *msg,
761 unsigned int flags);
762 /* No generic prototype for readahead */
763 asmlinkage long compat_sys_keyctl(u32 option,
764 u32 arg2, u32 arg3, u32 arg4, u32 arg5);
765 asmlinkage long compat_sys_execve(const char __user *filename, const compat_uptr_t __user *argv,
766 const compat_uptr_t __user *envp);
767 /* No generic prototype for fadvise64_64 */
768 /* CONFIG_MMU only */
769 asmlinkage long compat_sys_rt_tgsigqueueinfo(compat_pid_t tgid,
770 compat_pid_t pid, int sig,
771 struct compat_siginfo __user *uinfo);
772 asmlinkage long compat_sys_recvmmsg_time64(int fd, struct compat_mmsghdr __user *mmsg,
773 unsigned vlen, unsigned int flags,
774 struct __kernel_timespec __user *timeout);
775 asmlinkage long compat_sys_recvmmsg_time32(int fd, struct compat_mmsghdr __user *mmsg,
776 unsigned vlen, unsigned int flags,
777 struct old_timespec32 __user *timeout);
778 asmlinkage long compat_sys_wait4(compat_pid_t pid,
779 compat_uint_t __user *stat_addr, int options,
780 struct compat_rusage __user *ru);
781 asmlinkage long compat_sys_fanotify_mark(int, unsigned int, __u32, __u32,
782 int, const char __user *);
783 asmlinkage long compat_sys_open_by_handle_at(int mountdirfd,
784 struct file_handle __user *handle,
785 int flags);
786 asmlinkage long compat_sys_sendmmsg(int fd, struct compat_mmsghdr __user *mmsg,
787 unsigned vlen, unsigned int flags);
788 asmlinkage long compat_sys_execveat(int dfd, const char __user *filename,
789 const compat_uptr_t __user *argv,
790 const compat_uptr_t __user *envp, int flags);
791 asmlinkage ssize_t compat_sys_preadv2(compat_ulong_t fd,
792 const struct iovec __user *vec,
793 compat_ulong_t vlen, u32 pos_low, u32 pos_high, rwf_t flags);
794 asmlinkage ssize_t compat_sys_pwritev2(compat_ulong_t fd,
795 const struct iovec __user *vec,
796 compat_ulong_t vlen, u32 pos_low, u32 pos_high, rwf_t flags);
797 #ifdef __ARCH_WANT_COMPAT_SYS_PREADV64V2
798 asmlinkage long compat_sys_preadv64v2(unsigned long fd,
799 const struct iovec __user *vec,
800 unsigned long vlen, loff_t pos, rwf_t flags);
801 #endif
802
803 #ifdef __ARCH_WANT_COMPAT_SYS_PWRITEV64V2
804 asmlinkage long compat_sys_pwritev64v2(unsigned long fd,
805 const struct iovec __user *vec,
806 unsigned long vlen, loff_t pos, rwf_t flags);
807 #endif
808
809
810 /*
811 * Deprecated system calls which are still defined in
812 * include/uapi/asm-generic/unistd.h and wanted by >= 1 arch
813 */
814
815 /* __ARCH_WANT_SYSCALL_NO_AT */
816 asmlinkage long compat_sys_open(const char __user *filename, int flags,
817 umode_t mode);
818
819 /* __ARCH_WANT_SYSCALL_NO_FLAGS */
820 asmlinkage long compat_sys_signalfd(int ufd,
821 const compat_sigset_t __user *sigmask,
822 compat_size_t sigsetsize);
823
824 /* __ARCH_WANT_SYSCALL_OFF_T */
825 asmlinkage long compat_sys_newstat(const char __user *filename,
826 struct compat_stat __user *statbuf);
827 asmlinkage long compat_sys_newlstat(const char __user *filename,
828 struct compat_stat __user *statbuf);
829
830 /* __ARCH_WANT_SYSCALL_DEPRECATED */
831 asmlinkage long compat_sys_select(int n, compat_ulong_t __user *inp,
832 compat_ulong_t __user *outp, compat_ulong_t __user *exp,
833 struct old_timeval32 __user *tvp);
834 asmlinkage long compat_sys_ustat(unsigned dev, struct compat_ustat __user *u32);
835 asmlinkage long compat_sys_recv(int fd, void __user *buf, compat_size_t len,
836 unsigned flags);
837
838 /* obsolete */
839 asmlinkage long compat_sys_old_readdir(unsigned int fd,
840 struct compat_old_linux_dirent __user *,
841 unsigned int count);
842
843 /* obsolete */
844 asmlinkage long compat_sys_old_select(struct compat_sel_arg_struct __user *arg);
845
846 /* obsolete */
847 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
848
849 /* obsolete */
850 #ifdef __ARCH_WANT_SYS_SIGPENDING
851 asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set);
852 #endif
853
854 #ifdef __ARCH_WANT_SYS_SIGPROCMASK
855 asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *nset,
856 compat_old_sigset_t __user *oset);
857 #endif
858 #ifdef CONFIG_COMPAT_OLD_SIGACTION
859 asmlinkage long compat_sys_sigaction(int sig,
860 const struct compat_old_sigaction __user *act,
861 struct compat_old_sigaction __user *oact);
862 #endif
863
864 /* obsolete */
865 asmlinkage long compat_sys_socketcall(int call, u32 __user *args);
866
867 #ifdef __ARCH_WANT_COMPAT_TRUNCATE64
868 asmlinkage long compat_sys_truncate64(const char __user *pathname, compat_arg_u64(len));
869 #endif
870
871 #ifdef __ARCH_WANT_COMPAT_FTRUNCATE64
872 asmlinkage long compat_sys_ftruncate64(unsigned int fd, compat_arg_u64(len));
873 #endif
874
875 #ifdef __ARCH_WANT_COMPAT_FALLOCATE
876 asmlinkage long compat_sys_fallocate(int fd, int mode, compat_arg_u64(offset),
877 compat_arg_u64(len));
878 #endif
879
880 #ifdef __ARCH_WANT_COMPAT_PREAD64
881 asmlinkage long compat_sys_pread64(unsigned int fd, char __user *buf, size_t count,
882 compat_arg_u64(pos));
883 #endif
884
885 #ifdef __ARCH_WANT_COMPAT_PWRITE64
886 asmlinkage long compat_sys_pwrite64(unsigned int fd, const char __user *buf, size_t count,
887 compat_arg_u64(pos));
888 #endif
889
890 #ifdef __ARCH_WANT_COMPAT_SYNC_FILE_RANGE
891 asmlinkage long compat_sys_sync_file_range(int fd, compat_arg_u64(pos),
892 compat_arg_u64(nbytes), unsigned int flags);
893 #endif
894
895 #ifdef __ARCH_WANT_COMPAT_FADVISE64_64
896 asmlinkage long compat_sys_fadvise64_64(int fd, compat_arg_u64(pos),
897 compat_arg_u64(len), int advice);
898 #endif
899
900 #ifdef __ARCH_WANT_COMPAT_READAHEAD
901 asmlinkage long compat_sys_readahead(int fd, compat_arg_u64(offset), size_t count);
902 #endif
903
904 #endif /* CONFIG_ARCH_HAS_SYSCALL_WRAPPER */
905
906 /**
907 * ns_to_old_timeval32 - Compat version of ns_to_timeval
908 * @nsec: the nanoseconds value to be converted
909 *
910 * Returns the old_timeval32 representation of the nsec parameter.
911 */
ns_to_old_timeval32(s64 nsec)912 static inline struct old_timeval32 ns_to_old_timeval32(s64 nsec)
913 {
914 struct __kernel_old_timeval tv;
915 struct old_timeval32 ctv;
916
917 tv = ns_to_kernel_old_timeval(nsec);
918 ctv.tv_sec = tv.tv_sec;
919 ctv.tv_usec = tv.tv_usec;
920
921 return ctv;
922 }
923
924 /*
925 * Kernel code should not call compat syscalls (i.e., compat_sys_xyzyyz())
926 * directly. Instead, use one of the functions which work equivalently, such
927 * as the kcompat_sys_xyzyyz() functions prototyped below.
928 */
929
930 int kcompat_sys_statfs64(const char __user * pathname, compat_size_t sz,
931 struct compat_statfs64 __user * buf);
932 int kcompat_sys_fstatfs64(unsigned int fd, compat_size_t sz,
933 struct compat_statfs64 __user * buf);
934
935 #ifdef CONFIG_COMPAT
936
937 /*
938 * For most but not all architectures, "am I in a compat syscall?" and
939 * "am I a compat task?" are the same question. For architectures on which
940 * they aren't the same question, arch code can override in_compat_syscall.
941 */
942 #ifndef in_compat_syscall
in_compat_syscall(void)943 static inline bool in_compat_syscall(void) { return is_compat_task(); }
944 #endif
945
946 #else /* !CONFIG_COMPAT */
947
948 #define is_compat_task() (0)
949 /* Ensure no one redefines in_compat_syscall() under !CONFIG_COMPAT */
950 #define in_compat_syscall in_compat_syscall
in_compat_syscall(void)951 static inline bool in_compat_syscall(void) { return false; }
952
953 #endif /* CONFIG_COMPAT */
954
955 #define BITS_PER_COMPAT_LONG (8*sizeof(compat_long_t))
956
957 #define BITS_TO_COMPAT_LONGS(bits) DIV_ROUND_UP(bits, BITS_PER_COMPAT_LONG)
958
959 long compat_get_bitmap(unsigned long *mask, const compat_ulong_t __user *umask,
960 unsigned long bitmap_size);
961 long compat_put_bitmap(compat_ulong_t __user *umask, unsigned long *mask,
962 unsigned long bitmap_size);
963
964 /*
965 * Some legacy ABIs like the i386 one use less than natural alignment for 64-bit
966 * types, and will need special compat treatment for that. Most architectures
967 * don't need that special handling even for compat syscalls.
968 */
969 #ifndef compat_need_64bit_alignment_fixup
970 #define compat_need_64bit_alignment_fixup() false
971 #endif
972
973 /*
974 * A pointer passed in from user mode. This should not
975 * be used for syscall parameters, just declare them
976 * as pointers because the syscall entry code will have
977 * appropriately converted them already.
978 */
979 #ifndef compat_ptr
compat_ptr(compat_uptr_t uptr)980 static inline void __user *compat_ptr(compat_uptr_t uptr)
981 {
982 return (void __user *)(unsigned long)uptr;
983 }
984 #endif
985
ptr_to_compat(void __user * uptr)986 static inline compat_uptr_t ptr_to_compat(void __user *uptr)
987 {
988 return (u32)(unsigned long)uptr;
989 }
990
991 #endif /* _LINUX_COMPAT_H */
992