Skip to content

Commit

Permalink
m68k: Verify the offsets in struct siginfo never change.
Browse files Browse the repository at this point in the history
A change to the generic struct siginfo accidentally changed the offset
of si_offset.  Add build time checks to ensure the offsets of all known
fields in struct siginfo never change.  This copies the form of similar
changes on x86.

Signed-off-by: "Eric W. Biederman" <[email protected]>
  • Loading branch information
ebiederm committed Apr 2, 2018
1 parent 8420f71 commit 4be3332
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions arch/m68k/kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,66 @@ static inline int rt_save_fpu_state(struct ucontext __user *uc, struct pt_regs *

#endif /* CONFIG_FPU */

static inline void siginfo_build_tests(void)
{
/* This needs to be tested on m68k as it has a lesser
* alignment requirment than x86 and that can cause surprises.
*/

/* This is part of the ABI and can never change in size: */
BUILD_BUG_ON(sizeof(siginfo_t) != 128);

/* Ensure the know fields never change in location */
BUILD_BUG_ON(offsetof(siginfo_t, si_signo) != 0);
BUILD_BUG_ON(offsetof(siginfo_t, si_errno) != 4);
BUILD_BUG_ON(offsetof(siginfo_t, si_code) != 8);

/* _kill */
BUILD_BUG_ON(offsetof(siginfo_t, si_pid) != 0x0C);
BUILD_BUG_ON(offsetof(siginfo_t, si_uid) != 0x10);

/* _timer */
BUILD_BUG_ON(offsetof(siginfo_t, si_tid) != 0x0C);
BUILD_BUG_ON(offsetof(siginfo_t, si_overrun) != 0x10);
BUILD_BUG_ON(offsetof(siginfo_t, si_value) != 0x14);

/* _rt */
BUILD_BUG_ON(offsetof(siginfo_t, si_pid) != 0x0C);
BUILD_BUG_ON(offsetof(siginfo_t, si_uid) != 0x10);
BUILD_BUG_ON(offsetof(siginfo_t, si_value) != 0x14);

/* _sigchld */
BUILD_BUG_ON(offsetof(siginfo_t, si_pid) != 0x0C);
BUILD_BUG_ON(offsetof(siginfo_t, si_uid) != 0x10);
BUILD_BUG_ON(offsetof(siginfo_t, si_status) != 0x14);
BUILD_BUG_ON(offsetof(siginfo_t, si_utime) != 0x18);
BUILD_BUG_ON(offsetof(siginfo_t, si_stime) != 0x1C);

/* _sigfault */
BUILD_BUG_ON(offsetof(siginfo_t, si_addr) != 0x0C);

/* _sigfault._mcerr */
BUILD_BUG_ON(offsetof(siginfo_t, si_addr_lsb) != 0x10);

/* _sigfault._addr_bnd */
BUILD_BUG_ON(offsetof(siginfo_t, si_lower) != 0x12);
BUILD_BUG_ON(offsetof(siginfo_t, si_upper) != 0x16);

/* _sigfault._addr_pkey */
BUILD_BUG_ON(offsetof(siginfo_t, si_pkey) != 0x12);

/* _sigpoll */
BUILD_BUG_ON(offsetof(siginfo_t, si_band) != 0x0C);
BUILD_BUG_ON(offsetof(siginfo_t, si_fd) != 0x10);

/* _sigsys */
BUILD_BUG_ON(offsetof(siginfo_t, si_call_addr) != 0x0C);
BUILD_BUG_ON(offsetof(siginfo_t, si_syscall) != 0x10);
BUILD_BUG_ON(offsetof(siginfo_t, si_arch) != 0x14);

/* any new si_fields should be added here */
}

static int mangle_kernel_stack(struct pt_regs *regs, int formatvec,
void __user *fp)
{
Expand Down Expand Up @@ -635,6 +695,8 @@ restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *usc, void __u
struct sigcontext context;
int err = 0;

siginfo_build_tests();

/* Always make any pending restarted system calls return -EINTR */
current->restart_block.fn = do_no_restart_syscall;

Expand Down

0 comments on commit 4be3332

Please sign in to comment.