问题
cryptsetup close
当任何 flatpak 应用程序在后台运行时,我无法使用任何 LUKS 音量。是的,Flatpak 应用程序只需要在后台运行,我不想在沙箱或类似的东西中使用 cryptsetup。是的,这是这些问题之一。
重现步骤
mkdir ~/mnt
dd if=/dev/zero of=file.img bs=1MiB count=100
sudo losetup /dev/loop4 file.img
sudo cryptsetup luksFormat /dev/loop4
sudo cryptsetup open /dev/loop4 my_crypt
sudo mkfs.fat /dev/mapper/my_crypt
sudo mount /dev/mapper/my_crypt ~/mnt
echo ayylmao | sudo tee ~/mnt/foobar.txt
sync
# <open a flatpak app, such as flatseal, in the background>
sudo umount ~/mnt
sudo cryptsetup close my_crypt
# output:
# device-mapper: remove ioctl on my_crypt failed: Device or resource busy
# <the above line multiple times>
# Device my_crypt is still in use.
# <now close the flatpak app>
sudo cryptsetup close my_crypt
# Now it runs successfully
sudo losetup -d /dev/loop4
请注意,与循环设备相比,“真正的”LUKS 设备以及tomb也会发生同样的问题。
进一步诊断
似乎在启动 Flatpak 应用程序时,它会生成一个xdg-dbus-proxy
在新mnt
命名空间中调用的进程,出于某种原因,该进程会保持 LUKS 设备上的文件系统已挂载,即使在“默认”命名空间中卸载之后也是如此。例如,以下是lsns
启动 flatseal 之前的输出:
NS TYPE NPROCS PID USER COMMAND
4026531834 time 40 1452 renzev -bash
4026531835 cgroup 40 1452 renzev -bash
4026531836 pid 40 1452 renzev -bash
4026531837 user 40 1452 renzev -bash
4026531838 uts 40 1452 renzev -bash
4026531839 ipc 40 1452 renzev -bash
4026531840 net 40 1452 renzev -bash
4026531841 mnt 40 1452 renzev -bash
这是启动 Flatseal 后的输出:
NS TYPE NPROCS PID USER COMMAND
4026531834 time 44 1452 renzev -bash
4026531835 cgroup 44 1452 renzev -bash
4026531836 pid 42 1452 renzev -bash
4026531837 user 41 1452 renzev -bash
4026531838 uts 44 1452 renzev -bash
4026531839 ipc 44 1452 renzev -bash
4026531840 net 42 1452 renzev -bash
4026531841 mnt 41 1452 renzev -bash
4026532233 user 1 11485 renzev xdg-dbus-proxy --args=42
4026532254 mnt 1 11485 renzev xdg-dbus-proxy --args=42
4026532256 mnt 2 11488 renzev bwrap --args 40 com.github.tchx84.
4026532257 pid 2 11488 renzev bwrap --args 40 com.github.tchx84.
4026532258 net 2 11488 renzev bwrap --args 40 com.github.tchx84.
4026532391 user 2 11488 renzev bwrap --args 40 com.github.tchx84.
如果我们跳到名称空间检查已挂载的文件系统,我们可以看到它~/mnt
仍然挂载,即使我们在“默认”名称空间中卸载它之后:
sudo nsenter -t 11485 -m bash
mount | grep mnt
/dev/mapper/my_crypt on /home/renzev/mnt type vfat (ro,nosuid,nodev,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro)
尝试从命名空间内手动卸载设备会导致一些有趣的输出:
mountpoint /home/renzev/mnt
/home/renzev/mnt is a mountpoint
umount /home/renzev/mnt
umount: /home/renzev/mnt: not mounted.
系统详情
无效的Linux。cryptsetup 2.6.1 标志:UDEV BLKID KEYRING KERNEL_CAPI。Flatpak 1.15.6。Linux 6.3.13_1。
问题
如何在无需关闭每个 Flatpak 应用程序的情况下关闭 LUKS 设备?