mirror of
https://github.com/netblue30/firejail.git
synced 2026-05-15 14:16:14 -06:00
[GH-ISSUE #5640] firejail holds device mapper node preventing LUKS2/cryptsetup from being closed #3053
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#3053
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 @e-pirate on GitHub (Feb 5, 2023).
Original GitHub issue: https://github.com/netblue30/firejail/issues/5640
Description
After about 3 weeks of random guesses and attempts I finally caught firejail on holding device mapper node effectively preventing LUKS2/cryptsetup partition from been closed and completely ruining security efforts - LUKS2/cryptsetup device stays open and can be mounted as long as at least one firejail sandbox is running because your can't close it.
Steps to Reproduce
First of all it was extremely hard to figure out what is holding the device because there are no easy to use user-level instruments for this. lsof just won't do because there is no file system opened. This is very unexpected and unobvious, so initially I decided that KDE/Plasma is guilty, but after some test I found that KDE/Plasma is not the root of the problem.
# cryptsetup luksOpen /dev/sdxn sdxn_dmc# mount /dev/mapper/sdxn_dmc /home/cryptedFrom that point
sdxn_dmcdevice mapper node will appear and can be viewed bylsblkfor example;# umount /home/crypted# cryptsetup close sdxn_dmcFAIL.
Device sdxn_dmc is still in use.But there is actually nothing that can use it - the filesystem is already unmounted.
# cryptsetup close sdxn_dmcSuccess
To prove this is firejail I repeated steps 1-5 for all application I usually run in firejail but without firejail running them "plane" and no problem with closing crypted device - everything works like expected.
Expected behavior
firejail is not affecting device mapper / LUKS2/cryptsetup devices at all, just ignore it once and forever;
Actual behavior
A single firejail process of a third-party user prevents LUKS2/cryptsetup devices from been properly closed;
Additional context
I tried to mask the disk partition and the device mapper node by enabling
UDISKS_IGNORE=1with udev rule to make udisks2 hide this devices from dbus, but this has no effect on firejail at all.This is extremely nasty bug that ruins all the efforts of crypting file system leaving all the stuff you want to keep away from others open and accessible unless you quit all sandboxed application and retry closing the device. In my case I came across this issue while I was testing LUKS2/cryptsetup encrypted home directory with pam_mount to make user home accessible on user login and get closed as soon as user exits last session. If I login to a "crypted" user session and then start KDE/Plasma session for a different user and run any firejailed application, I then get "Device is still in use" error on "crypted" user logoff as cryptsetup can't close the crypted device. Moreover, I can't login with "crypted" user any more as pam_mount can't mount it's home. This is a major security problem because firejail will leave encrypted device open. Why? What kind of business it has with device mapper node created by a third-party user?
Environment
Checklist
/usr/bin/vlc) "fixes" it).https://github.com/netblue30/firejail/issues/1139)Some additional information can be found in cryptsetup bug tracker here.
@ghost commented on GitHub (Feb 7, 2023):
Thank you for reporting this. It's a lot to take in at one go, at least it is for me. Personally I don't have that much experience with the complex coexistence of Firejail and LUKS, but I sure can understand your worries and expressed frustrations in this context. We'll need to have a deeper look at the issues involved and fix whatever is needed, hence marking this as both a 'bug' and attaching the 'security' label.
I can only hope you'll understand that at the moment I can't offer any 'do this and all your issues will be fixed' magic here.
That being said, if I understand what you're describing at all correctly, the first thoughts that sprung up while reading your report and the referenced links relate to two of Firejail's large set of options that are used to put together a sandbox:
--private-dev
Create a new /dev directory. Only disc, dri, dvb, hidraw, null, full, zero, tty, pts, ptmx, random, snd, urandom, video, log, shm and usb devices are available. Use the options --no3d, --nodvd, --nosound, --notv, --nou2f and --novideo for additional restrictions.
--deterministic-shutdown
Always shut down the sandbox after the first child has terminated. The default behavior is to keep the sandbox alive as long as it contains running processes.
The first one,
--private-dev, is often usedconditionally:45a641deab/etc/profile-a-l/firefox-common.profile (L59)What I would try is using it directly in Firefox (and in whatever other profiles you use that have the conditional. It's been my experience that doing so works fine/better if you don't need the U2F support in a specific sandbox. At least --private-dev and what it does seems to be a crucial part of your issue, so it's very much worth playing with that option IMO.
The second one,
--deterministic-shutdown, doesn't get a lot of 'love' and attention in our default profiles. But it has fixed 'hanging' situations/issues before, like in ssh. Again, I can't promise it's going to be any kind of magic bullet, but I would certainly give it a go.Potentially related: #4870, #4440, #3491, #1518
@e-pirate commented on GitHub (Feb 8, 2023):
@glitsj16 first of all thank you for your attention and time. Firejail is a complex solution and needs time and much effort to dig out and fix problems, so I don't expect this issue to be fixed in a "single pass". It is obvious this will take some time. On my side, I will make whatever it takes to help debug and fix this. I will try your advices ASAP and report back what I found. The only little problem I see is that I'm forced to stay on 0.9.64.4 because of [#5010] and [#5607].
@ghost commented on GitHub (Feb 8, 2023):
@e-pirate No worries, take your time to try these options. Regarding being forced to stay on 0.9.64.4, both those issues should be fixed in git already. If it's an option for you, perhaps it's worthwhile to build firejail from git. There's detailed info on how to go about that on our wiki. In the spirit of 'everything is in constant flux and nothing stays the same', that advice could bring in other problems :) You might have noticed that we're refactoring
private-etcin git (#5610) and there's bound to be some fallout at the moment... So if you decide to try git build, check out something like252094f191, that doesn't have any of the private-etc refactor yet.Courage!
@e-pirate commented on GitHub (Feb 8, 2023):
Just tested
--private-devlike this:firejail --private-dev firefoxAnd nothing changed - as long as sandbox is running I get same 'device is still in use' error, as soon as I quit sandbox and no any other sandboxes are active, I can close the crypted device.
Concerning
--deterministic-shutdown- I don't think it will help because it should be possible to close crypted device during any period of sandbox life cycle regardless what's going on in the sandbox.@rusty-snake commented on GitHub (Feb 9, 2023):
The first thing should be to check with
--noprofile. And if that works you can start adding command. Starting with a long (redirect) profile like firefox is more complicated.@e-pirate commented on GitHub (Feb 9, 2023):
@rusty-snake tested
--noprofilewith FF with no changes, crypted device is held unless I quit FF and firejail process exits.@rusty-snake commented on GitHub (Feb 10, 2023):
Does it happen if you only
luksOpenit but do not mount it (i.e. the umount isn't propagated)?Still testing with
--noprofile.@e-pirate commented on GitHub (Feb 13, 2023):
@rusty-snake it came out that crypted device will not be blocked if file system is not mounted, regardless if
--noprofileis specified or not. I can close the crypted device even Firefox is running in active sandbox. Hope this helps to make a good assumption how to debug feather.@e-pirate commented on GitHub (Mar 28, 2023):
Any updates here?
@tetumetal commented on GitHub (Jun 15, 2023):
I'm having the same issue also in Gentoo with firejail version 0.9.72, and kernel 5.10.181-gentoo-x86_64. I wonder if anyone not using Gentoo is having the same problem.
Also, this information may be obvious but the process holding the luks is jbd2. This is how the lsof looks like when I try to close the luks device:
lsof | grep dm-3
jbd2/dm-3 14845 root cwd DIR 254,2 4096 2 /
jbd2/dm-3 14845 root rtd DIR 254,2 4096 2 /
jbd2/dm-3 14845 root txt unknown /proc/14845/exe
@e-pirate commented on GitHub (Dec 3, 2023):
Any updates/plans here?
@rusty-snake commented on GitHub (Dec 3, 2023):
No. No matter how often you ask there will be no update. You will be notified of any update here.
@tetumetal commented on GitHub (Jan 5, 2024):
I noticed that when I'm updating a Gentoo package, in the compile phase, I experience the same issue. As far as I know, emerge also uses a sort of sandbox when updating a package. So, I guess that this issue relates to the Linux kernel's sandboxing tools, or to the specific configuration of the Linux kernel in Gentoo.
I think that it would be useful if someone tries to reproduce this issue (with firejail) in some other distro
@e-pirate commented on GitHub (Jan 5, 2024):
@tetumetal what kernel version are you using? Can you give step-by-step reproduce scenario?
@tetumetal commented on GitHub (Jan 8, 2024):
A. umount the luks partition (this should work)
B. try to close the luks partition (this should not work)
C. cancel the compilation of the package
D. try to close the luks partition, again (now, this should work)
@e-pirate commented on GitHub (Jan 13, 2024):
@tetumetal thank you for the info. Currently I'm on 4.19.269 which is deprecated. I'm going to update to 6.1.67 before reproducing this potentially not related to firejail behaviour and if I can reproduce, bugreport. But before so, I need to sync old kernel config to new version and this will take some time. See what I will get in the end.
@schdro commented on GitHub (Sep 21, 2025):
Was also plagued by same issue. When having a separate backup shell script, which did
Always unmounting got stuck, till firejail instances were shut down.
My observation, as hint or workaround. When wrapping the script as follows, issue finally disappeared for me:
This way the script will ensure that
mounts of inner script are independent of the rest of the system (incl firejail).When script ends,
umountsucceeded.Of course, only some workaround, as now the victim script using LUKS mount avoids getting disturbed.