Bug 1085549

Summary: glibc: [RFE][LLNL 7.4 Bug] ldd misreports error
Product: Red Hat Enterprise Linux 8 Reporter: Ben Woodard <woodard>
Component: glibcAssignee: glibc team <glibc-bugzilla>
Status: CLOSED UPSTREAM QA Contact: qe-baseos-tools-bugs
Severity: medium Docs Contact:
Priority: medium    
Version: 8.1CC: ashankar, codonell, dj, fweimer, jbastian, mnewsome, pfrankli, tgummels, woodard
Target Milestone: pre-dev-freezeKeywords: FutureFeature, Patch, Triaged
Target Release: 8.1   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-05-14 19:59:53 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1599298    
Attachments:
Description Flags
bz1085549.diff none

Description Ben Woodard 2014-04-08 22:07:12 UTC
Description of problem:
if ldd fails for any reason including limited memory, the error message printed is "not a dynamic executable" which is not necessarily the real problem


Version-Release number of selected component (if applicable):
6.4 but appears to be all 

How reproducible:
always with the right setup

Steps to Reproduce:
severely limit memory and try to run ldd on a big executable

Actual results:
not a dynamic executable

Expected results:
it prints out that the reason it can't complete is lack of memory

Additional info:
ldd is just a script and the failing executable is actually ld-linux.
When you look at ld-linux it is exiting with EXIT_FAILURE (1) which causes that message to be in error.

in the case where it is out of memory, we might want to return something other than 1 like 3 and use that in the ldd script. 2 is already taken.

the challenge seems to be reporting what the actual error is from the kernel to glibc. That is down in the __dl_catch_error code. It seems to be called when something goes wrong in the dl linking by the elf handler in the kernel. 

I don't see where it sets any value that could be gleaned to figure out the actual source of the error.

Comment 2 Carlos O'Donell 2014-04-08 22:28:15 UTC
(In reply to Ben Woodard from comment #0)
> I don't see where it sets any value that could be gleaned to figure out the
> actual source of the error.

We need a reduced test case that shows the problem.

On glibc 2.17 or newer I see the following:

[carlos@koi ~]$ ulimit -v 5000
[carlos@koi ~]$ /usr/bin/ldd /lib64/libc.so.6
/usr/bin/bash: error while loading shared libraries: libdl.so.2: failed to map segment from shared object: Cannot allocate memory

Which looks exactly like what I would expect.

Thus this will get fixed as our users upgrade to the next version of RHEL.

To answer your technical question, glibc uses setjmp/longjmp around dlopen to handle errors and the error code returned is the error returned by the kernel and reported to the user. We are already propagating this errors for ENOMEM and passing that up via _dl_signal_error.

There might be a case we missed?

Comment 3 Carlos O'Donell 2014-04-08 22:30:56 UTC
Oh, hrm, I wonder if the latter failure was not in ldd, but in ld.so getting reach to run itself...

Comment 4 Carlos O'Donell 2014-04-08 22:31:28 UTC
(In reply to Carlos O'Donell from comment #3)
> Oh, hrm, I wonder if the latter failure was not in ldd, but in ld.so getting
> reach to run itself...

Either way, we need a test case.

Comment 5 Carlos O'Donell 2014-04-08 22:49:35 UTC
Created attachment 884276 [details]
bz1085549.diff

Comment 6 Ben Woodard 2014-04-09 00:53:36 UTC
I like your patch, I think it will solve the problem. I was looking in the same location but got misled by the "continuable error" part in the comment preceding _dl_signal_error and didn't recognize it as the entry point which stashed away the error code. I was looking for some other "non-continuable" error that could also jump into _dl_catch_error and kind of got lost.

I don't know how to make a test that would be reproducible across all possible platforms. The original bug report wasn't with ulimit: 

"A user on aztec3 had a process which top(1) showed to be consuming 91.8%
of memory. Meanwhile another user was trying to run a simple dynamically built serial code and file(1) on the executable said:

<executable>: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped

but ldd(1) said in the same 10-second period:

        not a dynamic executable

which was false information, and there was no error message such as,

"Could not load the executable to review its shared objects", or
some such. can we please get some [useful] error messages out of this?

----

I could probably reproduce it in virtual machine or maybe with a cgroup container but I don't know exactly how to make a very linux specific platform.

Comment 7 Ben Woodard 2014-04-09 00:55:53 UTC
err garbled my last comment: 
I could probably reproduce it in virtual machine or maybe with a cgroup container but I don't know exactly how to make a general reproducer like what is in the test suite both virtual machines and containers are very specific to the RHEL platform.

Comment 8 Carlos O'Donell 2014-04-10 07:43:34 UTC
(In reply to Ben Woodard from comment #7)
> err garbled my last comment: 
> I could probably reproduce it in virtual machine or maybe with a cgroup
> container but I don't know exactly how to make a general reproducer like
> what is in the test suite both virtual machines and containers are very
> specific to the RHEL platform.

Use systemtap and inject a NULL return for mmmap.

See:
https://sourceware.org/glibc/wiki/Testing/WhiteBox

Comment 11 Carlos O'Donell 2015-01-07 03:22:22 UTC
I've moved this to rhel-7.2. While it's possible we could have tackled this in rhel-6, I just don't see the customer demand for the change. The tricky part is that ld.so has to return new error codes, and we want to be conservative about that in rhel-6, thus the move to rhel-7.2.

Comment 18 Florian Weimer 2019-10-15 14:48:26 UTC
Upstream commit:

commit e7c8ffe4ec059da1523c093d6a240cd87d154df2
Author: Florian Weimer <fweimer>
Date:   Tue Oct 15 16:41:51 2019 +0200

    ldd: Print "not a dynamic executable" on standard error [BZ #24150]
    
    Tested with the testsuite on x86_64-linux-gnu, and manually.

Comment 19 Carlos O'Donell 2020-03-28 02:55:52 UTC
*** Bug 1817111 has been marked as a duplicate of this bug. ***

Comment 21 Carlos O'Donell 2020-05-14 19:59:53 UTC
We are actively tracking this issue upstream here:

Bug 25991 - ldd should print "insufficient memory" in certain cases
https://sourceware.org/bugzilla/show_bug.cgi?id=25991

When we make upstream progress on the bug we can review the CLOSED/UPSTREAM bugs and reopen for backport consideration.

Comment 22 Red Hat Bugzilla 2023-11-16 04:25:02 UTC
The needinfo request[s] on this closed bug have been removed as they have been unresolved for 120 days