Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/signals: Add missing signal_compat code for x86 features

The 32-bit siginfo is a different binary format than the 64-bit
one. So, when running 32-bit binaries on 64-bit kernels, we have
to convert the kernel's 64-bit version to a 32-bit version that
userspace can grok.

We've added a few features to siginfo over the past few years and
neglected to add them to arch/x86/kernel/signal_compat.c:

1. The si_addr_lsb used in SIGBUS's sent for machine checks
2. The upper/lower bounds for MPX SIGSEGV faults
3. The protection key for pkey faults

I caught this with some protection keys unit tests and realized
it affected a few more features.

This was tested only with my protection keys patch that looks
for a proper value in si_pkey. I didn't actually test the machine
check or MPX code.

Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dave Hansen <dave@sr71.net>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tony Luck <tony.luck@intel.com>
Cc: linux-edac@vger.kernel.org
Link: http://lkml.kernel.org/r/20160608172533.F8F05637@viggo.jf.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Dave Hansen and committed by
Ingo Molnar
a4455082 f0702555

+26
+11
arch/x86/include/asm/compat.h
··· 40 40 typedef s64 __attribute__((aligned(4))) compat_s64; 41 41 typedef u32 compat_uint_t; 42 42 typedef u32 compat_ulong_t; 43 + typedef u32 compat_u32; 43 44 typedef u64 __attribute__((aligned(4))) compat_u64; 44 45 typedef u32 compat_uptr_t; 45 46 ··· 182 181 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */ 183 182 struct { 184 183 unsigned int _addr; /* faulting insn/memory ref. */ 184 + short int _addr_lsb; /* Valid LSB of the reported address. */ 185 + union { 186 + /* used when si_code=SEGV_BNDERR */ 187 + struct { 188 + compat_uptr_t _lower; 189 + compat_uptr_t _upper; 190 + } _addr_bnd; 191 + /* used when si_code=SEGV_PKUERR */ 192 + compat_u32 _pkey; 193 + }; 185 194 } _sigfault; 186 195 187 196 /* SIGPOLL */
+15
arch/x86/kernel/signal_compat.c
··· 32 32 &to->_sifields._pad[0]); 33 33 switch (from->si_code >> 16) { 34 34 case __SI_FAULT >> 16: 35 + if (from->si_signo == SIGBUS && 36 + (from->si_code == BUS_MCEERR_AR || 37 + from->si_code == BUS_MCEERR_AO)) 38 + put_user_ex(from->si_addr_lsb, &to->si_addr_lsb); 39 + 40 + if (from->si_signo == SIGSEGV) { 41 + if (from->si_code == SEGV_BNDERR) { 42 + compat_uptr_t lower = (unsigned long)&to->si_lower; 43 + compat_uptr_t upper = (unsigned long)&to->si_upper; 44 + put_user_ex(lower, &to->si_lower); 45 + put_user_ex(upper, &to->si_upper); 46 + } 47 + if (from->si_code == SEGV_PKUERR) 48 + put_user_ex(from->si_pkey, &to->si_pkey); 49 + } 35 50 break; 36 51 case __SI_SYS >> 16: 37 52 put_user_ex(from->si_syscall, &to->si_syscall);