Piping password to mount.crypt fails with "no free loop devices"
Brought to you by:
jengelh
When using pam_mount to automatically mount a LUKS partition on session login , the mount fails, and I'm seeing the following sequence of log messages:
Oct 7 00:47:52 x1 sddm-helper: (mount.c:246): Mount info: globalconf, user=mg <volume fstype="crypt" server="(null)" path="/home/mgcrypt.img" mountpoint="/home/mgtest" cipher="(null)" fskeypath="(null)" fskeycipher="(null)" fskeyhash="(null)" options="" /> fstab=0 ssh=0
Oct 7 00:47:52 x1 sddm-helper: (mount.c:655): Password will be sent to helper as-is.
Oct 7 00:47:52 x1 sddm-helper: command: 'mount' '-t' 'crypt' '/home/mgcrypt.img' '/home/mgtest'
Oct 7 00:47:52 x1 sddm-helper: (mount.c:68): Messages from underlying mount program:
Oct 7 00:47:52 x1 sddm-helper: (mount.c:72): (crypto.c:310): Error: no free loop devices
I can actually reproduce the "no free loop devices" when I run the mount command and pipe the password through stdin:
cat pw.txt | sudo mount -t crypt /home/mgcrypt.img /home/mgtest
The mounting works as expected when I enter the password by hand at the prompt, using
sudo mount -t crypt /home/mgcrypt.img /home/mgtest
The issue seems to be due to a race condition, because when I delay the piped input, the mounting also works correctly. To check that I used the following code:
# delayed_pipe.py:
#!/usr/bin/env python
import sys
import time
for line in sys.stdin:
time.sleep(1)
sys.stdout.write(line)
And ran:
cat pw.txt | ./delayed_pipe.py | sudo mount -t crypt /home/mgcrypt.img /home/mgtest
libpam-mount version: 2.18-2build2
OS: kubuntu 22:04
I had the above problem both with LUKS1 and LUKS2 formats.