[PATCH] sigaction: don't sign-extend sa_flags

Florian Weimer fweimer@redhat.com
Mon Jun 2 09:24:03 GMT 2025


* наб:

> Before:
>   rt_sigaction(SIGBUS, {sa_handler=0x55abb9960139, sa_mask=[], sa_flags=SA_RESTORER|SA_RESETHAND|SA_SIGINFO|0xffffffff00000000, sa_restorer=0x7fb1b2a82050}, NULL, 8) = 0
>
> After:
>   rt_sigaction(SIGBUS, {sa_handler=0x7f6a70dce139, sa_mask=[], sa_flags=SA_RESTORER|SA_RESETHAND|SA_SIGINFO, sa_restorer=0x7f6a70c28f60}, NULL, 8) = 0
>
> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>

I wonder if this is something that should be fixed in strace?

It's not that the kernel can start using the upper bits with some
compatibility check (e.g., bits 32 and 33 have to be distinct).

> ---
>  sysdeps/unix/sysv/linux/libc_sigaction.c        | 2 +-
>  sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/sysdeps/unix/sysv/linux/libc_sigaction.c b/sysdeps/unix/sysv/linux/libc_sigaction.c
> index bbfc177655..f349f8660b 100644
> --- a/sysdeps/unix/sysv/linux/libc_sigaction.c
> +++ b/sysdeps/unix/sysv/linux/libc_sigaction.c
> @@ -49,7 +49,7 @@ __libc_sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
>      {
>        kact.k_sa_handler = act->sa_handler;
>        memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
> -      kact.sa_flags = act->sa_flags;
> +      kact.sa_flags = (unsigned)act->sa_flags;
>        SET_SA_RESTORER (&kact, act);
>      }

Our style looks more like this:

  kact.sa_flags = (unsigned int) act->sa_flags;

> diff --git a/sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c b/sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c
> index 006c532127..812e023584 100644
> --- a/sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c
> +++ b/sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c
> @@ -22,7 +22,7 @@
>  extern void restore_rt (void) asm ("__restore_rt") attribute_hidden;
>  
>  #define SET_SA_RESTORER(kact, act)			\
> -  (kact)->sa_flags = (act)->sa_flags | SA_RESTORER;	\
> +  (kact)->sa_flags |= SA_RESTORER;			\
>    (kact)->sa_restorer = &restore_rt
>  
>  #define RESET_SA_RESTORER(act, kact) 			\

I looked at the other architectures, and they already use this
construct.

Thanks,
Florian



More information about the Libc-alpha mailing list