-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LD_PRELOAD should not be used for injecting security-critical code because of glibc fail-open behavior #1
Comments
Yes, Also, both this library as well as |
The README currently reads to me as if the LD_PRELOAD approach is a suggested usage pattern. If that is not the case, it may be a good idea to add a big warning at the top of the "Dynamically linked executables" section. |
It is a suggested usage pattern, at least for now. |
Just to clarify more: while LD_PRELOAD has its downsides, we think it should be offered as an option still, because it helps in some cases, where Also, LD_PRELOAD is easier to configure. Going back to the global file descriptor example: in most well monitored production systems a global file descriptor exhaustion will likely cause many more issues and would not go unnoticed in the first place. Finally, some other users pointed out that there are similar solutions using similar approaches and LD_PRELOAD specifically, like Google minijail project, so it seems other engineers find value in the approach. |
Or you could use a different loader, or let your code signing infrastructure sign the patched executable, or...
Even if it is a deliberately targeted, extremely short spike?
That's not a reason to repeat their mistakes. |
This assumes the OS is already compromised. |
In other words, even if an attacker only gains code execution in a process that has the ability to fork and to open /dev/null (and not much else), you consider the OS to be compromised? |
I'm not sure that only with |
There are any number of other legitimate purposes for LD_PRELOAD (or other options like LD_AUDIT) that could be defeated if it fails to load the object for this kind of reason. If there's a bug here it can be argued that it's in glibc. If someone is that concerned, maybe a patch should instead be sent to glibc to add an environment variable like LD_EXIT_ON_ERROR=(preload,symbol-resolution,relocation,audit,...,any) so that one can be 100% confident that either a program starts with the LD_PRELOAD having been successful or it doesn't start at all. |
I hope I'm not misunderstanding the intention of the comments in defense of At this point the README should at very least document the risks of using |
It seems the more generic problem outlined here is how to make sure the process we're sandboxing is actually sandboxed and the rules were applied. I've added a section to the |
Thank you for adding that section @ignatk ! It's not the big warning that I was hoping for, but it's definitely an improvement |
If you use LD_PRELOAD for injecting security-critical code, that's extremely brittle because glibc will just plow ahead if loading LD_PRELOAD libraries fails:
If the executable runs without CAP_SYS_ADMIN, an attacker could e.g. deliberately trigger such an error condition by temporarily opening so many files that the system-global limit is reached and open() returns
-ENFILE
.Therefore, anything that relies on
LD_PRELOAD
for sandboxing is probably a bad idea, unless you have a safety net that somehow ensures that the LD_PRELOAD operation succeeded.The text was updated successfully, but these errors were encountered: