mirror of
https://github.com/netblue30/firejail.git
synced 2026-05-15 14:16:14 -06:00
[GH-ISSUE #4887] When /etc/fonts is a symlink to a directory, private-etc rules that invoke fcopy produce wrong directory structure and breaks apps (NixOS) #2800
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#2800
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 @reedriley on GitHub (Feb 1, 2022).
Original GitHub issue: https://github.com/netblue30/firejail/issues/4887
Description
On NixOS; the
/etc/fontsdirectory is a symlink (to a symlink) to a directory. When a profile includes this inprivate-etc; fcopy appears to copy the symlink into the target directory rather than resolving it as a directory and copying the contents over.In short; inside of a firejail; the "correct" path becomes
/etc/fonts/fontsinstead of/etc/fonts.Steps to Reproduce
etcwith a symlink from/etc/fontsto/etc/static/fontsand a symlink from/etc/static/fontsto some other location.Additional context
I think the fix here is probably to modify
fcopyto behave differently if a source symlink is to a directory vs. a file; and add a corresponding unit test. If that's the case; I'm happy to work on a pull request - but given that this is in a fairly subtle space I wanted to check if my understanding is correct before I begin.Environment
Checklist
/usr/bin/vlc) "fixes" it).https://github.com/netblue30/firejail/issues/1139)browser-allow-drm yes/browser-disable-u2f noinfirejail.configto allow DRM/U2F in browsers.--profile=PROFILENAMEto set the right profile. (Only relevant for AppImages)Log
From running
firejail --debug, I'm pretty confident the relevant section of the logs involve this snippet:Happy to provide more logs or perform more tests as requested.
@netblue30 commented on GitHub (Feb 2, 2022):
Thanks for the bug! Try the latest on mainline git, I think I have a fix for fcopy.
@rusty-snake commented on GitHub (Feb 2, 2022):
firejail --noprofile --debug --private-etc=localtime ls -l /etcnow shows an empty/etc. Can anyone confirm.@reinerh commented on GitHub (Feb 2, 2022):
Yes, I can confirm. With commit
4e27b344edon top of rc1 I also get an empty/etc.@reedriley commented on GitHub (Feb 2, 2022):
And I can confirm that with firejail built from
masterinstalled on NixOS that:/etc/fonts/looks sane again for a few profiles I tested, and also@netblue30 commented on GitHub (Feb 2, 2022):
New fix in, this time for localtime broken earlier. @reedriley, give it a try again. Thanks.
@reinerh commented on GitHub (Feb 2, 2022):
I'm wondering if special-casing
/etc/fontsis sufficient for NixOS. AFAIK they use a lot of symlinks, so probably also for other configuration (and application) files.@vs49688 commented on GitHub (Feb 2, 2022):
They do. This is from my NixOS system:
Directories:
Files:
@reedriley commented on GitHub (Feb 2, 2022):
This fix at least resolves the electron app issues. So it's at least an improvement. But like @vs49688 says there are other directory symlinks.
I think the old firejail handling of symlinks-to-files was probably correct; it's just the handling of symlinks-to-directories that was broken. Is it possible to run this logic only if
srcis a symlink that resolves to a directory?@netblue30 commented on GitHub (Feb 2, 2022):
Yes, probably there are other directories handled as symlinks on NixOS. Run a "ls -l /etc" and post it here.
@vs49688 commented on GitHub (Feb 2, 2022):
Done, see lsout.txt
@netblue30 commented on GitHub (Feb 2, 2022):
thanks @vs49688! The symlinks - plenty of them - are going in /etc/static. I'll bring in a new fix tomorrow.
@reedriley commented on GitHub (Feb 2, 2022):
On my system; these are the directories in
/etcthat are symlinks to other directories:i suspect the precise set will vary from installation to installation - for example
apparmor.disn't present on @vs49688's system.I still think the right fix here is probably to modify
fcopysemantics when the "source" argument is a symlink to a directory vs. symlink to a file? Just like howfcopyhas different semantics when the "source" argument is a directory vs. a file? (duplicate_dirvs.duplicate_file?)Either that; or if we can't trust that the symlink won't point somewhere else in the appropriate threat models; we might need to change
private-etcprofiles to encode whether an entry is a directory or a file. (e.g., by using a trailing slash - we could treatfonts/andfontsas having distinct meanings?)@netblue30 commented on GitHub (Feb 2, 2022):
I'm reading about NixOS. Do you guys also have a /etc/config directory?
@vs49688 commented on GitHub (Feb 2, 2022):
Not on any of my systems, although someone could add one via environment.etc
Yeah, I should probably enable AppArmor.
Agreed.
@reedriley commented on GitHub (Feb 2, 2022):
Here's a sketch of something that seems to work just fine for me:
c0822a0fe1With that patch applied; everything works the way I expect; and I get the following directory layout:
@reedriley commented on GitHub (Feb 2, 2022):
Or; alternatively; we could skip creating the empty
/etc/fontsdirectory in this case somehow. (Perhaps by modifyingcreate_empty_dir_as_rootto uselstatinstead ofstat? Orbuild_dirsinfs_etc.cto uselstatinstead ofstat?)@reedriley commented on GitHub (Feb 3, 2022):
Here's another fix that appears to work, which feels a lot less hacky:
967265deadThe flow:
fs_etc.cused to resolve the symlink/etc/fontsto a directory; and therefore create an empty directory.fcopymoved the symlink into the newly created empty directory screwing up the structure.Changing the
build_dirsfunction infs_etc.cto uselstatinstead ofstatallows it to handle this case correctly and preserve the directory structure rather than warping it.With this patch, I get:
@netblue30 commented on GitHub (Feb 3, 2022):
It turns out we already had all the support. It is --follow-link flag in fcopy, I just had to enable it for private-etc. Also reverted all the changes to fcopy.
Fix here:
8c33968747@reedriley commented on GitHub (Feb 4, 2022):
I can confirm; this fix works for my system as well. Thanks!
I'd flag there are probably other symlink issues lurking in firejail+NixOS; the distro relies on them heavily. But, if I hit any, I'll be sure to report them or submit a pull request,
@netblue30 commented on GitHub (Feb 4, 2022):
Sure, thanks! /etc should be fully fixed right now. The fix resolved all symlinks there. Closed for now.