zfs/cmd
Rob N 27cc6df760 Use memset to zero stack allocations containing unions
C99 6.7.8.17 says that when an undesignated initialiser is used, only
the first element of a union is initialised. If the first element is not
the largest within the union, how the remaining space is initialised is
up to the compiler.

GCC extends the initialiser to the entire union, while Clang treats the
remainder as padding, and so initialises according to whatever
automatic/implicit initialisation rules are currently active.

When Linux is compiled with CONFIG_INIT_STACK_ALL_PATTERN,
-ftrivial-auto-var-init=pattern is added to the kernel CFLAGS. This flag
sets the policy for automatic/implicit initialisation of variables on
the stack.

Taken together, this means that when compiling under
CONFIG_INIT_STACK_ALL_PATTERN on Clang, the "zero" initialiser will only
zero the first element in a union, and the rest will be filled with a
pattern. This is significant for aes_ctx_t, which in
aes_encrypt_atomic() and aes_decrypt_atomic() is initialised to zero,
but then used as a gcm_ctx_t, which is the fifth element in the union,
and thus gets pattern initialisation. Later, it's assumed to be zero,
resulting in a hang.

As confusing and undiscoverable as it is, by the spec, we are at fault
when we initialise a structure containing a union with the zero
initializer. As such, this commit replaces these uses with an explicit
memset(0).

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Tino Reichardt <milky-zfs@mcmilk.de>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Closes #16135
Closes #16206
2024-07-17 14:54:47 -07:00
..
raidz_test Fix multiplication converted to larger type 2022-10-28 09:30:37 -07:00
zdb zdb: bring crash handling over from ztest 2024-07-17 14:54:47 -07:00
zed Add slow disk diagnosis to ZED 2024-04-29 13:50:05 -07:00
zfs Add support for zfs mount -R <filesystem> 2024-04-22 09:28:06 -07:00
zinject Add slow disk diagnosis to ZED 2024-04-29 13:50:05 -07:00
zpool vdev probe to slow disk can stall mmp write checker 2024-04-30 10:01:15 -07:00
zpool_influxdb Do not report bytes skipped by scan as issued. 2023-06-30 08:47:13 -07:00
zstream Use memset to zero stack allocations containing unions 2024-07-17 14:54:47 -07:00
Makefile.am Add zilstat script to report zil kstats in a user friendly manner 2022-09-02 13:24:07 -07:00
arc_summary Speculative prefetch for reordered requests 2024-04-19 10:13:38 -07:00
arcstat.in Fix arcstats for FreeBSD after zfetch support 2024-04-29 13:50:05 -07:00
dbufstat.in Replace dead opensolaris.org license link 2022-07-11 14:16:13 -07:00
fsck.zfs.in cmd: move single-file binaries up, extract udev programs to udev/ 2022-05-10 10:20:34 -07:00
mount_zfs.c nvpair: Constify string functions 2023-03-14 15:25:50 -07:00
zfs_ids_to_path.c Replace dead opensolaris.org license link 2022-07-11 14:16:13 -07:00
zgenhostid.c Replace dead opensolaris.org license link 2022-07-11 14:16:13 -07:00
zhack.c Allow zhack label repair to restore detached devices. 2023-05-03 09:03:57 -07:00
zilstat.in zil: Add some more statistics. 2023-05-25 13:51:53 -07:00
ztest.c Replace P2ALIGN with P2ALIGN_TYPED and delete P2ALIGN. 2024-05-13 10:27:38 -05:00
zvol_wait zvol_wait logic may terminate prematurely 2022-10-11 12:12:04 -07:00