2017-11-01 15:08:43 +01:00
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2012-10-04 18:20:15 +01:00
# ifndef _UAPI_ASM_GENERIC_SIGINFO_H
# define _UAPI_ASM_GENERIC_SIGINFO_H
# include <linux/compiler.h>
# include <linux/types.h>
typedef union sigval {
int sival_int ;
void __user * sival_ptr ;
} sigval_t ;
# define SI_MAX_SIZE 128
/*
* The default " si_band " type is " long " , as specified by POSIX .
* However , some architectures want to override this to " int "
* for historical compatibility reasons , so we allow that .
*/
# ifndef __ARCH_SI_BAND_T
# define __ARCH_SI_BAND_T long
# endif
# ifndef __ARCH_SI_CLOCK_T
# define __ARCH_SI_CLOCK_T __kernel_clock_t
# endif
# ifndef __ARCH_SI_ATTRIBUTES
# define __ARCH_SI_ATTRIBUTES
# endif
2018-04-18 17:48:49 -05:00
union __sifields {
/* kill() */
struct {
__kernel_pid_t _pid ; /* sender's pid */
__kernel_uid32_t _uid ; /* sender's uid */
} _kill ;
/* POSIX.1b timers */
struct {
__kernel_timer_t _tid ; /* timer id */
int _overrun ; /* overrun count */
sigval_t _sigval ; /* same as below */
int _sys_private ; /* not to be passed to user */
} _timer ;
/* POSIX.1b signals */
struct {
__kernel_pid_t _pid ; /* sender's pid */
__kernel_uid32_t _uid ; /* sender's uid */
sigval_t _sigval ;
} _rt ;
/* SIGCHLD */
struct {
__kernel_pid_t _pid ; /* which child */
__kernel_uid32_t _uid ; /* sender's uid */
int _status ; /* exit code */
__ARCH_SI_CLOCK_T _utime ;
__ARCH_SI_CLOCK_T _stime ;
} _sigchld ;
/* SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */
struct {
void __user * _addr ; /* faulting insn/memory ref. */
2017-07-31 14:53:59 -05:00
# ifdef __ia64__
2018-04-18 17:48:49 -05:00
int _imm ; /* immediate value for "break" */
unsigned int _flags ; /* see ia64 si_flags */
unsigned long _isr ; /* isr */
2012-10-04 18:20:15 +01:00
# endif
2018-04-02 14:45:42 -05:00
# define __ADDR_BND_PKEY_PAD (__alignof__(void *) < sizeof(short) ? \
sizeof ( short ) : __alignof__ ( void * ) )
2018-04-18 17:48:49 -05:00
union {
siginfo: Move si_trapno inside the union inside _si_fault
It turns out that linux uses si_trapno very sparingly, and as such it
can be considered extra information for a very narrow selection of
signals, rather than information that is present with every fault
reported in siginfo.
As such move si_trapno inside the union inside of _si_fault. This
results in no change in placement, and makes it eaiser
to extend _si_fault in the future as this reduces the number of
special cases. In particular with si_trapno included in the union it
is no longer a concern that the union must be pointer aligned on most
architectures because the union follows immediately after si_addr
which is a pointer.
This change results in a difference in siginfo field placement on
sparc and alpha for the fields si_addr_lsb, si_lower, si_upper,
si_pkey, and si_perf. These architectures do not implement the
signals that would use si_addr_lsb, si_lower, si_upper, si_pkey, and
si_perf. Further these architecture have not yet implemented the
userspace that would use si_perf.
The point of this change is in fact to correct these placement issues
before sparc or alpha grow userspace that cares. This change was
discussed[1] and the agreement is that this change is currently safe.
[1]: https://lkml.kernel.org/r/CAK8P3a0+uKYwL1NhY6Hvtieghba2hKYGD6hcKx5n8=4Gtt+pHA@mail.gmail.com
Acked-by: Marco Elver <elver@google.com>
v1: https://lkml.kernel.org/r/m1tunns7yf.fsf_-_@fess.ebiederm.org
v2: https://lkml.kernel.org/r/20210505141101.11519-5-ebiederm@xmission.com
Link: https://lkml.kernel.org/r/20210517195748.8880-1-ebiederm@xmission.com
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
2021-04-30 17:06:01 -05:00
/* used on alpha and sparc */
int _trapno ; /* TRAP # which caused the signal */
2018-04-18 17:48:49 -05:00
/*
* used when si_code = BUS_MCEERR_AR or
* used when si_code = BUS_MCEERR_AO
*/
short _addr_lsb ; /* LSB of the reported address */
/* used when si_code=SEGV_BNDERR */
struct {
char _dummy_bnd [ __ADDR_BND_PKEY_PAD ] ;
void __user * _lower ;
void __user * _upper ;
} _addr_bnd ;
/* used when si_code=SEGV_PKUERR */
struct {
char _dummy_pkey [ __ADDR_BND_PKEY_PAD ] ;
__u32 _pkey ;
} _addr_pkey ;
2021-04-08 12:36:00 +02:00
/* used when si_code=TRAP_PERF */
signal, perf: Fix siginfo_t by avoiding u64 on 32-bit architectures
The alignment of a structure is that of its largest member. On
architectures like 32-bit Arm (but not e.g. 32-bit x86) 64-bit integers
will require 64-bit alignment and not its natural word size.
This means that there is no portable way to add 64-bit integers to
siginfo_t on 32-bit architectures without breaking the ABI, because
siginfo_t does not yet (and therefore likely never will) contain 64-bit
fields on 32-bit architectures. Adding a 64-bit integer could change the
alignment of the union after the 3 initial int si_signo, si_errno,
si_code, thus introducing 4 bytes of padding shifting the entire union,
which would break the ABI.
One alternative would be to use the __packed attribute, however, it is
non-standard C. Given siginfo_t has definitions outside the Linux kernel
in various standard libraries that can be compiled with any number of
different compilers (not just those we rely on), using non-standard
attributes on siginfo_t should be avoided to ensure portability.
In the case of the si_perf field, word size is sufficient since there is
no exact requirement on size, given the data it contains is user-defined
via perf_event_attr::sig_data. On 32-bit architectures, any excess bits
of perf_event_attr::sig_data will therefore be truncated when copying
into si_perf.
Since si_perf is intended to disambiguate events (e.g. encoding relevant
information if there are more events of the same type), 32 bits should
provide enough entropy to do so on 32-bit architectures.
For 64-bit architectures, no change is intended.
Fixes: fb6cc127e0b6 ("signal: Introduce TRAP_PERF si_code and si_perf to siginfo")
Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
Reported-by: Jon Hunter <jonathanh@nvidia.com>
Signed-off-by: Marco Elver <elver@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Tested-by: Jon Hunter <jonathanh@nvidia.com>
Link: https://lkml.kernel.org/r/20210422191823.79012-1-elver@google.com
2021-04-22 21:18:22 +02:00
unsigned long _perf ;
2018-04-18 17:48:49 -05:00
} ;
} _sigfault ;
/* SIGPOLL */
struct {
__ARCH_SI_BAND_T _band ; /* POLL_IN, POLL_OUT, POLL_MSG */
int _fd ;
} _sigpoll ;
/* SIGSYS */
struct {
void __user * _call_addr ; /* calling user insn */
int _syscall ; /* triggering system call number */
unsigned int _arch ; /* AUDIT_ARCH_* of syscall */
} _sigsys ;
} ;
# ifndef __ARCH_HAS_SWAPPED_SIGINFO
# define __SIGINFO \
struct { \
int si_signo ; \
int si_errno ; \
int si_code ; \
union __sifields _sifields ; \
}
# else
# define __SIGINFO \
struct { \
int si_signo ; \
int si_code ; \
int si_errno ; \
union __sifields _sifields ; \
}
# endif /* __ARCH_HAS_SWAPPED_SIGINFO */
typedef struct siginfo {
union {
__SIGINFO ;
int _si_pad [ SI_MAX_SIZE / sizeof ( int ) ] ;
} ;
2012-10-04 18:20:15 +01:00
} __ARCH_SI_ATTRIBUTES siginfo_t ;
/*
* How these fields are to be accessed .
*/
# define si_pid _sifields._kill._pid
# define si_uid _sifields._kill._uid
# define si_tid _sifields._timer._tid
# define si_overrun _sifields._timer._overrun
# define si_sys_private _sifields._timer._sys_private
# define si_status _sifields._sigchld._status
# define si_utime _sifields._sigchld._utime
# define si_stime _sifields._sigchld._stime
# define si_value _sifields._rt._sigval
# define si_int _sifields._rt._sigval.sival_int
# define si_ptr _sifields._rt._sigval.sival_ptr
# define si_addr _sifields._sigfault._addr
# define si_trapno _sifields._sigfault._trapno
# define si_addr_lsb _sifields._sigfault._addr_lsb
2014-11-14 07:18:19 -08:00
# define si_lower _sifields._sigfault._addr_bnd._lower
# define si_upper _sifields._sigfault._addr_bnd._upper
2017-07-31 10:08:59 -05:00
# define si_pkey _sifields._sigfault._addr_pkey._pkey
2021-04-08 12:36:00 +02:00
# define si_perf _sifields._sigfault._perf
2012-10-04 18:20:15 +01:00
# define si_band _sifields._sigpoll._band
# define si_fd _sifields._sigpoll._fd
# define si_call_addr _sifields._sigsys._call_addr
# define si_syscall _sifields._sigsys._syscall
# define si_arch _sifields._sigsys._arch
/*
* si_code values
* Digital reserves positive values for kernel - generated signals .
*/
# define SI_USER 0 /* sent by kill, sigsend, raise */
# define SI_KERNEL 0x80 /* sent by the kernel from somewhere */
# define SI_QUEUE -1 /* sent by sigqueue */
2017-07-16 22:36:59 -05:00
# define SI_TIMER -2 /* sent by timer expiration */
# define SI_MESGQ -3 /* sent by real time mesq state change */
2012-10-04 18:20:15 +01:00
# define SI_ASYNCIO -4 /* sent by AIO completion */
2017-07-16 22:36:59 -05:00
# define SI_SIGIO -5 /* sent by queued SIGIO */
2012-10-04 18:20:15 +01:00
# define SI_TKILL -6 /* sent by tkill system call */
# define SI_DETHREAD -7 /* sent by execve() killing subsidiary threads */
2017-07-24 14:46:09 -05:00
# define SI_ASYNCNL -60 /* sent by glibc async name lookup completion */
2012-10-04 18:20:15 +01:00
# define SI_FROMUSER(siptr) ((siptr)->si_code <= 0)
# define SI_FROMKERNEL(siptr) ((siptr)->si_code > 0)
/*
* SIGILL si_codes
*/
2017-07-16 22:36:59 -05:00
# define ILL_ILLOPC 1 /* illegal opcode */
# define ILL_ILLOPN 2 /* illegal operand */
# define ILL_ILLADR 3 /* illegal addressing mode */
# define ILL_ILLTRP 4 /* illegal trap */
# define ILL_PRVOPC 5 /* privileged opcode */
# define ILL_PRVREG 6 /* privileged register */
# define ILL_COPROC 7 /* coprocessor error */
# define ILL_BADSTK 8 /* internal stack error */
2018-03-15 13:30:51 +01:00
# define ILL_BADIADDR 9 /* unimplemented instruction address */
# define __ILL_BREAK 10 /* illegal break */
# define __ILL_BNDMOD 11 /* bundle-update (modification) in progress */
2018-01-13 18:57:14 -06:00
# define NSIGILL 11
2012-10-04 18:20:15 +01:00
/*
* SIGFPE si_codes
*/
2017-07-16 22:36:59 -05:00
# define FPE_INTDIV 1 /* integer divide by zero */
# define FPE_INTOVF 2 /* integer overflow */
# define FPE_FLTDIV 3 /* floating point divide by zero */
# define FPE_FLTOVF 4 /* floating point overflow */
# define FPE_FLTUND 5 /* floating point underflow */
# define FPE_FLTRES 6 /* floating point inexact result */
# define FPE_FLTINV 7 /* floating point invalid operation */
# define FPE_FLTSUB 8 /* subscript out of range */
2018-03-15 13:30:51 +01:00
# define __FPE_DECOVF 9 /* decimal overflow */
# define __FPE_DECDIV 10 /* decimal division by zero */
# define __FPE_DECERR 11 /* packed decimal error */
# define __FPE_INVASC 12 /* invalid ASCII digit */
# define __FPE_INVDEC 13 /* invalid decimal digit */
2018-03-01 17:44:06 +00:00
# define FPE_FLTUNK 14 /* undiagnosed floating-point exception */
2018-01-13 19:32:43 -06:00
# define FPE_CONDTRAP 15 /* trap on condition */
# define NSIGFPE 15
2012-10-04 18:20:15 +01:00
/*
* SIGSEGV si_codes
*/
2017-07-16 22:36:59 -05:00
# define SEGV_MAPERR 1 /* address not mapped to object */
# define SEGV_ACCERR 2 /* invalid permissions for mapped object */
2018-03-09 11:31:48 +01:00
# define SEGV_BNDERR 3 /* failed address bound checks */
2018-01-13 18:57:14 -06:00
# ifdef __ia64__
# define __SEGV_PSTKOVF 4 /* paragraph stack overflow */
# else
# define SEGV_PKUERR 4 /* failed protection key checks */
# endif
2018-02-21 10:15:43 -07:00
# define SEGV_ACCADI 5 /* ADI not enabled for mapped object */
# define SEGV_ADIDERR 6 /* Disrupting MCD error */
# define SEGV_ADIPERR 7 /* Precise MCD exception */
2019-08-07 12:21:05 +01:00
# define SEGV_MTEAERR 8 /* Asynchronous ARM MTE error */
# define SEGV_MTESERR 9 /* Synchronous ARM MTE exception */
# define NSIGSEGV 9
2012-10-04 18:20:15 +01:00
/*
* SIGBUS si_codes
*/
2017-07-16 22:36:59 -05:00
# define BUS_ADRALN 1 /* invalid address alignment */
# define BUS_ADRERR 2 /* non-existent physical address */
# define BUS_OBJERR 3 /* object specific hardware error */
2012-10-04 18:20:15 +01:00
/* hardware memory error consumed on a machine check: action required */
2018-03-09 11:31:48 +01:00
# define BUS_MCEERR_AR 4
2012-10-04 18:20:15 +01:00
/* hardware memory error detected in process but not consumed: action optional*/
2017-07-16 22:36:59 -05:00
# define BUS_MCEERR_AO 5
2012-10-04 18:20:15 +01:00
# define NSIGBUS 5
/*
* SIGTRAP si_codes
*/
2017-07-16 22:36:59 -05:00
# define TRAP_BRKPT 1 /* process breakpoint */
# define TRAP_TRACE 2 /* process trace trap */
# define TRAP_BRANCH 3 /* process taken branch trap */
# define TRAP_HWBKPT 4 /* hardware breakpoint/watchpoint */
2018-04-17 16:18:25 -05:00
# define TRAP_UNK 5 /* undiagnosed trap */
2021-04-08 12:36:00 +02:00
# define TRAP_PERF 6 /* perf event with sigtrap=1 */
# define NSIGTRAP 6
2012-10-04 18:20:15 +01:00
2017-06-26 13:09:03 -05:00
/*
2018-02-06 15:39:27 -08:00
* There is an additional set of SIGTRAP si_codes used by ptrace
* that are of the form : ( ( PTRACE_EVENT_XXX < < 8 ) | SIGTRAP )
2017-06-26 13:09:03 -05:00
*/
2012-10-04 18:20:15 +01:00
/*
* SIGCHLD si_codes
*/
2017-07-16 22:36:59 -05:00
# define CLD_EXITED 1 /* child has exited */
# define CLD_KILLED 2 /* child was killed */
# define CLD_DUMPED 3 /* child terminated abnormally */
# define CLD_TRAPPED 4 /* traced child has trapped */
# define CLD_STOPPED 5 /* child has stopped */
# define CLD_CONTINUED 6 /* stopped child has continued */
2012-10-04 18:20:15 +01:00
# define NSIGCHLD 6
/*
2017-06-29 09:28:50 -05:00
* SIGPOLL ( or any other signal without signal specific si_codes ) si_codes
2012-10-04 18:20:15 +01:00
*/
2017-07-16 22:36:59 -05:00
# define POLL_IN 1 /* data input available */
# define POLL_OUT 2 /* output buffers available */
# define POLL_MSG 3 /* input message available */
# define POLL_ERR 4 /* i/o error */
# define POLL_PRI 5 /* high priority input available */
# define POLL_HUP 6 /* device disconnected */
2012-10-04 18:20:15 +01:00
# define NSIGPOLL 6
/*
* SIGSYS si_codes
*/
2017-07-16 22:36:59 -05:00
# define SYS_SECCOMP 1 /* seccomp triggered */
2020-11-27 14:32:33 -05:00
# define SYS_USER_DISPATCH 2 /* syscall user dispatch triggered */
# define NSIGSYS 2
2012-10-04 18:20:15 +01:00
2018-04-18 19:15:59 -05:00
/*
* SIGEMT si_codes
*/
# define EMT_TAGOVF 1 /* tag overflow */
# define NSIGEMT 1
2012-10-04 18:20:15 +01:00
/*
* sigevent definitions
*
* It seems likely that SIGEV_THREAD will have to be handled from
* userspace , libpthread transmuting it to SIGEV_SIGNAL , which the
* thread manager then catches and does the appropriate nonsense .
* However , everything is written out here so as to not get lost .
*/
# define SIGEV_SIGNAL 0 /* notify via signal */
# define SIGEV_NONE 1 /* other notification: meaningless */
# define SIGEV_THREAD 2 /* deliver via thread creation */
# define SIGEV_THREAD_ID 4 /* deliver to thread */
/*
* This works because the alignment is ok on all current architectures
* but we leave open this being overridden in the future
*/
# ifndef __ARCH_SIGEV_PREAMBLE_SIZE
# define __ARCH_SIGEV_PREAMBLE_SIZE (sizeof(int) * 2 + sizeof(sigval_t))
# endif
# define SIGEV_MAX_SIZE 64
# define SIGEV_PAD_SIZE ((SIGEV_MAX_SIZE - __ARCH_SIGEV_PREAMBLE_SIZE) \
/ sizeof ( int ) )
typedef struct sigevent {
sigval_t sigev_value ;
int sigev_signo ;
int sigev_notify ;
union {
int _pad [ SIGEV_PAD_SIZE ] ;
int _tid ;
struct {
void ( * _function ) ( sigval_t ) ;
void * _attribute ; /* really pthread_attr_t */
} _sigev_thread ;
} _sigev_un ;
} sigevent_t ;
# define sigev_notify_function _sigev_un._sigev_thread._function
# define sigev_notify_attributes _sigev_un._sigev_thread._attribute
# define sigev_notify_thread_id _sigev_un._tid
# endif /* _UAPI_ASM_GENERIC_SIGINFO_H */