Bug 5168

Summary: LD_PRELOAD does not work as documented for SUID binaries
Product: uClibc Reporter: Erik Johansson <erik>
Component: Shared Library SupportAssignee: filippo.arcidiacono
Status: RESOLVED FIXED    
Severity: minor CC: uclibc-cvs
Priority: P5    
Version: 0.9.32   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Host: Target:
Build:
Attachments: proposed patch to fix the issue.

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.