diff mbox series

[uclibc-ng-devel] rlimit: fix 64-bit RLIM64_INFINITY macro

Message ID 20231117085731.5675-1-kozlov@synopsys.com
State Accepted
Headers show
Series [uclibc-ng-devel] rlimit: fix 64-bit RLIM64_INFINITY macro | expand

Commit Message

Pavel Kozlov Nov. 17, 2023, 8:57 a.m. UTC
From: Pavel Kozlov <pavel.kozlov@synopsys.com>

Linux kernel returns -1ULL as RLIM64_INFINITY for all cpus.

Fix RLIM64_INFINTIY and 64-bit variant of RLIM_INFINITY macro for
sparc, mips, alpha, as for these CPUs the library uses different
value than what the kernel sets and it can cause incorrect
RLIM64_INFINTY check.
Because alpha is a 64-bit arch, fix the RLIM_INFINITY macro twice
(the value should be the same with and without __USE_FILE_OFFSET64
definition) to match the prlimit64 syscall in the kernel.

Previous implementation of setrlimit/getrlimit functions didn't use
prlimit64 syscall and didn't receive RLIM64_INFINTIY from the kernel,
RLIM64_INFINTY macro was used by the library itself to mimic the
64-bit rlimit in the getrlimit64/setrlimit64 functions, that allowed
to have RLIM64_INFINTIY different from what the kernel sets.

New implementation of setrlimit/getrlimit uses prlimit64 and checks
for RLIM64_INFINITY value and must have equal RLIM64_INFINITY
definition with what the kernel uses.

This issue is indicated by the tst-rlim/tst-rlim64 tests
on sparc/mips32/alpha, tests return 23 (UNSUPPORTED) because of
incorrect RLIM_INFINTY check for available rlimit type.

This patch will require rebuild of sparc/mips32/alpha binaries that
explicitly use RLIM64_INFINTY or 64-bit variant of RLIM_INFINITY
(if binary for 32-bit CPU was built with _FILE_OFFSET_BITS=64) to
update the macro value.

Signed-off-by: Pavel Kozlov <pavel.kozlov@synopsys.com>
---
 libc/sysdeps/linux/alpha/bits/resource.h   | 6 +++---
 libc/sysdeps/linux/mips/bits/resource.h    | 4 ++--
 libc/sysdeps/linux/sparc/bits/resource.h   | 4 ++--
 libc/sysdeps/linux/sparc64/bits/resource.h | 4 ++--
 4 files changed, 9 insertions(+), 9 deletions(-)

Comments

Waldemar Brodkorb Nov. 20, 2023, 8:53 a.m. UTC | #1
Hi Pavel,

all open patches from you committed and pushed,

Thanks for the follow up fix!

best regards
 Waldemar

Pavel Kozlov wrote,

> From: Pavel Kozlov <pavel.kozlov@synopsys.com>
> 
> Linux kernel returns -1ULL as RLIM64_INFINITY for all cpus.
> 
> Fix RLIM64_INFINTIY and 64-bit variant of RLIM_INFINITY macro for
> sparc, mips, alpha, as for these CPUs the library uses different
> value than what the kernel sets and it can cause incorrect
> RLIM64_INFINTY check.
> Because alpha is a 64-bit arch, fix the RLIM_INFINITY macro twice
> (the value should be the same with and without __USE_FILE_OFFSET64
> definition) to match the prlimit64 syscall in the kernel.
> 
> Previous implementation of setrlimit/getrlimit functions didn't use
> prlimit64 syscall and didn't receive RLIM64_INFINTIY from the kernel,
> RLIM64_INFINTY macro was used by the library itself to mimic the
> 64-bit rlimit in the getrlimit64/setrlimit64 functions, that allowed
> to have RLIM64_INFINTIY different from what the kernel sets.
> 
> New implementation of setrlimit/getrlimit uses prlimit64 and checks
> for RLIM64_INFINITY value and must have equal RLIM64_INFINITY
> definition with what the kernel uses.
> 
> This issue is indicated by the tst-rlim/tst-rlim64 tests
> on sparc/mips32/alpha, tests return 23 (UNSUPPORTED) because of
> incorrect RLIM_INFINTY check for available rlimit type.
> 
> This patch will require rebuild of sparc/mips32/alpha binaries that
> explicitly use RLIM64_INFINTY or 64-bit variant of RLIM_INFINITY
> (if binary for 32-bit CPU was built with _FILE_OFFSET_BITS=64) to
> update the macro value.
> 
> Signed-off-by: Pavel Kozlov <pavel.kozlov@synopsys.com>
diff mbox series

