Skip to content

Commit 1fe0412

Browse files
committed
initrd/gpg: fix passphrase fd leaks and review issues
Replace --passphrase-file with --passphrase-fd 3 3< <(...) to avoid leaking the PIN value through /proc/<pid>/cmdline of the child echo/printf process in factory reset, card identity, and key import commands. Also fix 6 instances of $? clobbered by intervening TRACE_FUNC/DEBUG calls. Fix algo_code extraction to use head -1 against multi-key outputs. Fix STATUS_OK on public partition mount (only on success). Return actual hotp_verification error code. Signed-off-by: Thierry Laurion <insurgo@riseup.net>
1 parent b906dc2 commit 1fe0412

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

initrd/etc/gpg_functions.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ gpg_card_factory_reset() {
192192
echo y # confirm
193193
echo yes # confirm
194194
} | DO_WITH_DEBUG gpg --command-fd=0 --status-fd=1 --pinentry-mode=loopback \
195-
--passphrase-file <(echo -n "$card_admin_pin") --card-edit \
195+
--passphrase-fd 3 3< <(echo -n "$card_admin_pin") --card-edit \
196196
>/tmp/gpg_card_edit_output 2>&1
197197
rc=$?
198198
TRACE_FUNC
@@ -339,7 +339,7 @@ gpg_set_card_identity() {
339339
fi
340340
echo "quit"
341341
} | DO_WITH_DEBUG gpg --command-fd=0 --status-fd=2 --pinentry-mode=loopback \
342-
--passphrase-file <(printf '%s' "$card_admin_pin") --card-edit \
342+
--passphrase-fd 3 3< <(echo -n "$card_admin_pin") --card-edit \
343343
>/tmp/gpg_card_edit_output 2>&1 ||
344344
DIE "Failed to set identity fields on OpenPGP smartcard"
345345

@@ -511,7 +511,7 @@ reprovision_smartcard_from_backup() {
511511
# Phase 3: import the private key (master + subkeys) into ~/.gnupg.
512512
# --import-options restore brings in the full key material.
513513
STATUS "Importing GPG keys from backup"
514-
if ! gpg --pinentry-mode=loopback --passphrase-file <(printf '%s' "$admin_pin") \
514+
if ! gpg --pinentry-mode=loopback --passphrase-fd 3 3< <(echo -n "$admin_pin") \
515515
--import-options restore --import /media/privkey.sec >/dev/null 2>/tmp/gpg_import_err; then
516516
umount /media 2>/dev/null || true
517517
ERROR="$(cat /tmp/gpg_import_err)"

0 commit comments

Comments
 (0)