mirror of
https://github.com/netblue30/firejail.git
synced 2026-05-15 14:16:14 -06:00
[GH-ISSUE #1920] Lists of libraries for private-lib #1285
Labels
No labels
LTS merge
LTS merge
bug
bug
converted-to-discussion
doc-todo
documentation
duplicate
enhancement
file-transfer
firecfg
firejail-in-firejail
firetools
graphics
help wanted
information_old
installation
invalid
modif
moved
needinfo
networking
notabug
notourbug
old-version
overlayfs
packaging
profile-request
pull-request
question
question_old
removal
runtime-permissions
sandbox-ipc
security
stale
wiki
wiki
wontfix
wordpress
workaround
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/firejail#1285
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @chiraag-nataraj on GitHub (May 2, 2018).
Original GitHub issue: https://github.com/netblue30/firejail/issues/1920
So I was trying to get
private-libto work for Firefox and finally succeeded. Most of the dependencies can easily be extracted byldd(since just whitelisting/usr/lib/firefoxisn't enough. But even after that, I couldn't get firefox to work properly. It turned out there were other random dependencies (e.g./usr/lib/x86_64-linux-gnu/nss) which don't show up anywhere in the library dependencies but which are crucial for firefox to work properly.For now, I've just hard-coded it, but I'm trying to figure out how I can automatically extract them, since this feels very kludgy. I'm going to experiment a bit to see if I can reduce the hard-coded bits, but I wanted to see if anyone else has run across this and how people are using
private-libmore generally.[edit]
Never mind. The only dependency I had to add manually was
nss. Could we ensure thatnssis whitelisted wheneverlibnss3(and other libraries in that collection) are whitelisted?Also, if the script might be helpful for others, I'll put it here:
Here's an example of using it (in this case, firefox):
@chiraag-nataraj commented on GitHub (May 2, 2018):
In a related vein, when I try using
private-libfor Telegram (using the same scheme - runlddon the executable and then add in hard-wired directories if necessary), I have whitelisted/usr/lib/x86_64-linux-gnu/alsa-libas required for sound, but I still get a warning that it couldn't open a file in that directory (ALSA lib conf.c:3545:(snd_config_hooks_call) Cannot open shared library libasound_module_conf_pulse.so (/usr/lib/x86_64-linux-gnu/alsa-lib/libasound_module_conf_pulse.so: libasound_module_conf_pulse.so: cannot open shared object file: No such file or directory)). When I use--lsto see if the file exists, I see that it does. I'm not quite sure why this is happening.@reinerh commented on GitHub (May 2, 2018):
Not all libraries are dynamically linked into the binary. ldd only retrieves the ones that are.
But programs can also load libraries/plugins during runtime with dlopen (what probably happens with alsa modules). To figure them out, you need to actually run the program and trace it's dlopen calls.
@chiraag-nataraj commented on GitHub (May 2, 2018):
Cool, figured out that I needed to manually whitelist pulseaudio and it works!
@reinerh Yeah, that's how I figured out that I needed to whitelist the nss directory. So I guess there's no real automated way to do this...darn.
@Fred-Barclay commented on GitHub (May 2, 2018):
@chiraag-nataraj Can you post your private-lib filter? I'll test it across several distros and if it works well we can possibly add it to the firefox profile.
@chiraag-nataraj commented on GitHub (May 2, 2018):
@Fred-Barclay Well currently I'm generating it dynamically, but this is the current filter returned for Firefox:
(note that everything including and after
nsswas added manually)(note also that I'm not sure which of those is already included by default - this list could probably be culled a bit)
@chiraag-nataraj commented on GitHub (May 2, 2018):
Here's a tentative list of libraries for mutt:
(everything after and including
sasl2was added manually)@chiraag-nataraj commented on GitHub (May 2, 2018):
Here's a tentative list for Viber:
(everything after and including
nsswas added manually)(also,
firejailthrows up a bunch of warnings because some of these libraries are bundled with Viber, so they're not in the standard path)@chiraag-nataraj commented on GitHub (May 2, 2018):
Here's a tentative list for Telegram:
pulseaudio,libpulse.so.0@chiraag-nataraj commented on GitHub (May 2, 2018):
To be clear, I have not tested these extensively in the sense that some functionality may well be broken. All I can attest to is that on my machine, it works with the functionality I require 😉 😂
@chiraag-nataraj commented on GitHub (May 2, 2018):
Here's a (very) tentative list for Signal (and other Electron apps):
nss,pulseaudio,locale,gconv,libsqlite3.so.0,libudev.so.1,libvorbisenc.so.2,libvorbis.so.0,libogg.so.0,libFLAC.so.8,libasyncns.so.0,libsndfile.so.1,libwrap.so.0,libSM.so.6,libICE.so.6,libcap.so.2,libpulse.so.0,libnotify.so.4,libGL.so.1@chiraag-nataraj commented on GitHub (May 3, 2018):
Also, @netblue30, @Fred-Barclay, and others:
Is there any way we can make these filters dynamic? In the script posted above, I re-enumerate the list of libraries on each run, since this should (hopefully) help ensure a smooth upgrade experience and shouldn't force too much tinkering. This is one reason I was disappointed that I need to hardcode some of the dependencies manually, since if they change, the filter (and application) will break.
[edit]
I modified the script slightly to ensure that any subdirectories in the
lddlist are automatically captured and added (yay less manual labor!). This, of course, still leaves libraries which are loaded withdlopen...@chiraag-nataraj commented on GitHub (May 3, 2018):
mpdJust Works™@chiraag-nataraj commented on GitHub (May 4, 2018):
Here's a tentative list for fetchmail + getmail_maildir as the MDA:
nss,ssl,python2.7,libnss_resolve.so.2,libnss_mdns4_minimal.so.2,locale,libnss_files.so.2,libnsl.so.1,libnss_nis.so.2,libnss_compat.so.2,libutil.so.1,libz.so.1,libm.so.6@chiraag-nataraj commented on GitHub (May 4, 2018):
gerberaJust Works™@topimiettinen commented on GitHub (May 4, 2018):
The lists are always going to be fragile. A robust way would be to consult distro package dependencies and whitelist everything that the program depends on. That would also be almost useless, for example in Debian a package can depend on any basic system component (like bash) without stating dependencies explicitly. What we're doing with the private-lib is to generate more minimal set of dependencies manually. The effort to do this and also to keep the lists up to date as other components change may make sense for critical apps like browsers, maybe less so for others.
Perhaps it would be better to provide a tool, which analyzes what files an application uses in a non-enforcing trial run and generates the lists automatically. When a library changes, the tool may have to be rerun.
@chiraag-nataraj commented on GitHub (May 4, 2018):
Right, so with the script above, I can dynamically generate (most of) the dependencies for most programs. In some cases, that's all I needed (e.g.
gerbera). In the vast majority of them, I also had to hardcode some extra libraries and folders. The script in the OP would help solve part of this issue, since most of the dependencies are resolved automatically based on what libraries the program depends on at the time of running and this would be distro-agnostic.If we use the script from the first post, we only need to worry about updating the hard-coded dependencies (the second argument to compile_list). If we decide to go with it, the next step is to integrate this into firejail proper so that it happens transparently (maybe a
private-lib.extrafield with the contents of the second argument to compile_list?). I'm just spit-balling here though.[edit]
If we want to do this in C, we should be able to get the library dependencies (as we do with
ldd) by settingLD_TRACE_LOADED_OBJECTSto a non-empty value (not sure if there are security implications, though? found this: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=514408 but I think that's just anlddissue, not an issue with this technique?). But I think the combination of dynamically resolving dependencies and having a static set of secondary, indirect dependencies makes sense.@topimiettinen commented on GitHub (May 5, 2018):
We already have
flddwhich is used to build the private-lib list by checking library dependencies, it can of course be enhanced to match what your script can do and/or fix it if it doesn't detect the same libraries asldd.But I was thinking of using system call
ptraceor other means (libtrace, kernel probes, SystemTap) to build the list based on trial run. That way also extra libraries opened later and their folders can be detected.@chiraag-nataraj commented on GitHub (May 5, 2018):
Ohhh...right. I think one thing that might be worth adding is scanning for ELF files if passed a directory a la
find(so for example, it would scan for all ELF files in/usr/lib/firefox/and add their dependencies). This might go a little bit towards making this process less painful? One other thing my script does (and idk if this is useful and/or easily doable infldd) is parse the list output bylddto detect subfolders of/usr/lib/and automatically whitelist those folders (rather than particular libraries, since it's likely the program will need other things in those folders).As for learning mode, I think that's a great idea - run the program without
private-lib, ask the user to do what they normally do, store the list of libraries loaded in memory, and (probably) cache it. Ideally, we'd also remove the list of automatically-determined dependencies so that the list of hard-coded stuff is a lot less (basically the second argument to my function above).@chiraag-nataraj commented on GitHub (May 10, 2018):
So we can definitely include
private-libwith some of these profiles (e.g.gerbera,mpd). Others probably need some testing (and probably manual tweaking on the part of users).With respect to
firefox, I figured out the problem - thefirefoxexecutable itself doesn't depend on much. What it does is read in a list of (arch/OS-dependent?) dependencies from/usr/lib/firefox/dependentlibs.list. The reason my script worked is that if it is provided a directory (e.g./usr/lib/firefox), it goes through and finds all ELF binaries and libraries and runs ldd on them (rather than just the binaries specified inprivate-bin). @netblue30, is this something we can think about forfldd?