Patch

diff --git a/libc/sysdeps/linux/alpha/bits/resource.h b/libc/sysdeps/linux/alpha/bits/resource.h
index 38f73961e99d..dba818714d84 100644
--- a/libc/sysdeps/linux/alpha/bits/resource.h
+++ b/libc/sysdeps/linux/alpha/bits/resource.h
@@ -113,13 +113,13 @@  enum __rlimit_resource
 
 /* Value to indicate that there is no limit.  */
 #ifndef __USE_FILE_OFFSET64
-# define RLIM_INFINITY ((long int)(~0UL >> 1))
+# define RLIM_INFINITY ((unsigned long int)(~0UL))
 #else
-# define RLIM_INFINITY 0x7fffffffffffffffLL
+# define RLIM_INFINITY 0xffffffffffffffffULL
 #endif
 
 #ifdef __USE_LARGEFILE64
-# define RLIM64_INFINITY 0x7fffffffffffffffLL
+# define RLIM64_INFINITY 0xffffffffffffffffULL
 #endif
 
 /* We can represent all limits.  */
diff --git a/libc/sysdeps/linux/mips/bits/resource.h b/libc/sysdeps/linux/mips/bits/resource.h
index 5690527bf9a3..97487d274f21 100644
--- a/libc/sysdeps/linux/mips/bits/resource.h
+++ b/libc/sysdeps/linux/mips/bits/resource.h
@@ -123,10 +123,10 @@  enum __rlimit_resource
 # ifndef __USE_FILE_OFFSET64
 #  define RLIM_INFINITY ((long int)(~0UL >> 1))
 # else
-#  define RLIM_INFINITY 0x7fffffffffffffffULL
+#  define RLIM_INFINITY 0xffffffffffffffffULL
 # endif
 # ifdef __USE_LARGEFILE64
-#  define RLIM64_INFINITY 0x7fffffffffffffffULL
+#  define RLIM64_INFINITY 0xffffffffffffffffULL
 # endif
 #endif
 
diff --git a/libc/sysdeps/linux/sparc/bits/resource.h b/libc/sysdeps/linux/sparc/bits/resource.h
index a5ec31e4e677..48e1049f41a6 100644
--- a/libc/sysdeps/linux/sparc/bits/resource.h
+++ b/libc/sysdeps/linux/sparc/bits/resource.h
@@ -114,11 +114,11 @@  enum __rlimit_resource
 #ifndef __USE_FILE_OFFSET64
 # define RLIM_INFINITY ((long int)(~0UL >> 1))
 #else
-# define RLIM_INFINITY 0x7fffffffffffffffLL
+# define RLIM_INFINITY 0xffffffffffffffffULL
 #endif
 
 #ifdef __USE_LARGEFILE64
-# define RLIM64_INFINITY 0x7fffffffffffffffLL
+# define RLIM64_INFINITY 0xffffffffffffffffULL
 #endif
 
 /* We can represent all limits.  */
diff --git a/libc/sysdeps/linux/sparc64/bits/resource.h b/libc/sysdeps/linux/sparc64/bits/resource.h
index f1e11e239602..84c76878520d 100644
--- a/libc/sysdeps/linux/sparc64/bits/resource.h
+++ b/libc/sysdeps/linux/sparc64/bits/resource.h
@@ -128,11 +128,11 @@  enum __rlimit_resource
 #ifndef __USE_FILE_OFFSET64
 # define RLIM_INFINITY ((long int)(~0UL >> 1))
 #else
-# define RLIM_INFINITY 0x7fffffffffffffffLL
+# define RLIM_INFINITY 0xffffffffffffffffULL
 #endif
 
 #ifdef __USE_LARGEFILE64
-# define RLIM64_INFINITY 0x7fffffffffffffffLL
+# define RLIM64_INFINITY 0xffffffffffffffffULL
 #endif
 
 #endif