[PATCH] sigaction: don't sign-extend sa_flags
Dmitry V. Levin
ldv@strace.io
Mon Jun 2 22:24:56 GMT 2025
On Mon, Jun 02, 2025 at 04:39:35PM +0200, Florian Weimer wrote:
> * Andreas Schwab:
> > On Jun 02 2025, Adhemerval Zanella Netto wrote:
> >
> >> So I think it should be fixed on strace as well
> >
> > strace just shows what is passed to the kernel, I don't see anything
> > wrong with that.
>
> It's a borderline case. In many cases, strace masks out values that are
> ignored by the kernel, such as the third argument to open, or upper
> halves of 64-bit registers if the system call definition uses an
> unsigned int type.
In strace, we usually mask out unused bits when the kernel in known to
consistently ignore those bits across all supported kernel versions.
In this case, the kernel behaviour changed by commit v5.11-rc1~136^2~4 [1].
Before that commit, unused bits weren't fully cleared, neither when
storing the userspace-provided sa_flags nor when returning them later
via oldact argument.
Taking this into consideration, I don't think it would be correct for
strace to ignore those bits for kernel versions prior to v5.11.
Given that glibc by default also supports kernel versions prior to v5.11,
it seems to me that it should avoid sign-extending sa_flags. By the way,
is there any reason why glibc sign-extends sa_flags in the first place?
[1] https://git.kernel.org/torvalds/c/23acdc76f1798b090bb9dcc90671cd29d929834e
--
ldv
More information about the Libc-alpha
mailing list