mbox series

[0/4] Fix getrlimit/setrlimit/prlimit on Alpha and 32-bit machines

Message ID 20180105132429.21118-1-aurelien@aurel32.net
Headers show
Series Fix getrlimit/setrlimit/prlimit on Alpha and 32-bit machines | expand

Message

Aurelien Jarno Jan. 5, 2018, 1:24 p.m. UTC
Since commit 045c13d185 ("Consolidate Linux setrlimit and getrlimit
implementation") which is in glibc 2.25, the getrlimit and setrlimit
functions are broken when used with RLIM_INFINITY on alpha. The commit
changed the syscalls behind these functions from getrlimit/setrlimit to
prlimit64. RLIM_INFINITY is not represented the same way in these
syscalls on alpha. The getrlimit/setrlimit syscalls use the same
definition than the GNU libc, that is 0x7fffffffffffffff while prlimit64
uses a standard value across all architectures which is 0xffffffffffffffff.

The commit therefore broke the getrlimit/setrlimit functions on alpha,
and is the reason why dozens of the glibc tests abort with:

  allocatestack.c:480: allocate_stack: Assertion `size != 0' failed.

This patch series fixes that in two steps, the first patch adds a
wrapper to fix the value before/after the syscall and can be backported
to stable branches. The second add a new symbol so that the
RLIM_INFINITY value can be changed to the same value as in the kernel
and other architectures.

The third patch fixes an issue with prlimit and RLIM_INFINITY on 32-bit
machines found while writing a test. The last patch add a test to detect
such issueS.

Aurelien Jarno (4):
  Alpha: Add wrappers to get/setrlimit64 to fix RLIM64_INFINITY constant
    [BZ #22648]
  Alpha: Fix the RLIM_INFINITY and RLIM64_INFINITY constants
  prlimit: Translate old_rlimit from RLIM64_INFINITY to RLIM_INFINITY
    [BZ #22678]
  Add test for getrlimit/setrlimit/prlimit with infinity value

 ChangeLog                                     |  41 +++++++
 sysdeps/unix/sysv/linux/Makefile              |   3 +-
 sysdeps/unix/sysv/linux/alpha/Versions        |   3 +
 sysdeps/unix/sysv/linux/alpha/bits/resource.h |   6 +-
 sysdeps/unix/sysv/linux/alpha/getrlimit64.c   |  56 +++++++++
 sysdeps/unix/sysv/linux/alpha/libc.abilist    |   4 +
 sysdeps/unix/sysv/linux/alpha/setrlimit64.c   |  53 +++++++++
 sysdeps/unix/sysv/linux/getrlimit64.c         |  18 +--
 sysdeps/unix/sysv/linux/prlimit.c             |  15 ++-
 sysdeps/unix/sysv/linux/setrlimit64.c         |   5 +
 sysdeps/unix/sysv/linux/tst-rlimit-infinity.c | 157 ++++++++++++++++++++++++++
 11 files changed, 342 insertions(+), 19 deletions(-)
 create mode 100644 sysdeps/unix/sysv/linux/alpha/getrlimit64.c
 create mode 100644 sysdeps/unix/sysv/linux/alpha/setrlimit64.c
 create mode 100644 sysdeps/unix/sysv/linux/tst-rlimit-infinity.c

Comments

Joseph Myers Jan. 5, 2018, 11:55 p.m. UTC | #1
One of these patches breaks the testsuite build for various (but not all) 
32-bit configurations.

https://sourceware.org/ml/libc-testresults/2018-q1/msg00035.html

The failures are all of the form:

/scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc/io/test-lfs.o: In function `do_prepare':
/scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc-src/io/test-lfs.c:75: undefined reference to `getrlimit64'
collect2: error: ld returned 1 exit status
../Rules:202: recipe for target '/scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc/io/test-lfs' failed
make[3]: *** [/scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc/io/test-lfs] Error 1
Aurelien Jarno Jan. 6, 2018, 10 a.m. UTC | #2
On 2018-01-05 23:55, Joseph Myers wrote:
> One of these patches breaks the testsuite build for various (but not all) 
> 32-bit configurations.
> 
> https://sourceware.org/ml/libc-testresults/2018-q1/msg00035.html
> 
> The failures are all of the form:
> 
> /scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc/io/test-lfs.o: In function `do_prepare':
> /scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc-src/io/test-lfs.c:75: undefined reference to `getrlimit64'
> collect2: error: ld returned 1 exit status
> ../Rules:202: recipe for target '/scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc/io/test-lfs' failed
> make[3]: *** [/scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc/io/test-lfs] Error 1

Sorry about that. The issue happens on 32-bit configurations which have
a minimum version >= 2.2, and thus which don't need the 2GiB limited
compat getrlimit64. I wrongly moved one case under the #ifdef
__RLIM_T_MATCHES_RLIM64_T case, while it should have been copied
instead.

I am currently testing the following patch:

diff --git a/sysdeps/unix/sysv/linux/getrlimit64.c b/sysdeps/unix/sysv/linux/getrlimit64.c
index 1cc82e364d..a14ca58096 100644
--- a/sysdeps/unix/sysv/linux/getrlimit64.c
+++ b/sysdeps/unix/sysv/linux/getrlimit64.c
@@ -81,4 +81,7 @@ __old_getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits)
 }
 versioned_symbol (libc, __getrlimit64, getrlimit64, GLIBC_2_2);
 compat_symbol (libc, __old_getrlimit64, getrlimit64, GLIBC_2_1);
+#else
+weak_alias (__getrlimit64, getrlimit64)
+libc_hidden_weak (getrlimit64)
 #endif /* __RLIM_T_MATCHES_RLIM64_T  */
Aurelien Jarno Jan. 6, 2018, 11:01 a.m. UTC | #3
On 2018-01-06 11:00, Aurelien Jarno wrote:
> On 2018-01-05 23:55, Joseph Myers wrote:
> > One of these patches breaks the testsuite build for various (but not all) 
> > 32-bit configurations.
> > 
> > https://sourceware.org/ml/libc-testresults/2018-q1/msg00035.html
> > 
> > The failures are all of the form:
> > 
> > /scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc/io/test-lfs.o: In function `do_prepare':
> > /scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc-src/io/test-lfs.c:75: undefined reference to `getrlimit64'
> > collect2: error: ld returned 1 exit status
> > ../Rules:202: recipe for target '/scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc/io/test-lfs' failed
> > make[3]: *** [/scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc/io/test-lfs] Error 1
> 
> Sorry about that. The issue happens on 32-bit configurations which have
> a minimum version >= 2.2, and thus which don't need the 2GiB limited
> compat getrlimit64. I wrongly moved one case under the #ifdef
> __RLIM_T_MATCHES_RLIM64_T case, while it should have been copied
> instead.
> 
> I am currently testing the following patch:

It worked fine on arm-linux-gnueabihf with no regression. Here is the
full patch.


From 5551e9755c3bbcd0c6682a1626eb869596d201c6 Mon Sep 17 00:00:00 2001
From: Aurelien Jarno <aurelien@aurel32.net>
Date: Sat, 6 Jan 2018 11:48:16 +0100
Subject: [PATCH] getrlimit64: fix for 32-bit configurations with default
 version >= 2.2

Commit 24731685 ("prlimit: Translate old_rlimit from RLIM64_INFINITY to
RLIM_INFINITY") broken the getrlimit64 for 32-bit configurations which
do no need the 2GiB limited compat getrlimit (default version >= 2.2).

This patch fixes that by restoring the weak alias in that case.

Changelog:
	* sysdeps/unix/sysv/linux/getrlimit64 (getrlimit64)
	[!__RLIM_T_MATCHES_RLIM64_T]
	[!SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_2)]: Define as weak alias of
	__getrlimit64. Add libc_hidden_weak.
---
 ChangeLog                             | 7 +++++++
 sysdeps/unix/sysv/linux/getrlimit64.c | 3 +++
 2 files changed, 10 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 8833b1da33..303ded4877 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2018-01-06  Aurelien Jarno  <aurelien@aurel32.net>
+
+	* sysdeps/unix/sysv/linux/getrlimit64 (getrlimit64)
+	[!__RLIM_T_MATCHES_RLIM64_T]
+	[!SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_2)]: Define as weak alias of
+	__getrlimit64. Add libc_hidden_weak.
+
 2018-01-06  Samuel Thibault  <samuel.thibault@ens-lyon.org>
 
 	* sysdeps/mach/hurd/i386/jmp_buf-macros.h: New file.
diff --git a/sysdeps/unix/sysv/linux/getrlimit64.c b/sysdeps/unix/sysv/linux/getrlimit64.c
index 1cc82e364d..a14ca58096 100644
--- a/sysdeps/unix/sysv/linux/getrlimit64.c
+++ b/sysdeps/unix/sysv/linux/getrlimit64.c
@@ -81,4 +81,7 @@ __old_getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits)
 }
 versioned_symbol (libc, __getrlimit64, getrlimit64, GLIBC_2_2);
 compat_symbol (libc, __old_getrlimit64, getrlimit64, GLIBC_2_1);
+#else
+weak_alias (__getrlimit64, getrlimit64)
+libc_hidden_weak (getrlimit64)
 #endif /* __RLIM_T_MATCHES_RLIM64_T  */
Aurelien Jarno Jan. 7, 2018, 9:44 p.m. UTC | #4
On 2018-01-06 12:01, Aurelien Jarno wrote:
> On 2018-01-06 11:00, Aurelien Jarno wrote:
> > On 2018-01-05 23:55, Joseph Myers wrote:
> > > One of these patches breaks the testsuite build for various (but not all) 
> > > 32-bit configurations.
> > > 
> > > https://sourceware.org/ml/libc-testresults/2018-q1/msg00035.html
> > > 
> > > The failures are all of the form:
> > > 
> > > /scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc/io/test-lfs.o: In function `do_prepare':
> > > /scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc-src/io/test-lfs.c:75: undefined reference to `getrlimit64'
> > > collect2: error: ld returned 1 exit status
> > > ../Rules:202: recipe for target '/scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc/io/test-lfs' failed
> > > make[3]: *** [/scratch/jmyers/glibc-bot/build/glibcs/arm-linux-gnueabi/glibc/io/test-lfs] Error 1
> > 
> > Sorry about that. The issue happens on 32-bit configurations which have
> > a minimum version >= 2.2, and thus which don't need the 2GiB limited
> > compat getrlimit64. I wrongly moved one case under the #ifdef
> > __RLIM_T_MATCHES_RLIM64_T case, while it should have been copied
> > instead.
> > 
> > I am currently testing the following patch:
> 
> It worked fine on arm-linux-gnueabihf with no regression. Here is the
> full patch.

I have now committed it, as I don't want to leave things broken for too
long.

Aurelien