I hadn't heard of LD_PRELOAD before now, but my first reaction was "oh wow, better static link all the things!". Is that wrong?
I hadn't heard of LD_PRELOAD before now, but my first reaction was "oh wow, better static link all the things!". Is that wrong?
Depends. Sadly, current trend is to keep everything static in big binary or bundle own set of dependencies. Let's assume your program is using libpng. Now, every program is keeping own libpng in RAM. That is not even the worst case; imagine particular libpng has security issue. The only way to update all those static programs is to recompile everything or download everything; which is trend, again.
I image we will have shared library approach "rediscovered" and commercialized with some cool buzzword.
Regarding security issues. I imagine that we will gradually rewrite everything in memory-safe languages such as Rust. It'll take a while - there's a lot of value in the code that's already been written. But once a library for a given task has been rewritten into a safe language, it's going to be hard to justify using the equivalent C library.
Of course this won't completely eliminate security issues. But I'd guess that along with a bit of fuzzing, it could easily reduce the frequency to <10% of what we have today. That, along with the fact that modern languages have package managers, and updating a library to the latest patch version is a one-line change, will make keeping on top of security issues well within the reach of the average app developer.
Shared libraries were a necessary tool in a world with limited computing resources, but I suspect the current trend will continue until they're used only in niche circumstances (plugins? libc?)
The assumption here is likely that read-only mapped pages of libpng could be shared across different running programs that link with it. But it ignores all the extra read-write pages as a consequence of dynamic linking and that there is basically just libc that is shared across different running programs. So it's mostly wrong, you can probably even reduce memory usage by switching to static linking.
For heavy libraries, good example is Qt and KDE. KDE would preload all necessary libraries so KDE and Qt applications could start faster, and there was significant differences when Qt application was started under KDE comparing other desktop environment.
Don't forget that under X11, everything is linked with X11 libraries and many applications with either Qt or Gtk, which brings own set of additional dependencies (pango, cairo, etc).
> Regarding security issues. I imagine that we will gradually rewrite everything in memory-safe languages such as Rust
I'm not sure how this will save us from programming errors. You just move from one surface (memory) to another (VM, compiler, package manager) with added complexity.
I suppose many/all would require the user's environment to be so throughly compromised that security might be a lost cause. But it still makes me wonder if there's a defense-in-depth argument in favor of static linking.
If the program has additional privileges which should be withheld from the user, like original Unix setuid or setgid, or modern style Linux capabilities(7), then LD_PRELOAD is ignored by ld.so(8), and there is no problem.
But if you are talking about a normal user’s environment being “compromised”, or the users’ wishes being a problem, then you have no business writing software for users, or, rather, users would be better off not running software written by you, since your software is obviously not written with their best interest in mind.
I mean, LD_PRELOAD is very useful. I used libfaketime once to debug a problem in a project that I worked that only happened when you run the test suite in a specific range of time. This power is very useful.
Can it be abused? Maybe, however you should assume that your environment is trusted or there is way worse ways to modify a process that is running in your system. In some of them it doesn't matter if the binary is static or not.
There are so many strong arguments for static linking that this one feels like a drop in the swimming pool; but yes.