linux/include/uapi
Marco Elver 3ddb3fd8cd 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: fb6cc127e0 ("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-23 09:03:16 +02:00
..
asm-generic signal, perf: Fix siginfo_t by avoiding u64 on 32-bit architectures 2021-04-23 09:03:16 +02:00
drm - HDCP 2.2 and HDCP 1.4 Gen12 DP MST support (Anshuman) 2021-01-29 17:05:15 +10:00
linux perf: Extend PERF_TYPE_HARDWARE and PERF_TYPE_HW_CACHE 2021-04-19 20:03:29 +02:00
misc habanalabs: return block size + block ID 2021-02-08 18:20:08 +02:00
mtd MTD: mtd-abi.h: drop a duplicated word 2020-08-02 23:00:10 +02:00
rdma Linux 5.11 2021-02-18 11:19:29 -04:00
scsi scsi: fc: Update formal FPIN descriptor definitions 2020-10-26 18:06:45 -04:00
sound Auxiliary Bus support tag for 5.11-rc1 2020-12-04 20:39:45 +00:00
video
xen xen/gntdev: gntdev.h: drop a duplicated word 2020-08-03 07:46:42 +02:00
Kbuild