mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-28 23:23:55 +08:00
a4455082dc
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>
111 lines
3.2 KiB
C
111 lines
3.2 KiB
C
#include <linux/compat.h>
|
|
#include <linux/uaccess.h>
|
|
|
|
int copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from)
|
|
{
|
|
int err = 0;
|
|
bool ia32 = test_thread_flag(TIF_IA32);
|
|
|
|
if (!access_ok(VERIFY_WRITE, to, sizeof(compat_siginfo_t)))
|
|
return -EFAULT;
|
|
|
|
put_user_try {
|
|
/* If you change siginfo_t structure, please make sure that
|
|
this code is fixed accordingly.
|
|
It should never copy any pad contained in the structure
|
|
to avoid security leaks, but must copy the generic
|
|
3 ints plus the relevant union member. */
|
|
put_user_ex(from->si_signo, &to->si_signo);
|
|
put_user_ex(from->si_errno, &to->si_errno);
|
|
put_user_ex((short)from->si_code, &to->si_code);
|
|
|
|
if (from->si_code < 0) {
|
|
put_user_ex(from->si_pid, &to->si_pid);
|
|
put_user_ex(from->si_uid, &to->si_uid);
|
|
put_user_ex(ptr_to_compat(from->si_ptr), &to->si_ptr);
|
|
} else {
|
|
/*
|
|
* First 32bits of unions are always present:
|
|
* si_pid === si_band === si_tid === si_addr(LS half)
|
|
*/
|
|
put_user_ex(from->_sifields._pad[0],
|
|
&to->_sifields._pad[0]);
|
|
switch (from->si_code >> 16) {
|
|
case __SI_FAULT >> 16:
|
|
if (from->si_signo == SIGBUS &&
|
|
(from->si_code == BUS_MCEERR_AR ||
|
|
from->si_code == BUS_MCEERR_AO))
|
|
put_user_ex(from->si_addr_lsb, &to->si_addr_lsb);
|
|
|
|
if (from->si_signo == SIGSEGV) {
|
|
if (from->si_code == SEGV_BNDERR) {
|
|
compat_uptr_t lower = (unsigned long)&to->si_lower;
|
|
compat_uptr_t upper = (unsigned long)&to->si_upper;
|
|
put_user_ex(lower, &to->si_lower);
|
|
put_user_ex(upper, &to->si_upper);
|
|
}
|
|
if (from->si_code == SEGV_PKUERR)
|
|
put_user_ex(from->si_pkey, &to->si_pkey);
|
|
}
|
|
break;
|
|
case __SI_SYS >> 16:
|
|
put_user_ex(from->si_syscall, &to->si_syscall);
|
|
put_user_ex(from->si_arch, &to->si_arch);
|
|
break;
|
|
case __SI_CHLD >> 16:
|
|
if (ia32) {
|
|
put_user_ex(from->si_utime, &to->si_utime);
|
|
put_user_ex(from->si_stime, &to->si_stime);
|
|
} else {
|
|
put_user_ex(from->si_utime, &to->_sifields._sigchld_x32._utime);
|
|
put_user_ex(from->si_stime, &to->_sifields._sigchld_x32._stime);
|
|
}
|
|
put_user_ex(from->si_status, &to->si_status);
|
|
/* FALL THROUGH */
|
|
default:
|
|
case __SI_KILL >> 16:
|
|
put_user_ex(from->si_uid, &to->si_uid);
|
|
break;
|
|
case __SI_POLL >> 16:
|
|
put_user_ex(from->si_fd, &to->si_fd);
|
|
break;
|
|
case __SI_TIMER >> 16:
|
|
put_user_ex(from->si_overrun, &to->si_overrun);
|
|
put_user_ex(ptr_to_compat(from->si_ptr),
|
|
&to->si_ptr);
|
|
break;
|
|
/* This is not generated by the kernel as of now. */
|
|
case __SI_RT >> 16:
|
|
case __SI_MESGQ >> 16:
|
|
put_user_ex(from->si_uid, &to->si_uid);
|
|
put_user_ex(from->si_int, &to->si_int);
|
|
break;
|
|
}
|
|
}
|
|
} put_user_catch(err);
|
|
|
|
return err;
|
|
}
|
|
|
|
int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from)
|
|
{
|
|
int err = 0;
|
|
u32 ptr32;
|
|
|
|
if (!access_ok(VERIFY_READ, from, sizeof(compat_siginfo_t)))
|
|
return -EFAULT;
|
|
|
|
get_user_try {
|
|
get_user_ex(to->si_signo, &from->si_signo);
|
|
get_user_ex(to->si_errno, &from->si_errno);
|
|
get_user_ex(to->si_code, &from->si_code);
|
|
|
|
get_user_ex(to->si_pid, &from->si_pid);
|
|
get_user_ex(to->si_uid, &from->si_uid);
|
|
get_user_ex(ptr32, &from->si_ptr);
|
|
to->si_ptr = compat_ptr(ptr32);
|
|
} get_user_catch(err);
|
|
|
|
return err;
|
|
}
|