Skip to content

Commit 2e873e9

Browse files
committed
initrd/gpg: add LUKS cleanup trap and fix partition derivation
- Add EXIT trap to reprovision_smartcard_from_backup() that unmounts /media and closes any leftover usb_mount LUKS mappings. Error paths that return early after opening LUKS would otherwise leave stale crypto mappings, blocking subsequent USB backup drive access. - Fix partition derivation: use sed -E s/[0-9]+$// without the (p?) capture group that was removing the p separator from NVMe/MMC devices (nvme0n1p1 -> nvme0n1, producing nvme0n12 instead of nvme0n1p2). Signed-off-by: Thierry Laurion <insurgo@riseup.net>
1 parent 1d3bfcb commit 2e873e9

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

initrd/etc/gpg_functions.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,9 @@ reprovision_smartcard_from_backup() {
448448
local mapper_dev parent_disk pub_partition
449449
local algo_code bit_len
450450

451+
# Ensure LUKS mappings are cleaned up on any exit path (error or normal)
452+
trap 'umount /media 2>/dev/null || true; for d in /dev/mapper/usb_mount_*; do [ -e "$d" ] && cryptsetup close "$(basename "$d")" 2>/dev/null || true; done' EXIT
453+
451454
# Detect dongle branding early -- needed for whiptail messages and
452455
# Nitrokey Storage AES key reset in factory_reset_and_configure.
453456
enable_usb

0 commit comments

Comments
 (0)