linux/include/uapi/asm-generic
Eric W. Biederman cc731525f2 signal: Remove kernel interal si_code magic
struct siginfo is a union and the kernel since 2.4 has been hiding a union
tag in the high 16bits of si_code using the values:
__SI_KILL
__SI_TIMER
__SI_POLL
__SI_FAULT
__SI_CHLD
__SI_RT
__SI_MESGQ
__SI_SYS

While this looks plausible on the surface, in practice this situation has
not worked well.

- Injected positive signals are not copied to user space properly
  unless they have these magic high bits set.

- Injected positive signals are not reported properly by signalfd
  unless they have these magic high bits set.

- These kernel internal values leaked to userspace via ptrace_peek_siginfo

- It was possible to inject these kernel internal values and cause the
  the kernel to misbehave.

- Kernel developers got confused and expected these kernel internal values
  in userspace in kernel self tests.

- Kernel developers got confused and set si_code to __SI_FAULT which
  is SI_USER in userspace which causes userspace to think an ordinary user
  sent the signal and that it was not kernel generated.

- The values make it impossible to reorganize the code to transform
  siginfo_copy_to_user into a plain copy_to_user.  As si_code must
  be massaged before being passed to userspace.

So remove these kernel internal si codes and make the kernel code simpler
and more maintainable.

To replace these kernel internal magic si_codes introduce the helper
function siginfo_layout, that takes a signal number and an si_code and
computes which union member of siginfo is being used.  Have
siginfo_layout return an enumeration so that gcc will have enough
information to warn if a switch statement does not handle all of union
members.

A couple of architectures have a messed up ABI that defines signal
specific duplications of SI_USER which causes more special cases in
siginfo_layout than I would like.  The good news is only problem
architectures pay the cost.

Update all of the code that used the previous magic __SI_ values to
use the new SIL_ values and to call siginfo_layout to get those
values.  Escept where not all of the cases are handled remove the
defaults in the switch statements so that if a new case is missed in
the future the lack will show up at compile time.

Modify the code that copies siginfo si_code to userspace to just copy
the value and not cast si_code to a short first.  The high bits are no
longer used to hold a magic union member.

Fixup the siginfo header files to stop including the __SI_ values in
their constants and for the headers that were missing it to properly
update the number of si_codes for each signal type.

The fixes to copy_siginfo_from_user32 implementations has the
interesting property that several of them perviously should never have
worked as the __SI_ values they depended up where kernel internal.
With that dependency gone those implementations should work much
better.

The idea of not passing the __SI_ values out to userspace and then
not reinserting them has been tested with criu and criu worked without
changes.

Ref: 2.4.0-test1
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
2017-07-24 14:30:28 -05:00
..
auxvec.h
bitsperlong.h
errno-base.h
errno.h errno.h: Improve ENOSYS's comment 2015-04-17 09:03:58 -04:00
fcntl.h vfs: renumber FMODE_NONOTIFY and add to uniqueness check 2015-01-08 15:10:52 -08:00
int-l64.h
int-ll64.h
ioctl.h userfaultfd: document _IOR/_IOW 2017-02-22 16:41:27 -08:00
ioctls.h tty: add TIOCGPTPEER ioctl 2017-06-09 12:27:54 +02:00
ipcbuf.h uapi, asm-generic: Use __kernel_ulong_t in uapi struct ipc64_perm 2014-01-20 14:44:35 -08:00
Kbuild.asm uapi: export all headers under uapi directories 2017-05-11 00:21:54 +09:00
kvm_para.h
mman-common.h x86/pkeys: Allocation/free syscalls 2016-09-09 13:02:27 +02:00
mman.h mm: mlock: add mlock flags to enable VM_LOCKONFAULT usage 2015-11-05 19:34:48 -08:00
msgbuf.h uapi: Use __kernel_ulong_t in struct msqid64_ds 2014-01-20 14:45:01 -08:00
param.h
poll.h net: rename low latency sockets functions to busy poll 2013-07-08 19:25:45 -07:00
posix_types.h
resource.h asm-generic: remove _STK_LIM_MAX 2014-05-15 00:32:09 +01:00
sembuf.h
setup.h
shmbuf.h uapi: Use __kernel_ulong_t in shmid64_ds/shminfo64/shm_info 2014-01-20 14:45:25 -08:00
shmparam.h
siginfo.h signal: Remove kernel interal si_code magic 2017-07-24 14:30:28 -05:00
signal-defs.h
signal.h arm64: Fix MINSIGSTKSZ and SIGSTKSZ 2015-10-12 17:40:12 +01:00
socket.h net: introduce SO_PEERGROUPS getsockopt 2017-06-21 11:38:41 -04:00
sockios.h
stat.h
statfs.h x86, x32: Use __kernel_long_t for __statfs_word 2013-12-20 16:06:21 -08:00
swab.h
termbits.h
termios.h
types.h asm/types.h: Remove include/asm-generic/int-l64.h 2014-01-23 16:36:53 -08:00
ucontext.h
unistd.h Remove compat_sys_getdents64() 2017-04-17 12:52:22 -04:00