Bug 5168 - LD_PRELOAD does not work as documented for SUID binaries
Summary: LD_PRELOAD does not work as documented for SUID binaries
Status: RESOLVED FIXED
Alias: None
Product: uClibc
Classification: Unclassified
Component: Shared Library Support (show other bugs)
Version: 0.9.32
Hardware: PC Linux
: P5 minor
Target Milestone: ---
Assignee: filippo.arcidiacono
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-03 06:53 UTC by Erik Johansson
Modified: 2012-06-06 08:55 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments
proposed patch to fix the issue. (2.29 KB, patch)
2012-05-23 13:50 UTC, filippo.arcidiacono
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Erik Johansson 2012-05-03 06:53:53 UTC
According to the help for LDSO_PRELOAD_ENV_SUPPORT: "For set-user-ID/set-group-ID ELF binaries, only libraries in the standard search directories that are also set-user-ID will be loaded."

However, this does not work. 

Looking at _dl_get_ready_to_run() in ldso/ldso/ldso.c it seems that LD_PRELOAD and _dl_preload is unset when _dl_secure is 1. This looks incorrect as _dl_load_elf_shared_library() in ldso/ldso/dl-elf.c seems to only allow loading of SUID libraries when _dl_secure is 1.

Without having tested it, perhaps it would be enough to replace:
_dl_preload = NULL;

in ldso.c with:
_dl_preload = _dl_getenv("LD_PRELOAD", envp);

and moving the statement before the while that unsets unsecure envvars?
Comment 1 filippo.arcidiacono 2012-05-23 13:50:54 UTC
Created attachment 4364 [details]
proposed patch to fix the issue.

The attacched patch fix the issue spotted in this bug.
There was also a discussion in stlinux bugzilla at https://bugzilla.stlinux.com/show_bug.cgi?id=19052, where show the tests done to fix it.
Any comments are welcome.

regards,
Filippo Arcidiacono
Comment 2 filippo.arcidiacono 2012-06-06 08:55:31 UTC
The fix has been recently committed in uClibc master branch by Bernhard.
Issue fixed.