Skip to content

Conversation

@vittyvk
Copy link

@vittyvk vittyvk commented Apr 24, 2025

LUKS volumes can be automatically unlocked by TPM devices and this comes handy for kdump as there's no need to a manual action. This, however, doesn't work by default:

systemd-cryptsetup[494]: Automatically discovered security TPM2 token unlocks volume.
systemd-cryptsetup[494]: Could not find TPM2 device: Operation not supported
systemd-cryptsetup[494]: TPM2 operation failed, falling back to traditional unlocking: Operation not supported

The problem is that we need to have libcryptsetup-token-systemd-tpm2.so and the corresponding tools/libraries in the initramfs and this is done by 'tpm2-tss' module which is not in the default set. Include it when 'tpm2' tool (tpm2-tools package) is present.

In theory, we can be smarter and try to detect 'systemd-tpm2' tokens with cryptsetup:

 # cryptsetup luksDump /dev/vda2   
 LUKS header information   
 Version:       	2   
 Epoch:         	394   
 ...   
   
 Tokens:   
   1: systemd-tpm2   
 	tpm2-hash-pcrs:   7   
 	tpm2-pcr-bank:    sha256   

but the risk is that tokens can change after kdump initramfs is created. For now, stick to a simpler but more robust solution.

LUKS volumes can be automatically unlocked by TPM devices and this comes
handy for kdump as there's no need to a manual action. This, however,
doesn't work by default:

 systemd-cryptsetup[494]: Automatically discovered security TPM2 token unlocks volume.
 systemd-cryptsetup[494]: Could not find TPM2 device: Operation not supported
 systemd-cryptsetup[494]: TPM2 operation failed, falling back to traditional unlocking: Operation not supported

The problem is that we need to have libcryptsetup-token-systemd-tpm2.so
and the corresponding tools/libraries in the initramfs and this is done by
'tpm2-tss' module which is not in the default set. Include it when 'tpm2'
tool (tpm2-tools package) is present.

In theory, we can be smarter and try to detect 'systemd-tpm2' tokens with
cryptsetup:

 # cryptsetup luksDump /dev/vda2
 LUKS header information
 Version:       	2
 Epoch:         	394
 ...

 Tokens:
   1: systemd-tpm2
 	tpm2-hash-pcrs:   7
 	tpm2-pcr-bank:    sha256

but the risk is that tokens can change after kdump initramfs is
created. For now, stick to a simpler but more robust solution.

Signed-off-by: Vitaly Kuznetsov <[email protected]>
@sourcery-ai
Copy link

sourcery-ai bot commented Apr 24, 2025

Reviewer's Guide by Sourcery

This pull request adds the 'tpm2-tss' dracut module to the kdump initramfs when the 'tpm2-tools' package is present. This allows LUKS volumes to be automatically unlocked by TPM devices during kdump, avoiding the need for manual intervention. The change ensures that the necessary libraries and tools for TPM2 unlocking are included in the initramfs.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Inclusion of the 'tpm2-tss' dracut module based on the presence of 'tpm2-tools'.
  • Added logic to check for the 'tpm2' tool (from the 'tpm2-tools' package).
  • If the 'tpm2' tool is found, the 'tpm2-tss' dracut module is included in the kdump initramfs.
mkdumprd

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @vittyvk - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding a comment explaining why we check for the tpm2 tool instead of the tpm2-tss package directly.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@coiby
Copy link
Member

coiby commented May 6, 2025

Hi @vittyvk ,

Do you have an agenda to support this case in RHEL? If we can wait, I'll prefer a more general solution [PATCH v9 0/8] Support kdump with LUKS encryption by reusing LUKS volume keys. Currently the patch set has been pulled into Andrew Morton's nm-everything tree and there is a good chance it will be pulled into Linus's tree.

@vittyvk
Copy link
Author

vittyvk commented May 6, 2025

Hey @coiby , yes, 'reusing LUKS keys' is a much more interesting feature indeed :-) Here, however, we may be solving one additional use-case: imagine we want to dump to a LUKS device which is not actually used in the main system (e.g. a special dedicated device for dumps) which can be unlocked with TPM. Then, we can't pass LUKS key to it from the main kernel as it doesn't have it. I'm not sure if it is so important though.

@coiby
Copy link
Member

coiby commented Jun 11, 2025

Thanks for proposing another scenario! Unfortunately, kdumpctl needs to unlock the device to check if disk space will be available for vmcore dumping. However it doesn't know how to unlock a LUKS device. If we want to support this additional case, we will need to add these code as well. Otherwise, kdumpctl will fail to build the initramfs,

kdump: Rebuilding /boot/initramfs-6.14.0-rc1+kdump.img
kdump: Dump target "UUID=a3a60e7b-d671-4629-bc5c-b809bbcbde15" is neither mounted nor configured as "noauto"
kdump: mkdumprd: failed to make kdump initrd

Btw, my work to support kdump with LUKS encryption by reusing LUKS volume keys has been merged into Linus's tree. While doing the corresponding user space part in kdump-utils and anaconda, I'll also evaluate the necessity of this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants