From 8c2f6218f81ab5303e07bad4e13f181aa9581d92 Mon Sep 17 00:00:00 2001 From: Pavel Kozlov Date: Tue, 17 Oct 2023 14:01:22 +0400 Subject: setrlimit/getrlimit: fix prlimit64 syscall use for 32-bit CPUs Commit 95e38b37 ("add support for systems without legacy setrlimit/getrlimit syscalls") has added use of the prlimit64 syscall in getrlimit and setrlimit functions. This change causes memory corruption on getrlimit call for 32-bit CPUs like ARC, as ARC doesn't have ugetrlimit syscall and uses prlimit64. Also, setrlimit has been broken by prlimit64 call on 32-bit CPUs like, i386, ARM, ARC. For the prlimit64 syscall the kernel expects an rlimit struct with 64-bit fields, but on 32-bit CPUs without _FILE_OFFSET_BITS=64 the struct rlimit has 32-bit fields. Add safe implementations of getrlimit, setrlimit, prlimit for 32-bit CPUs with a local struct rlimit64 variable for use in the prlimit64 syscall. For 64-bit CPUs and configurations with _FILE_OFFSET_BITS=64 use getrlimit, setrlimit, prlimit as aliases to getrlimit64, setrlimit64 and prlimit64. Add a new function prlimit64. Tested on aarch64, arm, i386, arc. Fixes: 95e38b37 ("add support for systems without legacy setrlimit/getrlimit syscalls") Signed-off-by: Pavel Kozlov --- include/sys/resource.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/sys/resource.h b/include/sys/resource.h index 00c63ff0f..e9fac2c65 100644 --- a/include/sys/resource.h +++ b/include/sys/resource.h @@ -106,6 +106,10 @@ libc_hidden_proto(setpriority) extern int prlimit (__pid_t __pid, enum __rlimit_resource __resource, const struct rlimit *__new_limit, struct rlimit *__old_limit) __THROW; + +extern int prlimit64 (__pid_t __pid, enum __rlimit_resource __resource, + const struct rlimit64 *__new_limit, + struct rlimit64 *__old_limit) __THROW; #endif __END_DECLS -- cgit v1.2.3