Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 89381 - glibc dynamic loader becomes confused when entry in LD_LIBRARY_PATH looks like a library it's trying to locate
Summary: glibc dynamic loader becomes confused when entry in LD_LIBRARY_PATH looks lik...
Status: RESOLVED WONTFIX
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: High major
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-04-16 22:29 UTC by Robert Trace
Modified: 2006-01-10 21:09 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
glibc-dirs-are-not-elfs.patch (glibc-dirs-are-not-elfs.patch,872 bytes, patch)
2005-12-24 22:08 UTC, SpanKY
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Trace 2005-04-16 22:29:52 UTC
If a subdirectory of an entry in LD_LIBRARY_PATH is named the same as a library that ld-linux.so is trying to locate, it'll get confused and open the directory as if it were the library itself.  The loader doesn't like this much as it'll try to find and ELF header in the directory entry (which it obviously won't find) and it'll error out.

In the glibc source elf/dl-load.c, the open_path function is looping over entries in LD_LIBRARY_PATH trying to find various libraries.  It eventually calls open_verify to try an actually open the library.  open_verify will issue and __open() on the specified path.  If this path (which is named like a library) is a directory, the __open() will succeed.  If the open succeeds, open_verify tries to verify that it's an ELF file (which it's not).

It seems like a stat() to check if what you're opening is actually a file would be a good fix.  (I'd supply a patch, but I'm not a glibc hacker. :-)


Reproducible: Always
Steps to Reproduce:
1. mkdir -p /tmp/lib/libc.so.6
2. export LD_LIBRARY_PATH=/tmp/lib
3. Run anything that's dynamically linked

Actual Results:  
$ export LD_LIBRARY_PATH=/tmp/lib
$ ls
ls: error while loading shared libraries: /tmp/lib/libc.so.6: cannot read file
data: Error 21
$ /bin/sh
/bin/sh: error while loading shared libraries: /tmp/lib/libc.so.6: cannot read
file data: Error 21

etc...


Expected Results:  
ld-linux.so shouldn't try to open directories and then try to treat them like
ELF files.

This is all relevant because revdep-rebuild uses LD_LIBRARY_PATH when searching
for broken dependancies.  This is how I found this bug.  I have
vmware-workstation installed and it has a library installed as
/opt/vmware/lib/lib/libgdk_pixbuf.so.2/libgdk_pixbuf.so.2.  So revdep-rebuild
will add /opt/vmware/lib/lib to the LD_LIBRARY_PATH.  Then when trying to find
the library libgdk_pixbuf.so.2, it'll fail (because of this bug) and (in my
case) not find a broken dependancy.

Hmm... I guess this is also a bug in revdep-rebuild (it probably shouldn't
silently fail when it gets an error from ldd).
Comment 1 Mark Loeser (RETIRED) gentoo-dev 2005-12-15 23:41:13 UTC
Confirmed that this is still an issue.  Can someone push this upstream or come
up with a patch? :)
Comment 2 SpanKY gentoo-dev 2005-12-24 22:08:36 UTC
Created attachment 75481 [details, diff]
glibc-dirs-are-not-elfs.patch

this should fix it
Comment 3 SpanKY gentoo-dev 2006-01-06 20:28:45 UTC
i'm pretty sure this is intended behavior but i sent the patch upstream anyways
Comment 4 SpanKY gentoo-dev 2006-01-07 18:40:32 UTC
yeah, upstream says this is expected behavior, so i wont include the patch in our Gentoo ebuild
Comment 5 Robert Trace 2006-01-10 21:03:10 UTC
(In reply to comment #4)
> yeah, upstream says this is expected behavior, so i wont include the patch in
> our Gentoo ebuild

Ok, fair enough (thanks for looking into it).  Out of curiosity, why does upstream think that this behavior is good?
Comment 6 SpanKY gentoo-dev 2006-01-10 21:09:05 UTC
they consider it something that shouldnt be wrong ... here's a comment from the code itself:
/* Open a file and verify it is an ELF file for this architecture.  We
   ignore only ELF files for other architectures.  Non-ELF files and
   ELF files with different header information cause fatal errors since
   this could mean there is something wrong in the installation and the
   user might want to know about this.  */

they dont think of dirs as a special non-elf case