[PATCH v2] linux: Enforce zero fill of siginfo_t
mengqinggang
mengqinggang@loongson.cn
Tue Apr 21 08:34:32 GMT 2026
Gcc zero-initialize the whole struct like this:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124356
Struct siginfo has an extra "int __pad0" if __WORDSIZE == 64.
sysdeps/unix/sysv/linux/bits/types/siginfo_t.h
36 typedef struct
37 {
38 int si_signo; /* Signal number. */
39 #if __SI_ERRNO_THEN_CODE
40 int si_errno; /* If non-zero, an errno value
associated with
41 this signal, as defined in
<errno.h>. */
42 int si_code; /* Signal code. */
43 #else
44 int si_code;
45 int si_errno;
46 #endif
47 #if __WORDSIZE == 64
48 int __pad0; /* Explicit padding. */
49 #endif
This initialization code causes gcc to zero the whole struct only on
64-bit targets.
213 siginfo_t info =
214 {
215 .si_signo = SIGUSR2,
216 .si_errno = EAGAIN,
217 .si_code = -10,
218 .si_pid = ppid,
219 .si_uid = puid
220 };
So I think this patch is necessary for 32-bit targets.
在 2026/4/21 14:25, Florian Weimer 写道:
> * Adhemerval Zanella:
>
>> The glibc siginfo struct is larger than the kABI one, and the kernel
>> enforces that for an unknown si_code, all the extra bytes should be 0
>> (post_copy_siginfo_from_user).
> I still think the explanation of this change is wrong (I think it's that
> designated initializers with unions do not necessary zero-initialize
> inactive members), but the code change itself is correct.
>
> Thanks,
> Florian
More information about the Libc-alpha
mailing list