Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(crypt): close crypt devices to release encryption keys get on shutdown #2471

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions modules.d/90crypt/crypt-shutdown.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

# Mark crypt devices for deferred removal.
# The dm module removes holding devices, so
# that the encryption keys can be released.
dmsetup ls --target crypt | while read -r name _; do
if ! type "cryptsetup" > /dev/null 2>&1; then
warn "cryptsetup not installed, skipping closing of encrypted devices"
return
fi
cryptsetup close "$name" --deferred 2>&1 | vinfo
done
6 changes: 5 additions & 1 deletion modules.d/90crypt/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,12 @@ install() {
fi

inst_hook cmdline 30 "$moddir/parse-crypt.sh"
inst_hook shutdown 24 "$moddir/crypt-shutdown.sh"
LaszloGombos marked this conversation as resolved.
Show resolved Hide resolved
if type "cryptsetup" > /dev/null 2>&1; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the following is easier to read (and type) instead, but it is certainly just a matter of taste

inst_multiple -o cryptsetup

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I didn't know of this simple way of optional includes, as this is my first time fiddling with dracut. Thanks for bringing this up @LaszloGombos , I will update it accordingly for simplicity.

inst_binary cryptsetup
fi
if ! dracut_module_included "systemd"; then
inst_multiple cryptsetup rmdir readlink umount
inst_multiple rmdir readlink umount
inst_script "$moddir"/cryptroot-ask.sh /sbin/cryptroot-ask
inst_script "$moddir"/probe-keydev.sh /sbin/probe-keydev
inst_hook cmdline 10 "$moddir/parse-keydev.sh"
Expand Down
Loading