Skip to content

Commit f6a0154

Browse files
committed
signal/x86: Include the field offsets in the build time checks
Due to an oversight when refactoring siginfo_t si_pkey has been in the wrong position since 4.16-rc1. Add an explicit check of the offset of every user space field in siginfo_t and compat_siginfo_t to make a mistake like this hard to make in the future. I have run this code on 4.15 and 4.16-rc1 with the position of si_pkey fixed and all of the fields show up in the same location. Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
1 parent 859d880 commit f6a0154

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

arch/x86/kernel/signal_compat.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ static inline void signal_compat_build_tests(void)
4343
BUILD_BUG_ON(offsetof(compat_siginfo_t, _sifields) != 3 * sizeof(int));
4444
#define CHECK_CSI_OFFSET(name) BUILD_BUG_ON(_sifields_offset != offsetof(compat_siginfo_t, _sifields.name))
4545

46+
BUILD_BUG_ON(offsetof(siginfo_t, si_signo) != 0);
47+
BUILD_BUG_ON(offsetof(siginfo_t, si_errno) != 4);
48+
BUILD_BUG_ON(offsetof(siginfo_t, si_code) != 8);
49+
50+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_signo) != 0);
51+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_errno) != 4);
52+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_code) != 8);
4653
/*
4754
* Ensure that the size of each si_field never changes.
4855
* If it does, it is a sign that the
@@ -63,36 +70,94 @@ static inline void signal_compat_build_tests(void)
6370
CHECK_CSI_SIZE (_kill, 2*sizeof(int));
6471
CHECK_SI_SIZE (_kill, 2*sizeof(int));
6572

73+
BUILD_BUG_ON(offsetof(siginfo_t, si_pid) != 0x10);
74+
BUILD_BUG_ON(offsetof(siginfo_t, si_uid) != 0x14);
75+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_pid) != 0xC);
76+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_uid) != 0x10);
77+
6678
CHECK_CSI_OFFSET(_timer);
6779
CHECK_CSI_SIZE (_timer, 3*sizeof(int));
6880
CHECK_SI_SIZE (_timer, 6*sizeof(int));
6981

82+
BUILD_BUG_ON(offsetof(siginfo_t, si_tid) != 0x10);
83+
BUILD_BUG_ON(offsetof(siginfo_t, si_overrun) != 0x14);
84+
BUILD_BUG_ON(offsetof(siginfo_t, si_value) != 0x18);
85+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_tid) != 0x0C);
86+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_overrun) != 0x10);
87+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_value) != 0x14);
88+
7089
CHECK_CSI_OFFSET(_rt);
7190
CHECK_CSI_SIZE (_rt, 3*sizeof(int));
7291
CHECK_SI_SIZE (_rt, 4*sizeof(int));
7392

93+
BUILD_BUG_ON(offsetof(siginfo_t, si_pid) != 0x10);
94+
BUILD_BUG_ON(offsetof(siginfo_t, si_uid) != 0x14);
95+
BUILD_BUG_ON(offsetof(siginfo_t, si_value) != 0x18);
96+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_pid) != 0x0C);
97+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_uid) != 0x10);
98+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_value) != 0x14);
99+
74100
CHECK_CSI_OFFSET(_sigchld);
75101
CHECK_CSI_SIZE (_sigchld, 5*sizeof(int));
76102
CHECK_SI_SIZE (_sigchld, 8*sizeof(int));
77103

104+
BUILD_BUG_ON(offsetof(siginfo_t, si_pid) != 0x10);
105+
BUILD_BUG_ON(offsetof(siginfo_t, si_uid) != 0x14);
106+
BUILD_BUG_ON(offsetof(siginfo_t, si_status) != 0x18);
107+
BUILD_BUG_ON(offsetof(siginfo_t, si_utime) != 0x20);
108+
BUILD_BUG_ON(offsetof(siginfo_t, si_stime) != 0x28);
109+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_pid) != 0x0C);
110+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_uid) != 0x10);
111+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_status) != 0x14);
112+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_utime) != 0x18);
113+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_stime) != 0x1C);
114+
78115
#ifdef CONFIG_X86_X32_ABI
79116
CHECK_CSI_OFFSET(_sigchld_x32);
80117
CHECK_CSI_SIZE (_sigchld_x32, 7*sizeof(int));
81118
/* no _sigchld_x32 in the generic siginfo_t */
119+
BUILD_BUG_ON(offsetof(compat_siginfo_t, _sifields._sigchld_x32._utime) != 0x18);
120+
BUILD_BUG_ON(offsetof(compat_siginfo_t, _sifields._sigchld_x32._stime) != 0x20);
82121
#endif
83122

84123
CHECK_CSI_OFFSET(_sigfault);
85124
CHECK_CSI_SIZE (_sigfault, 4*sizeof(int));
86125
CHECK_SI_SIZE (_sigfault, 8*sizeof(int));
87126

127+
BUILD_BUG_ON(offsetof(siginfo_t, si_addr) != 0x10);
128+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_addr) != 0x0C);
129+
130+
BUILD_BUG_ON(offsetof(siginfo_t, si_addr_lsb) != 0x18);
131+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_addr_lsb) != 0x10);
132+
133+
BUILD_BUG_ON(offsetof(siginfo_t, si_lower) != 0x20);
134+
BUILD_BUG_ON(offsetof(siginfo_t, si_upper) != 0x28);
135+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_lower) != 0x14);
136+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_upper) != 0x18);
137+
138+
BUILD_BUG_ON(offsetof(siginfo_t, si_pkey) != 0x20);
139+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_pkey) != 0x14);
140+
88141
CHECK_CSI_OFFSET(_sigpoll);
89142
CHECK_CSI_SIZE (_sigpoll, 2*sizeof(int));
90143
CHECK_SI_SIZE (_sigpoll, 4*sizeof(int));
91144

145+
BUILD_BUG_ON(offsetof(siginfo_t, si_band) != 0x10);
146+
BUILD_BUG_ON(offsetof(siginfo_t, si_fd) != 0x18);
147+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_band) != 0x0C);
148+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_fd) != 0x10);
149+
92150
CHECK_CSI_OFFSET(_sigsys);
93151
CHECK_CSI_SIZE (_sigsys, 3*sizeof(int));
94152
CHECK_SI_SIZE (_sigsys, 4*sizeof(int));
95153

154+
BUILD_BUG_ON(offsetof(siginfo_t, si_call_addr) != 0x10);
155+
BUILD_BUG_ON(offsetof(siginfo_t, si_syscall) != 0x18);
156+
BUILD_BUG_ON(offsetof(siginfo_t, si_arch) != 0x1C);
157+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_call_addr) != 0x0C);
158+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_syscall) != 0x10);
159+
BUILD_BUG_ON(offsetof(compat_siginfo_t, si_arch) != 0x14);
160+
96161
/* any new si_fields should be added here */
97162
}
98163

0 commit comments

Comments
 (0)