-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Reduce dependencies of libsystemd #32028
Comments
In the next release all the compression libraries and gcrypt will be dlopen() style dependencies which means that the libraries will only be loaded if the relevant functionality in libsystemd is actually used by the service. https://lists.fedoraproject.org/archives/list/[email protected]/message/4VRKIAQAXGXU7C7A2ERO7SN3WTC5ML33/ gives an overview of why splitting libsystemd is not trivial and involves other tradeoffs. |
I think, |
I do think we need to start strongly considering splitting libsystemd back up into component libraries. Yes, this will be rather painful because there have been no architecture boundaries for the library code for 10 years now, but this incident has shown that the architecture of integration matters a lot. The |
I would love to see the big mono-repo split up. There are many good things in systemd that I'd love to use in Alpine Linux but can not, due to only GNU libc is supported. A few things that could be nice to have separated out are:
It would be very nice if those could be built independently by init systems that have musl libc support. |
I don't think that's realistic or desirable by the contributors. And none of us in this issue are asking for that. But having a modular architecture does not necessarily require a polyrepo setup. And Alpine can still take the source code and build only the components they want to use. As for Musl libc support, I think that's largely dependent on beefing up musl to support the missing primitives. Nobody here is against it as long as the stuff needed by systemd is present on musl-based systems. |
@ncopa That's a different topic, and I don't think it's desirable. Maintaining components in one repo has a major benefit that allows us to reuse Regarding musl, people from postmarketOS are working on it AFAIK. But that's pretty irrelevant too. |
Some ignorant questions: Why does libsystemd need 3 different compression libraries? Can they be reduced? (As I was typing this the above MR for dynamically loading compression libraries was merged.) |
We are not going to split again the library, because that just creates usability, maintainability and integration problems for no gains. The dependencies will all be optional via dlopen, and I'll also document that using sd_journal APIs will result in optional dependencies to be loaded. |
Fair enough. My thinking here was poly repo setup would likely help enforcing a modular architecture if that was a goal. I just wanted to mention that it would also be beneficial for non-supported platforms.
Sure, I'm just saying it would be nice to have it more separated.
Being against and supporting something are two different things.
This means "not supported". Thanks for listening. |
This is the dependency tree with a full-feature build and the pending PRs merged:
There's a TODO item to replace libcap with ioctls, maybe this is a good time to look into that too? Any volunteers? |
After lunch I'll also work on adding an MIT-0 example to the manpage on how to reimplement sd_notify in C, so that it is copy/paste ready. The notify protocol is stable and trivial for the manager <-> service case, and if one wants to prioritize avoiding dependencies we should facilitate that. |
Well, nobody is against adding |
I'm sorry if I'm sidelining the discussion a bit, but if I understand @poettering here correctly, these protocols are documented with the explicit intent ("on purpose") to enable third party projects to re-implement them as they see fit. As such, any evolution of these protocols would surely have to take that into account already. In his post he is talking about |
stable interfaces and protocols are already documented at: https://systemd.io/PORTABILITY_AND_STABILITY/ |
The ability to reimplement the protocols is good and very welcome, but there is benefit in having a reference implementation that is easy to use in third party services without much downsides, like unnecessary dependencies. This relieves those services from having to implement, test and maintain their own implementations, however simple it may be. My understanding is that libsystemd was supposed to be that reference implementation. |
--> #32030 |
Even better than example code in a documentation would be a function that gets linked into the program, without actually adding libsystemd.so.N as a runtime dependency. Recall that
I imagine that a similar linker script could be used for
|
No, we are not adding new libraries. If you want convenience then just use the existing library, otherwise put in some effort and use the copy pastable example. |
Clearly there are gains or it wouldn't be brought up all the time, and especially now.
And you are free to do this, even though it doesn't fix any of the problems people are actually talking about. |
Sorry, but I really don't see the point here. If people don't use |
Support adding this to Linux/ELF 👍 Would be a neat feature... |
If IFUNC ever gets changed to allow a dlopen to replace already loaded symbols then we are back at square one regarding this. That change might happen when someone half a decade from now decides that windows' automatic delay load using stubs is a great thing to have for linux. And I very much doubt that people will have a long enough memory to remember this backdoor and be load enough to add sufficient protections (aka explicit opt-in for the delay loaded functions checked at load times). |
Ultimately we have to trust some libraries/maintainers. Every library/binary/subsystem can theoretically be infiltrated. Searching for silver bullets is hard.
|
How about creating a It would
And the size of |
I really want this to be the last time it needs to be repeated:
We have some real work to do, and this insistence from the peanut gallery on things that have already been clearly and unambiguously rejected is wasting everyone's time and verging on the spam side. Please stop. Thank you. |
Why though? As it appears sshd is implementing sd_notify() on their own. Which is what I'd recommend anyway for a project like that. https://bugzilla.mindrot.org/show_bug.cgi?id=2641 So maybe let's end this specific discussion now? I mean, let's summarize:
So, however you want to spin this, it's handled from both directions now: from sshd, from systemd. If you want us to expose the dlopen information in way programs can read it from ELF metadata, then we are on board, write a spec, we'll help from our side, and make sure to get at least one relevant potential user of this data on board too (dpkg, rpm, ldd, initrd builders, …). But for me that settles things pretty comprehensibly. |
The openssh upstream is already reimplementing the notification protocol on their own: https://bugzilla.mindrot.org/show_bug.cgi?id=2641#c13 |
Indeed; a good move.
As a convenience for the other packages, other than openssh, that need
A good portion of these packages certainly does not need the full libsystemd.so.0 either. |
Another thing that could be useful is a systemd api that you can use as either an allowlist or blocklist for dlopen'ing libraries. Because lets say we have all the systemd optional dependencies installed on a machine. But lets take binary sshd as an example where we need to be extra secure. We need/want to use libsystemd in sshd... But... We do not want to use liblzma in sshd because we do not need it or trust it, this could be useful:
|
Then they don't need to be part of libsystemd, do they? They each be in a separate library. Given the problem of "libsystemd links to many things", the solution seems to me that libsystemd solves too many problems, creating an insecurity. OR, if that's simply unacceptable to you, then restructure libsystemd so that every function is in its own .o file, so that when someone links their program to libsystemd, ONLY the code they actually use becomes part of their executable. Static linking and small .o files are your friend. |
Such an API would certainly useful (though I don't see how it would it help in any way in the xzpocalipse). But I'd argue this should probably be prat of glibc/libd/dl.so. i.e. another LD_XYZ env var or so. |
I don't think oyu know what you are talking of. there's not that much left if you remove the IPC clients. Also, please read up, let's not repeat this discussion over and over again.
Yeah, but no. Sorry. Please do not add further noise to this thread. Unless you are very sure that what you are saying hasn't been said before here, don't write it. I'll start to aggressively hide further comments to keep the noise down if they just reiterate the same things over and over again. So, for anyone else: if you want to suggest splitting up the lib, just shut up, please. It has been proposed before, and has been rejected before. Go and read up. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Well lets say sshd or a similar project wants to use libsystemd but not liblzma, but they expect in many cases liblzma will be installed on the OS regardless. It closes up an attack vector for sshd in this case. |
@bluca why did you reopen? is there anything left to address? |
The gcrypt dlopenify PR, will work on that next |
I have regenerated the docs so the self-contained example is published at: https://www.freedesktop.org/software/systemd/man/devel/sd_notify.html#Notes |
This comment was marked as off-topic.
This comment was marked as off-topic.
Regarding the original issue, "Reduce dependencies": downstream distros have the full capability to reduce the dependencies they don't trust, with meson options such as Of course this all doesn't mean that upstreams get to be careless when choosing to integrate with 3rd party components. There are also non-optional dependencies like glibc/ld.so (which BTW introduced the GNU IFUNC feature used in the exploit). |
This comment was marked as spam.
This comment was marked as spam.
This is now also linked from https://systemd.io/PORTABILITY_AND_STABILITY/ |
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as spam.
This comment was marked as spam.
I guess this was linked on some social media - time for lock&roll |
Component
systemd
Is your feature request related to a problem? Please describe
The recent sshd/xz backdoor fiasco (CVE-2024-3094) has shown that the extra dependencies introduced by libsystemd may be the source of vulnerabilities in core and sensitive components on the system. libsystemd is being linked into all systemd services, as well as any third party services that intend to interact with systemd through the C API. For example, any service that wishes to notify systemd of its startup and termination would call
sd_notify
family of functions. Any process that wishes to write logs to systemd-journal would callsd_journal_print
family of functions. And so on.Describe the solution you'd like
This issue is asking to reduce the dependencies of libsystemd to the bare minimum, which is libc. Currently, on Kubuntu 22.04 (libsystemd0 version 249.11-0ubuntu3.12)
ldd libsystemd.so.0
shows:I believe, most of these dependencies are not necessary to implement core libsystemd functions, like those mentioned above.
This issue may mean splitting libsystemd to multiple libraries implementing different APIs, one of which, say, libsystemd-core, would only depend on libc, and other, more specialized libraries, would add other dependencies. Also, if some of the dependencies are only needed by certain systemd services, move the dependencies to those services.
The ultimate effect of this should be reduced attack surface and improved system security.
Describe alternatives you've considered
For some APIs, there are documented underlying protocols (e.g. there is native journal protocol). Third party processes could be implementing those protocols to interact with systemd. However, this approach is counter-productive and error-prone, as every process would need to implement the same protocol, and may do it incorrectly. This would also make future evolution of these protocols more difficult as there would be many implementations of it that would need to be upgraded. Furthermore, this does not solve the problem for systemd itself, as the dependencies remain loaded into every systemd process, whether they are needed or not.
The systemd version you checked that didn't have the feature you are asking for
249
The text was updated successfully, but these errors were encountered: