x86/oprofile: Fix bogus GCC-8 warning in nmi_setup()
[cris-mirror.git] / arch / x86 / kernel / signal_compat.c
blobac057f9b076360168704438f9f808d152a2dce8d
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/compat.h>
3 #include <linux/uaccess.h>
4 #include <linux/ptrace.h>
6 /*
7 * The compat_siginfo_t structure and handing code is very easy
8 * to break in several ways. It must always be updated when new
9 * updates are made to the main siginfo_t, and
10 * copy_siginfo_to_user32() must be updated when the
11 * (arch-independent) copy_siginfo_to_user() is updated.
13 * It is also easy to put a new member in the compat_siginfo_t
14 * which has implicit alignment which can move internal structure
15 * alignment around breaking the ABI. This can happen if you,
16 * for instance, put a plain 64-bit value in there.
18 static inline void signal_compat_build_tests(void)
20 int _sifields_offset = offsetof(compat_siginfo_t, _sifields);
23 * If adding a new si_code, there is probably new data in
24 * the siginfo. Make sure folks bumping the si_code
25 * limits also have to look at this code. Make sure any
26 * new fields are handled in copy_siginfo_to_user32()!
28 BUILD_BUG_ON(NSIGILL != 11);
29 BUILD_BUG_ON(NSIGFPE != 13);
30 BUILD_BUG_ON(NSIGSEGV != 4);
31 BUILD_BUG_ON(NSIGBUS != 5);
32 BUILD_BUG_ON(NSIGTRAP != 4);
33 BUILD_BUG_ON(NSIGCHLD != 6);
34 BUILD_BUG_ON(NSIGSYS != 1);
36 /* This is part of the ABI and can never change in size: */
37 BUILD_BUG_ON(sizeof(compat_siginfo_t) != 128);
39 * The offsets of all the (unioned) si_fields are fixed
40 * in the ABI, of course. Make sure none of them ever
41 * move and are always at the beginning:
43 BUILD_BUG_ON(offsetof(compat_siginfo_t, _sifields) != 3 * sizeof(int));
44 #define CHECK_CSI_OFFSET(name) BUILD_BUG_ON(_sifields_offset != offsetof(compat_siginfo_t, _sifields.name))
47 * Ensure that the size of each si_field never changes.
48 * If it does, it is a sign that the
49 * copy_siginfo_to_user32() code below needs to updated
50 * along with the size in the CHECK_SI_SIZE().
52 * We repeat this check for both the generic and compat
53 * siginfos.
55 * Note: it is OK for these to grow as long as the whole
56 * structure stays within the padding size (checked
57 * above).
59 #define CHECK_CSI_SIZE(name, size) BUILD_BUG_ON(size != sizeof(((compat_siginfo_t *)0)->_sifields.name))
60 #define CHECK_SI_SIZE(name, size) BUILD_BUG_ON(size != sizeof(((siginfo_t *)0)->_sifields.name))
62 CHECK_CSI_OFFSET(_kill);
63 CHECK_CSI_SIZE (_kill, 2*sizeof(int));
64 CHECK_SI_SIZE (_kill, 2*sizeof(int));
66 CHECK_CSI_OFFSET(_timer);
67 CHECK_CSI_SIZE (_timer, 3*sizeof(int));
68 CHECK_SI_SIZE (_timer, 6*sizeof(int));
70 CHECK_CSI_OFFSET(_rt);
71 CHECK_CSI_SIZE (_rt, 3*sizeof(int));
72 CHECK_SI_SIZE (_rt, 4*sizeof(int));
74 CHECK_CSI_OFFSET(_sigchld);
75 CHECK_CSI_SIZE (_sigchld, 5*sizeof(int));
76 CHECK_SI_SIZE (_sigchld, 8*sizeof(int));
78 #ifdef CONFIG_X86_X32_ABI
79 CHECK_CSI_OFFSET(_sigchld_x32);
80 CHECK_CSI_SIZE (_sigchld_x32, 7*sizeof(int));
81 /* no _sigchld_x32 in the generic siginfo_t */
82 #endif
84 CHECK_CSI_OFFSET(_sigfault);
85 CHECK_CSI_SIZE (_sigfault, 4*sizeof(int));
86 CHECK_SI_SIZE (_sigfault, 8*sizeof(int));
88 CHECK_CSI_OFFSET(_sigpoll);
89 CHECK_CSI_SIZE (_sigpoll, 2*sizeof(int));
90 CHECK_SI_SIZE (_sigpoll, 4*sizeof(int));
92 CHECK_CSI_OFFSET(_sigsys);
93 CHECK_CSI_SIZE (_sigsys, 3*sizeof(int));
94 CHECK_SI_SIZE (_sigsys, 4*sizeof(int));
96 /* any new si_fields should be added here */
99 void sigaction_compat_abi(struct k_sigaction *act, struct k_sigaction *oact)
101 signal_compat_build_tests();
103 /* Don't leak in-kernel non-uapi flags to user-space */
104 if (oact)
105 oact->sa.sa_flags &= ~(SA_IA32_ABI | SA_X32_ABI);
107 if (!act)
108 return;
110 /* Don't let flags to be set from userspace */
111 act->sa.sa_flags &= ~(SA_IA32_ABI | SA_X32_ABI);
113 if (in_ia32_syscall())
114 act->sa.sa_flags |= SA_IA32_ABI;
115 if (in_x32_syscall())
116 act->sa.sa_flags |= SA_X32_ABI;