allow building multicall binary as dynamic library #7928
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It was noted in the latest Ubuntu post that they were having problems with AppArmor profiles on the multicall binary, and listed a possible solution of
I decided to see how much work that would be, and it turns out to not be too bad. Basically, I just moved the multicall binary logic into a top-level library, and made the multicall binary link to it, either statically (i.e., normal Rust linking) or dynamically, depending on whether the "dynamic" feature is enabled. On my Debian system with
--release
, the normalcoreutils
(i.e., the default multicall binary) is ~14M, while when dynamically linking,libcoreutils.so
is ~26M andcoreutils
(i.e., the minimal shim that loads and executes the shared library) is 381K.This allows creating individual binaries with different profiles by just copying the dynamically linked multicall binary with the name of each respective utility. It's only marginally better for security though, since the behavior of the shim executable is identical to the full multicall binary, meaning someone could just modify
argv[0]
to get the coreutilfoo
to run with the AppArmor profile of coreutilbar
, or exploit a confused deputy with setuid, etc. There are a few possible solutions to that (for a future PR), with the main gist being to get each util's (uu)main dynamically linked when thedynamic
feature is enabled. Another thing I'm putting off is proper Windows support in the documentation and CICD. I don't know as much about Windows/.dll
s as I do Unix shared libraries, and don't have a local Windows dev env right now, so I'm not testing it at all yet, but in theory it should work.Some things I'd welcome any feedback on:
LD_LIBRARY_PATH
works fine for local configurations..so
generation with musl yet), to ensure it loads fine, but not run the tests with it. On the other hand, the default test suite is rarely the bottleneck in CICD, so we could run it if we think that overhead is acceptable.