[PATCH 0/5] linux: Extend 32-bit syscall arguments when the kernel reads as long (BZ 34917)
Adhemerval Zanella
adhemerval.zanella@linaro.org
Thu Nov 5 17:13:06 GMT 2026
The kernel declares some syscall arguments as long or unsigned long
where the glibc interface uses int or unsigned int, and it uses all 64
bits of the register. The x86_64, x32, and AArch64 calling conventions
leave the upper 32 bits of a 32-bit argument unspecified, so a valid
call can fail when the caller leaves garbage there. The other 64-bit ABIs
extend 32-bit arguments in the caller and are not affected.
Patch 1 makes the x86_64 inline syscall macros cast each argument to
long int, as the x32 and AArch64 macros already do. This fixes the C
wrappers (ptrace, pkey_mprotect, mmap). It also adds a test that calls
each affected function with garbage in the upper half of its 32-bit
arguments.
Patches 2-5 move mprotect, pkey_alloc, remap_file_pages, and unshare
from syscalls.list to C, since the generated assembly wrappers pass the
registers through unchanged on all three ABIs.
Adhemerval Zanella (5):
x86_64: Extend 32-bit syscall arguments to the full register (BZ
34917)
linux: Implement mprotect in C (BZ 34917)
linux: Implement pkey_alloc in C (BZ 34917)
linux: Implement remap_file_pages in C (BZ 34917)
linux: Implement unshare in C (BZ 34917)
sysdeps/unix/syscalls.list | 1 -
sysdeps/unix/sysv/linux/Makefile | 3 +
sysdeps/unix/sysv/linux/mprotect.c | 28 +++
sysdeps/unix/sysv/linux/pkey_alloc.c | 28 +++
sysdeps/unix/sysv/linux/remap_file_pages.c | 33 +++
sysdeps/unix/sysv/linux/syscalls.list | 3 -
.../unix/sysv/linux/tst-syscall-upper-bits.c | 215 ++++++++++++++++++
sysdeps/unix/sysv/linux/unshare.c | 26 +++
sysdeps/unix/sysv/linux/x86_64/sysdep.h | 13 +-
9 files changed, 340 insertions(+), 10 deletions(-)
create mode 100644 sysdeps/unix/sysv/linux/mprotect.c
create mode 100644 sysdeps/unix/sysv/linux/pkey_alloc.c
create mode 100644 sysdeps/unix/sysv/linux/remap_file_pages.c
create mode 100644 sysdeps/unix/sysv/linux/tst-syscall-upper-bits.c
create mode 100644 sysdeps/unix/sysv/linux/unshare.c
--
2.53.0
More information about the Libc-alpha
mailing list