Support kdump with LUKS encryption by reusing LUKS volume key
Subsystems (7)
cover Support kdump with LUKS encryption by reusing LUKS volume key
v1
- "Put the luks key handling related to crash_dump out into a separate file kernel/crash_dump_luks.c" [Baoquan]
- Put the generic luks handling code before the x86 specific code to make it easier for other arches to follow suit [Baoquan]
- Use phys_to_virt instead of "pfn -> page -> vaddr" [Dave Hansen]
- Drop the RFC prefix [Dave Young]
- Rebase the code onto latest Linus tree (6.4.0-rc4)
RFC v2
- libcryptsetup interacts with the kernel via sysfs instead of "hacking" dm-crypt
- to save a kdump copy of the LUKS volume key in 1st kernel
- to add a logon key using the copy for libcryptsetup in kdump kernel [Milan]
- to avoid the incorrect usage of LUKS master key in dm-crypt [Milan]
- save the kdump copy of LUKS volume key randomly [Jan]
- mark the kdump copy inaccessible [Pingfan]
- Miscellaneous
- explain when operations related to the LUKS volume key happen [Jan]
- s/master key/volume key/g
- use crash_ instead of kexec_ as function prefix
- fix commit subject prefixes e.g. "x86, kdump" to x86/crash
LUKS is the standard for Linux disk encryption. Many users choose LUKS and in some use cases like Confidential VM it's mandated. With kdump enabled, when the 1st kernel crashes, the system could boot into the kdump/crash kernel and dump the memory image i.e. /proc/vmcore to a specified target. Currently, when dumping vmcore to a LUKS encrypted device, there are two problems,
- Kdump kernel may not be able to decrypt the LUKS partition. For some machines, a system administrator may not have a chance to enter the password to decrypt the device in kdump initramfs after the 1st kernel crashes; For cloud confidential VMs, the kdump kernel can't unseal the key with TPM.
- LUKS2 by default use the memory-hard Argon2 key derivation function which is quite memory-consuming compared to the limited memory reserved for kdump. Take Fedora example, by default, only 256M is reserved for systems having memory between 4G-64G. With LUKS enabled, ~1300M needs to be reserved for kdump. Note if the memory reserved for kdump can't be used by 1st kernel i.e. an user sees ~1300M memory missing in the 1st kernel.
Besides users (at least for Fedora) usually expect kdump to work out of the box i.e. no manual password input is needed. And it doesn't make sense to derivate the key again in kdump kernel which seems to be redundant work.
Based on Milan's feedback [1] on Kairui's ideas to support kdump with LUKS encryption, this patch set addresses the above issues by reusing the LUKS volume key in kdump kernel and here is the life cycle of this kdump copy of LUKS volume key,
1. After the 1st kernel loads the initramfs during boot, systemd asks for a passphrase from the user and uses it to de-crypt the LUKS volume key
2. After the 1st kernel saving the volume key as a logon key, libcrytpsetup notifies the kernel to read this logon key and store a temporary copy by writing the key description to /sys/kernel/crash_luks_volume_key
3. After switching to the real root fs, kdump.serivce is started and it loads the kdump kernel using the kexec_file_load syscall
4. The kexec_file_load syscall saves the temporary copy of the volume key to kdump reserved memory and wipe the copy.
5. When the 1st kernel crashes and kdump kernel is booted, libcryptsetup asks the kdump kernel to add a logon key using the volume key stored in kdump reserved memory by writing the key description to /sys/kernel/crash_luks_volume_key
6. The system gets rebooted to the 1st kernel after dumping vmcore to the LUKS encrypted device is finished
Note the kdump copy of LUKS volume key never leaves the kernel space and is saved in the memory area exclusively reserved for kdump where even the 1st kernel has no direct access.
Milan's major concern [2] on previous version is "storing the encryption key to yet another place are creating another attack vector". To further secure this copy, two additional protections are added,
- save the copy randomly in kdump reserved memory as suggested by Jan
- clear the _PAGE_PRESENT flag of the page that stores the copy as suggested by Pingfan
If there is no further security concern with this approach or any other concern, I will drop the following assumptions,
- only x86 is supported
- there is only one LUKS device for the system
to extend the support to other architectures including POWER, ARM and s390x and address the case of multiple LUKS devices. Any feedback will be appreciated, thanks!
For a proof of concept, I've patched cryptsetup [3] in a quick-and-dirty way to support a new option "--kdump-kernel-master-key"
and hacked systemd [4]. It works for Fedora 37.
[1] https://yhbt.net/lore/all/[email protected]/
[2] https://lwn.net/ml/linux-kernel/[email protected]/
[3] https://gitlab.com/coxu/cryptsetup/-/commit/750a46d933fac82e0c994b5c41de40a0b8cac647
[4] https://github.com/coiby/systemd/tree/reuse_kdump_master_key
Coiby Xu (5):
kexec_file: allow to place kexec_buf randomly
crash_dump: save the LUKS volume key temporarily
crash_dump: retrieve LUKS volume key in kdump kernel x86/crash: pass the LUKS volume key to kdump kernel x86/crash: make the page that stores the LUKS volume key inaccessible
arch/x86/include/asm/crash.h | 1 + arch/x86/kernel/crash.c | 47 ++++++- arch/x86/kernel/kexec-bzimage64.c | 7 + arch/x86/kernel/machine_kexec_64.c | 14 ++ include/linux/crash_core.h | 2 + include/linux/crash_dump.h | 2 + include/linux/kexec.h | 6 + kernel/Makefile | 2 +- kernel/crash_dump_luks.c | 202 +++++++++++++++++++++++++++++ kernel/kexec_file.c | 15 +++ kernel/ksysfs.c | 19 +++ 11 files changed, 315 insertions(+), 2 deletions(-) create mode 100644 kernel/crash_dump_luks.c
Signature · 1 line
2.40.1
PATCH 1/5 kexec_file: allow to place kexec_buf randomly
Currently, kexec_buf is placed in order which means for the same machine, the info in the kexec_buf is always located at the same position each time the machine is booted. This may cause a risk for sensitive information like LUKS volume key. Now struct kexec_buf has a new field random which indicates it's supposed to be placed in a random position.
--- include/linux/kexec.h | 2 ++ kernel/kexec_file.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+)
include/linux/kexec.h +2 -0
@@ -172,6 +172,7 @@ int kexec_image_post_load_cleanup_default(struct kimage *image);* @buf_min: The buffer can't be placed below this address. * @buf_max: The buffer can't be placed above this address. * @top_down: Allocate from top of memory. +* @random: Place the buffer at a random position. */ struct kexec_buf {struct kimage *image;
@@ -183,6 +184,7 @@ struct kexec_buf {unsigned long buf_min;unsigned long buf_max;bool top_down; +bool random; };int kexec_load_purgatory (struct kimage *image,struct kexec_buf *kbuf);
kernel/kexec_file.c +15 -0
@@ -25,6 +25,7 @@#include <linux/elfcore.h> #include <linux/kernel.h> #include <linux/kernel_read_file.h> +#include <linux/prandom.h> #include <linux/syscalls.h> #include <linux/vmalloc.h> #include "kexec_internal.h"
@@ -419,6 +420,16 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd,return ret; } +static unsigned long kexec_random_start (unsigned long start,unsigned long end) +{ +unsigned long temp_start; +unsigned short i; + +get_random_bytes (&i,sizeof (unsigned short )); + temp_start = start + (end - start) /USHRT_MAX * i; +return temp_start; +} +static int locate_mem_hole_top_down (unsigned long start,unsigned long end,struct kexec_buf *kbuf) {
@@ -427,6 +438,8 @@ static int locate_mem_hole_top_down(unsigned long start, unsigned long end, temp_end =min (end, kbuf->buf_max); temp_start = temp_end - kbuf->memsz; +if (kbuf->random) + temp_start =kexec_random_start (temp_start, temp_end); do { /* align down start */
@@ -464,6 +477,8 @@ static int locate_mem_hole_bottom_up(unsigned long start, unsigned long end,unsigned long temp_start, temp_end; temp_start =max (start, kbuf->buf_min); +if (kbuf->random) + temp_start =kexec_random_start (temp_start, end); do { temp_start = ALIGN(temp_start, kbuf->buf_align);
Signature · 1 line
2.40.1
PATCH 2/5 crash_dump: save the LUKS volume key temporarily
In reply to Coiby XuAfter having the volume key, crytpsetup/systemd-cryptsetup saves the volume key as a logon key to its thread keyring and this key is destroyed immediately with the terminated thread. So a temporary copy of the volume key is needed in order to later save it to kdump reserved memory when the crash kernel is loaded later.
crytpsetup/systemd-cryptsetup will write the key description to /sys/kernel/crash_luks_volume_key so the kernel will read the logon key and save a temporary copy for later user. kdump has 1 hour at maximum to get the temporary copy before the key gets wiped. And after kdump retrieves the key, the key will be wiped immediately.
--- include/linux/crash_core.h | 2 + kernel/Makefile | 2 +- kernel/crash_dump_luks.c | 90 ++++++++++++++++++++++++++++++++++++++ kernel/ksysfs.c | 19 ++++++++ 4 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 kernel/crash_dump_luks.c
include/linux/crash_core.h +2 -0
@@ -83,5 +83,7 @@ int parse_crashkernel_high(char *cmdline, unsigned long long system_ram, unsigned long long *crash_size, unsigned long long *crash_base);int parse_crashkernel_low (char *cmdline,unsigned long long system_ram,unsigned long long *crash_size,unsigned long long *crash_base); +int crash_sysfs_luks_volume_key_write (const char *key_des,size_t count); +int crash_pass_temp_luks_volume_key (void **addr,unsigned long *sz);#endif /* LINUX_CRASH_CORE_H */
kernel/Makefile +1 -1
@@ -118,7 +118,7 @@ obj-$(CONFIG_PERF_EVENTS) += events/ obj-$(CONFIG_USER_RETURN_NOTIFIER) += user-return-notifier.o obj-$(CONFIG_PADATA) += padata.o -obj-$(CONFIG_CRASH_DUMP) += crash_dump.o +obj-$(CONFIG_CRASH_DUMP) += crash_dump.o crash_dump_luks.o obj-$(CONFIG_JUMP_LABEL) += jump_label.o obj-$(CONFIG_CONTEXT_TRACKING) += context_tracking.o obj-$(CONFIG_TORTURE_TEST) += torture.o
kernel/crash_dump_luks.c new file +90 -0
90 lines not on this page · raw message
kernel/ksysfs.c +19 -0
@@ -165,6 +165,24 @@ static ssize_t vmcoreinfo_show(struct kobject *kobj, }KERNEL_ATTR_RO (vmcoreinfo); +static ssize_t crash_luks_volume_key_show (struct kobject *kobj, +struct kobj_attribute *attr, +char *buf) +{ +return 0 ; +} + +static ssize_t crash_luks_volume_key_store (struct kobject *kobj, +struct kobj_attribute *attr, +const char *buf,size_t count) +{ +int ret; + + ret =crash_sysfs_luks_volume_key_write (buf, count); +return ret <0 ? ret : count; +} +KERNEL_ATTR_RW (crash_luks_volume_key); +#endif /* CONFIG_CRASH_CORE */ /* whether file capabilities are enabled */
@@ -255,6 +273,7 @@ static struct attribute * kernel_attrs[] = {#endif #ifdef CONFIG_CRASH_CORE &vmcoreinfo_attr.attr, + &crash_luks_volume_key_attr.attr, #endif #ifndef CONFIG_TINY_RCU &rcu_expedited_attr.attr,
Signature · 1 line
2.40.1
PATCH 3/5 crash_dump: retrieve LUKS volume key in kdump kernel
In reply to Coiby XuCrash kernel will retrieve the LUKS volume key based on the luksvolumekey command line parameter. When libcryptsetup writes the key description to /sys/kernel/crash_luks_volume_key, crash kernel will create a thread keyring and add a logon key.
--- include/linux/crash_dump.h | 2 + kernel/crash_dump_luks.c | 116 ++++++++++++++++++++++++++++++++++++- 2 files changed, 116 insertions(+), 2 deletions(-)
include/linux/crash_dump.h +2 -0
@@ -15,6 +15,8 @@extern unsigned long long elfcorehdr_addr;extern unsigned long long elfcorehdr_size; +extern unsigned long long luks_volume_key_addr; +#ifdef CONFIG_CRASH_DUMP extern int elfcorehdr_alloc (unsigned long long *addr,unsigned long long *size);extern void elfcorehdr_free (unsigned long long addr);
kernel/crash_dump_luks.c +114 -2
140 lines not on this page · raw message
Signature · 1 line
2.40.1
PATCH 4/5 x86/crash: pass the LUKS volume key to kdump kernel
In reply to Coiby Xu1st kernel will build up the kernel command parameter luksvolumekey as similar to elfcorehdr to pass the memory address of the stored info of LUKS volume key to kdump kernel.
--- arch/x86/include/asm/crash.h | 1 + arch/x86/kernel/crash.c | 47 ++++++++++++++++++++++++++++++- arch/x86/kernel/kexec-bzimage64.c | 7 +++++ include/linux/kexec.h | 4 +++ 4 files changed, 58 insertions(+), 1 deletion(-)
arch/x86/include/asm/crash.h +1 -0
@@ -4,6 +4,7 @@struct kimage ; +int crash_load_luks_volume_key (struct kimage *image);int crash_load_segments (struct kimage *image);int crash_setup_memmap_entries (struct kimage *image,struct boot_params *params);
arch/x86/kernel/crash.c +46 -1
65 lines not on this page · raw message
arch/x86/kernel/kexec-bzimage64.c +7 -0
@@ -76,6 +76,10 @@ static int setup_cmdline(struct kimage *image, struct boot_params *params,if (image->type ==KEXEC_TYPE_CRASH ) { len =sprintf (cmdline_ptr,"elfcorehdr=0x%lx " , image->elf_load_addr); + +if (image->luks_volume_key_addr !=0 ) + len +=sprintf (cmdline_ptr + len, +"luksvolumekey=0x%lx " , image->luks_volume_key_addr); }memcpy (cmdline_ptr + len, cmdline, cmdline_len); cmdline_len += len;
@@ -433,6 +437,9 @@ static void *bzImage64_load(struct kimage *image, char *kernel, ret =crash_load_segments (image);if (ret)return ERR_PTR (ret); + ret =crash_load_luks_volume_key (image); +if (ret) +pr_debug ("Either no LUKS volume key or error to retrieve the LUKS volume key\n" ); }/*
include/linux/kexec.h +4 -0
@@ -374,6 +374,10 @@ struct kimage {void *elf_headers;unsigned long elf_headers_sz;unsigned long elf_load_addr; + +/* LUKS volume key buffer */ +unsigned long luks_volume_key_addr; +unsigned long luks_volume_key_sz; };/* kexec interface functions */
Signature · 1 line
2.40.1
PATCH 5/5 x86/crash: make the page that stores the LUKS volume key inaccessible
In reply to Coiby XuThis adds an addition layer of protection for the saved copy of LUKS volume key. Trying to access the saved copy will cause page fault.
--- arch/x86/kernel/machine_kexec_64.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
arch/x86/kernel/machine_kexec_64.c +14 -0
@@ -546,9 +546,23 @@ static void kexec_mark_crashkres(bool protect)kexec_mark_range (control, crashk_res.end, protect); } +static void kexec_mark_luks_volume_key_inaccessible (void ) +{ +unsigned long start_paddr, end_paddr; +unsigned int nr_pages; + +if (kexec_crash_image->luks_volume_key_addr) { + start_paddr = kexec_crash_image->luks_volume_key_addr; + end_paddr = start_paddr + kexec_crash_image->luks_volume_key_sz -1 ; + nr_pages = (PAGE_ALIGN (end_paddr) -PAGE_ALIGN_DOWN (start_paddr))/PAGE_SIZE ; +set_memory_np ((unsigned long )phys_to_virt (start_paddr), nr_pages); + } +} +void arch_kexec_protect_crashkres (void ) {kexec_mark_crashkres (true); +kexec_mark_luks_volume_key_inaccessible (); }void arch_kexec_unprotect_crashkres (void )
Signature · 1 line
2.40.1
Quoted 1 line · Coiby Xu
[PATCH 0/5] Support kdump with LUKS encryption by reusing LUKS volume key
The kernel has no concept of LUKS at all. It provides dm-crypt, which LUKS happens to use. But LUKS is a userspace concept.
This is a kernel patchset, so why does it make sense for it to be talking about LUKS at all? Perhaps you mean dm-crypt?
- Eric
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 8 lines · Eric Biggers
Quoted 1 line · Coiby Xu
[PATCH 0/5] Support kdump with LUKS encryption by reusing LUKS volume key
The kernel has no concept of LUKS at all. It provides dm-crypt, which LUKS happens to use. But LUKS is a userspace concept.
This is a kernel patchset, so why does it make sense for it to be talking about LUKS at all? Perhaps you mean dm-crypt?
Exactly.
I had the same comment almost a year ago... and it still applies:
https://lore.kernel.org/all/[email protected]/
Anyway, please fix the naming before this patchset can be read or reviewed!
LUKS is user-space key management only (on-disk metadata); the kernel has no idea how the key is derived or what LUKS is - dm-crypt only knows the key (either through keyring or directly in the mapping table).
Polluting kernel namespace with "luks" names variables is wrong - dm-crypt is used in many other mappings (plain, bitlocker, veracrypt, ...) Just use the dm-crypt key, do not reference LUKS at all.
Milan
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Hi Eric and Milan,
Quoted 11 lines · Milan Broz
Quoted 8 lines · Eric Biggers
Quoted 1 line · Coiby Xu
[PATCH 0/5] Support kdump with LUKS encryption by reusing LUKS volume key
The kernel has no concept of LUKS at all. It provides dm-crypt, which LUKS happens to use. But LUKS is a userspace concept.
This is a kernel patchset, so why does it make sense for it to be talking about LUKS at all? Perhaps you mean dm-crypt?
Exactly.
Thanks for raising the above concern! The use cases like CoreOS and Confidential VMs explicitly want kdump to work for LUKS. And correct me if I'm wrong, I think the two problems addressed by this patch set only apply to LUKS so the kdump part of the kernel only cares about the LUKS case. If there are use cases where similar approach is needed, I'll be happy to make the solution more generic.
Quoted 6 lines
I had the same comment almost a year ago... and it still applies:
https://lore.kernel.org/all/[email protected]/Anyway, please fix the naming before this patchset can be read or reviewed!
Quoted 7 lines
LUKS is user-space key management only (on-disk metadata); the kernel has no idea how the key is derived or what LUKS is - dm-crypt only knows the key (either through keyring or directly in the mapping table).
Polluting kernel namespace with "luks" names variables is wrong - dm-crypt is used in many other mappings (plain, bitlocker, veracrypt, ...) Just use the dm-crypt key, do not reference LUKS at all.
Thanks for the reminding! That comment was on the first RFC version. But starting with "RFC v2", there is no longer any interaction with dm-crypt (to save a copy of the LUKS volume key for the kdump kernel) and now I make cryptsetup talks to the kdump part of the kernel via the sysfs to reuse the volume key. So only the kdump part of the kernel needs to know LUKS which is what it cares. Thus I don't think there is any kernel namespace pollution now.
Quoted 3 lines
Milan
Signature · 8 lines
Best regards, Coiby _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Quoted 36 lines · Coiby Xu
Hi Eric and Milan,
Quoted 11 lines · Milan Broz
Quoted 8 lines · Eric Biggers
Quoted 1 line · Coiby Xu
[PATCH 0/5] Support kdump with LUKS encryption by reusing LUKS volume key
The kernel has no concept of LUKS at all. It provides dm-crypt, which LUKS happens to use. But LUKS is a userspace concept.
This is a kernel patchset, so why does it make sense for it to be talking about LUKS at all? Perhaps you mean dm-crypt?
Exactly.
Thanks for raising the above concern! The use cases like CoreOS and Confidential VMs explicitly want kdump to work for LUKS. And correct me if I'm wrong, I think the two problems addressed by this patch set only apply to LUKS so the kdump part of the kernel only cares about the LUKS case. If there are use cases where similar approach is needed, I'll be happy to make the solution more generic.
Quoted 6 lines
I had the same comment almost a year ago... and it still applies:
https://lore.kernel.org/all/[email protected]/Anyway, please fix the naming before this patchset can be read or reviewed!
Quoted 7 lines
LUKS is user-space key management only (on-disk metadata); the kernel has no idea how the key is derived or what LUKS is - dm-crypt only knows the key (either through keyring or directly in the mapping table).
Polluting kernel namespace with "luks" names variables is wrong - dm-crypt is used in many other mappings (plain, bitlocker, veracrypt, ...) Just use the dm-crypt key, do not reference LUKS at all.
Quoted 7 lines
Thanks for the reminding! That comment was on the first RFC version. But starting with "RFC v2", there is no longer any interaction with dm-crypt (to save a copy of the LUKS volume key for the kdump kernel) and now I make cryptsetup talks to the kdump part of the kernel via the sysfs to reuse the volume key. So only the kdump part of the kernel needs to know LUKS which is what it cares. Thus I don't think there is any kernel namespace pollution now.
Hi,
I am sorry if I did understand correctly, but I thought that kdump is part of the kernel.
I am trying to say that kernel generally has no concept of LUKS; this is a userspace abstraction for key management.
Even the cryptsetup dm-crypt configuration mapping table generated from LUKS has nothing LUKS special in it (only in DM-UUID as a name prefix).
So I do not understand why you need to mention LUKS even in kdump part. Perhaps it is still only a naming problem, nothing more.
All you need is to preserve key and configuration parameters (for dm-crypt). If it is set by cryptsetup, dmsetup, or any other way is not important - on this kernel layer, it has nothing to do with LUKS key management metadata.
No problem if you support only LUKS in userspace, but really, all this machinery should work for any dm-crypt devices. Perhaps your patch even works for it already.
Milan
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 45 lines · Milan Broz
Quoted 36 lines · Coiby Xu
Hi Eric and Milan,
Quoted 11 lines · Milan Broz
Quoted 8 lines · Eric Biggers
Quoted 1 line · Coiby Xu
[PATCH 0/5] Support kdump with LUKS encryption by reusing LUKS volume key
The kernel has no concept of LUKS at all. It provides dm-crypt, which LUKS happens to use. But LUKS is a userspace concept.
This is a kernel patchset, so why does it make sense for it to be talking about LUKS at all? Perhaps you mean dm-crypt?
Exactly.
Thanks for raising the above concern! The use cases like CoreOS and Confidential VMs explicitly want kdump to work for LUKS. And correct me if I'm wrong, I think the two problems addressed by this patch set only apply to LUKS so the kdump part of the kernel only cares about the LUKS case. If there are use cases where similar approach is needed, I'll be happy to make the solution more generic.
Quoted 6 lines
I had the same comment almost a year ago... and it still applies:
https://lore.kernel.org/all/[email protected]/Anyway, please fix the naming before this patchset can be read or reviewed!
Quoted 7 lines
LUKS is user-space key management only (on-disk metadata); the kernel has no idea how the key is derived or what LUKS is - dm-crypt only knows the key (either through keyring or directly in the mapping table).
Polluting kernel namespace with "luks" names variables is wrong - dm-crypt is used in many other mappings (plain, bitlocker, veracrypt, ...) Just use the dm-crypt key, do not reference LUKS at all.
Quoted 7 lines
Thanks for the reminding! That comment was on the first RFC version. But starting with "RFC v2", there is no longer any interaction with dm-crypt (to save a copy of the LUKS volume key for the kdump kernel) and now I make cryptsetup talks to the kdump part of the kernel via the sysfs to reuse the volume key. So only the kdump part of the kernel needs to know LUKS which is what it cares. Thus I don't think there is any kernel namespace pollution now.
Quoted 4 lines
Hi,
I am sorry if I did understand correctly, but I thought that kdump is part of the kernel.
Yes, there is the kernel part of the kdump although there is also the userspace part to make the feature complete:)
Quoted 10 lines
I am trying to say that kernel generally has no concept of LUKS; this is a userspace abstraction for key management.
Even the cryptsetup dm-crypt configuration mapping table generated from LUKS has nothing LUKS special in it (only in DM-UUID as a name prefix).
So I do not understand why you need to mention LUKS even in kdump part. Perhaps it is still only a naming problem, nothing more.
Quoted 6 lines
All you need is to preserve key and configuration parameters (for dm-crypt). If it is set by cryptsetup, dmsetup, or any other way is not important - on this kernel layer, it has nothing to do with LUKS key management metadata.
No problem if you support only LUKS in userspace, but really, all this machinery should work for any dm-crypt devices. Perhaps your patch even works for it already.
Thanks for the explanation! After reflecting on your words for some time, I realize I had an implicit assumption. I assumed is if I use a name like dm_crypt_key instead of luks_volume_key, I need to support all mappings like plain, bitlocker, veracrypt as mentioned by you and this could mean much more efforts. So I'm not motivated to do that as currently users only request kdump to work for LUKS.
But maybe I can divide the efforts into the kernel part and userspace part. For the kernel part, almost no effort is needed since only renaming is needed as pointed out by you. For the userpace part, maybe it's OK to support preserving key only for LUKS2 in cryptsetup as hinted by your last paragraph? Does it look good to you from the viewpoint of the maintainer of cryptsetup?
Quoted 3 lines
Milan
Signature · 8 lines
Best regards, Coiby _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Quoted 71 lines · Coiby Xu
Quoted 45 lines · Milan Broz
Quoted 36 lines · Coiby Xu
Hi Eric and Milan,
Quoted 11 lines · Milan Broz
Quoted 8 lines · Eric Biggers
Quoted 1 line · Coiby Xu
[PATCH 0/5] Support kdump with LUKS encryption by reusing LUKS volume key
The kernel has no concept of LUKS at all. It provides dm-crypt, which LUKS happens to use. But LUKS is a userspace concept.
This is a kernel patchset, so why does it make sense for it to be talking about LUKS at all? Perhaps you mean dm-crypt?
Exactly.
Thanks for raising the above concern! The use cases like CoreOS and Confidential VMs explicitly want kdump to work for LUKS. And correct me if I'm wrong, I think the two problems addressed by this patch set only apply to LUKS so the kdump part of the kernel only cares about the LUKS case. If there are use cases where similar approach is needed, I'll be happy to make the solution more generic.
Quoted 6 lines
I had the same comment almost a year ago... and it still applies:
https://lore.kernel.org/all/[email protected]/Anyway, please fix the naming before this patchset can be read or reviewed!
Quoted 7 lines
LUKS is user-space key management only (on-disk metadata); the kernel has no idea how the key is derived or what LUKS is - dm-crypt only knows the key (either through keyring or directly in the mapping table).
Polluting kernel namespace with "luks" names variables is wrong - dm-crypt is used in many other mappings (plain, bitlocker, veracrypt, ...) Just use the dm-crypt key, do not reference LUKS at all.
Quoted 7 lines
Thanks for the reminding! That comment was on the first RFC version. But starting with "RFC v2", there is no longer any interaction with dm-crypt (to save a copy of the LUKS volume key for the kdump kernel) and now I make cryptsetup talks to the kdump part of the kernel via the sysfs to reuse the volume key. So only the kdump part of the kernel needs to know LUKS which is what it cares. Thus I don't think there is any kernel namespace pollution now.
Quoted 4 lines
Hi,
I am sorry if I did understand correctly, but I thought that kdump is part of the kernel.
Yes, there is the kernel part of the kdump although there is also the userspace part to make the feature complete:)
Quoted 10 lines
I am trying to say that kernel generally has no concept of LUKS; this is a userspace abstraction for key management.
Even the cryptsetup dm-crypt configuration mapping table generated from LUKS has nothing LUKS special in it (only in DM-UUID as a name prefix).
So I do not understand why you need to mention LUKS even in kdump part. Perhaps it is still only a naming problem, nothing more.
Quoted 6 lines
All you need is to preserve key and configuration parameters (for dm-crypt). If it is set by cryptsetup, dmsetup, or any other way is not important - on this kernel layer, it has nothing to do with LUKS key management metadata.
No problem if you support only LUKS in userspace, but really, all this machinery should work for any dm-crypt devices. Perhaps your patch even works for it already.
Quoted 6 lines
Thanks for the explanation! After reflecting on your words for some time, I realize I had an implicit assumption. I assumed is if I use a name like
dm_crypt_keyinstead ofluks_volume_key, I need to support all mappings like plain, bitlocker, veracrypt as mentioned by you and this could mean much more efforts. So I'm not motivated to do that as currently users only request kdump to work for LUKS.
Thanks, I think it is perfectly fine to implement just subset here.
Quoted 6 lines
But maybe I can divide the efforts into the kernel part and userspace part. For the kernel part, almost no effort is needed since only renaming is needed as pointed out by you. For the userpace part, maybe it's OK to support preserving key only for LUKS2 in cryptsetup as hinted by your last paragraph? Does it look good to you from the viewpoint of the maintainer of cryptsetup?
My comment was just about proper naming in kernel, it is of course up to you what you want to support in userspace (and even in kernel, extensions can be added later).
Only LUKS2 uses keyring for volume key in dm-crypt as default option anyway. I do not think you need any cryptsetup patches, all you need is to write decrypted volume key from LUKS metadata with
cryptsetup luksDump ---dump-volume-key -volume-key-file <out> <device>
(or any code equivalent with libcryptsetup), am I correct?
Milan
--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
Quoted 81 lines · Milan Broz
Quoted 71 lines · Coiby Xu
Quoted 45 lines · Milan Broz
Quoted 36 lines · Coiby Xu
Hi Eric and Milan,
Quoted 11 lines · Milan Broz
Quoted 8 lines · Eric Biggers
Quoted 1 line · Coiby Xu
[PATCH 0/5] Support kdump with LUKS encryption by reusing LUKS volume key
The kernel has no concept of LUKS at all. It provides dm-crypt, which LUKS happens to use. But LUKS is a userspace concept.
This is a kernel patchset, so why does it make sense for it to be talking about LUKS at all? Perhaps you mean dm-crypt?
Exactly.
Thanks for raising the above concern! The use cases like CoreOS and Confidential VMs explicitly want kdump to work for LUKS. And correct me if I'm wrong, I think the two problems addressed by this patch set only apply to LUKS so the kdump part of the kernel only cares about the LUKS case. If there are use cases where similar approach is needed, I'll be happy to make the solution more generic.
Quoted 6 lines
I had the same comment almost a year ago... and it still applies:
https://lore.kernel.org/all/[email protected]/Anyway, please fix the naming before this patchset can be read or reviewed!
Quoted 7 lines
LUKS is user-space key management only (on-disk metadata); the kernel has no idea how the key is derived or what LUKS is - dm-crypt only knows the key (either through keyring or directly in the mapping table).
Polluting kernel namespace with "luks" names variables is wrong - dm-crypt is used in many other mappings (plain, bitlocker, veracrypt, ...) Just use the dm-crypt key, do not reference LUKS at all.
Quoted 7 lines
Thanks for the reminding! That comment was on the first RFC version. But starting with "RFC v2", there is no longer any interaction with dm-crypt (to save a copy of the LUKS volume key for the kdump kernel) and now I make cryptsetup talks to the kdump part of the kernel via the sysfs to reuse the volume key. So only the kdump part of the kernel needs to know LUKS which is what it cares. Thus I don't think there is any kernel namespace pollution now.
Quoted 4 lines
Hi,
I am sorry if I did understand correctly, but I thought that kdump is part of the kernel.
Yes, there is the kernel part of the kdump although there is also the userspace part to make the feature complete:)
Quoted 10 lines
I am trying to say that kernel generally has no concept of LUKS; this is a userspace abstraction for key management.
Even the cryptsetup dm-crypt configuration mapping table generated from LUKS has nothing LUKS special in it (only in DM-UUID as a name prefix).
So I do not understand why you need to mention LUKS even in kdump part. Perhaps it is still only a naming problem, nothing more.
Quoted 6 lines
All you need is to preserve key and configuration parameters (for dm-crypt). If it is set by cryptsetup, dmsetup, or any other way is not important - on this kernel layer, it has nothing to do with LUKS key management metadata.
No problem if you support only LUKS in userspace, but really, all this machinery should work for any dm-crypt devices. Perhaps your patch even works for it already.
Quoted 6 lines
Thanks for the explanation! After reflecting on your words for some time, I realize I had an implicit assumption. I assumed is if I use a name like
dm_crypt_keyinstead ofluks_volume_key, I need to support all mappings like plain, bitlocker, veracrypt as mentioned by you and this could mean much more efforts. So I'm not motivated to do that as currently users only request kdump to work for LUKS.Thanks, I think it is perfectly fine to implement just subset here.
[...]
Quoted 4 lines
My comment was just about proper naming in kernel, it is of course up to you what you want to support in userspace (and even in kernel, extensions can be added later).
Thanks for the confirmation!
Quoted 2 lines
Only LUKS2 uses keyring for volume key in dm-crypt as default option anyway.
Thanks for the info!
Quoted 4 lines
I do not think you need any cryptsetup patches, all you need is to write decrypted volume key from LUKS metadata with
cryptsetup luksDump ---dump-volume-key -volume-key-file <out> <device>
(or any code equivalent with libcryptsetup), am I correct?
Correct me if I'm wrong, but I don't think there will be a safer way to preserve key without patching cryptsetup. Actually the --dump-volume-key approach has been proposed before and I agree with your conclusion [1] on that approach i.e. "passing volume key this way is quite insecure". Without patching cryptsetup, even if I save the volume key in the memory reserved for the kdump kernel, I need to retrieve this key in the userspace to unlock the LUKS device which may lead to quite a security vulnerability.
I respect the efforts from you and the cryptsetup community to make LUKS as secure as possible. And kdump is used in product environment. Kdump is to a server as a black box is to an aircraft. So by no means I want to reverse the used security measures and patching cryptsetup can allow to keep the security measures. One concern raised by you against "FRC v1" was a copy of the LUKS volume key for the kdump kernel creates an attack vector. I took this feedback seriously and have sought advice from my colleagues to implement the countermeasures ([PATCH 1/5] and [Patch 4/5]).
[1] https://yhbt.net/lore/all/[email protected]/
Quoted 3 lines
Milan
Signature · 8 lines
Best regards, Coiby _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
On 6/7/23 14:39, Coiby Xu wrote:
...
Quoted 5 lines
Quoted 4 lines
I do not think you need any cryptsetup patches, all you need is to write decrypted volume key from LUKS metadata with
cryptsetup luksDump ---dump-volume-key -volume-key-file <out> <device>
(or any code equivalent with libcryptsetup), am I correct?
Quoted 8 lines
Correct me if I'm wrong, but I don't think there will be a safer way to preserve key without patching cryptsetup. Actually the --dump-volume-key approach has been proposed before and I agree with your conclusion [1] on that approach i.e. "passing volume key this way is quite insecure". Without patching cryptsetup, even if I save the volume key in the memory reserved for the kdump kernel, I need to retrieve this key in the userspace to unlock the LUKS device which may lead to quite a security vulnerability.
Hm, where are the patches for cryptsetup, then? I am afraid we do not want to add such specific things there.
But we are just going to merge a patchset that changes how we use keyring where you can tell cryptsetup to store/link key under some specific name and to specific keyring
(see https://gitlab.com/cryptsetup/cryptsetup/-/merge_requests/492)
(Please talk to Red Hat cryptsetup maintainers for more info, I just mentioned this mail to them today.)
Quoted 11 lines
I respect the efforts from you and the cryptsetup community to make LUKS as secure as possible. And kdump is used in product environment. Kdump is to a server as a black box is to an aircraft. So by no means I want to reverse the used security measures and patching cryptsetup can allow to keep the security measures. One concern raised by you against "FRC v1" was a copy of the LUKS volume key for the kdump kernel creates an attack vector. I took this feedback seriously and have sought advice from my colleagues to implement the countermeasures ([PATCH 1/5] and [Patch 4/5]).
Yes, I appreciate that. And it is perfectly ok if your customers accept the trade-off and security risk of handling the key this way.
Anyway, I feel we are going in circles here, and as it seems to be my fault, I do not want to sound grumpy as I am perhaps missing some context.
Could you please talk to internal RH cryptsetup maintainers first and discuss your solution? They know what we can do here can help to find an acceptable solution. (I added cc to Ondra.)
Thanks,
Milan
Quoted 16 lines · Milan Broz
On 6/7/23 14:39, Coiby Xu wrote:
...Quoted 5 lines
Quoted 4 lines
I do not think you need any cryptsetup patches, all you need is to write decrypted volume key from LUKS metadata with
cryptsetup luksDump ---dump-volume-key -volume-key-file <out> <device>
(or any code equivalent with libcryptsetup), am I correct?Quoted 8 lines
Correct me if I'm wrong, but I don't think there will be a safer way to preserve key without patching cryptsetup. Actually the --dump-volume-key approach has been proposed before and I agree with your conclusion [1] on that approach i.e. "passing volume key this way is quite insecure". Without patching cryptsetup, even if I save the volume key in the memory reserved for the kdump kernel, I need to retrieve this key in the userspace to unlock the LUKS device which may lead to quite a security vulnerability.
Quoted 2 lines
Hm, where are the patches for cryptsetup, then? I am afraid we do not want to add such specific things there.
Thanks for cleaning up the text to make the discussion easier! Sorry I only mentioned it [3] in the cover letter and didn't provide one in previous reply. [3] was done in a quick-and-dirty way (I plan to send a formal merge request after finishing the kernel part) and there is no need to read it. Let's me explain what [3] does here instead,
1) After unlocking the LUKS-encrypted device, if cryptsetup finds /sys/kernel/crash_luks_volume_key exists, it will write the key description of the volume key to it to notify the kernel to save a copy of this logon key linked to its thread keyring for the kdump kernel
2) After the 1st kernel crashes, if crytpsetup finds it's in the kdump kernel, instead of deriving the volume key from a passphrase, it will write the key description to /sys/kernel/crash_luks_volume_key to ask the kdump kernel to link the saved key to its thread keyring.
[3] https://gitlab.com/coxu/cryptsetup/-/commit/750a46d933fac82e0c994b5c41de40a0b8cac647
Quoted 7 lines
But we are just going to merge a patchset that changes how we use keyring where you can tell cryptsetup to store/link key under some specific name and to specific keyring
(see https://gitlab.com/cryptsetup/cryptsetup/-/merge_requests/492)
(Please talk to Red Hat cryptsetup maintainers for more info, I just mentioned this mail to them today.)
Thanks for pointing me to the above MR which looks promising! Unlike treating the kdump use case as a special case [3], it just provides a generic way with the implemented options --link-vk-to-keyring and --volume-key-keyring.
Quoted 11 lines
Quoted 11 lines
I respect the efforts from you and the cryptsetup community to make LUKS as secure as possible. And kdump is used in product environment. Kdump is to a server as a black box is to an aircraft. So by no means I want to reverse the used security measures and patching cryptsetup can allow to keep the security measures. One concern raised by you against "FRC v1" was a copy of the LUKS volume key for the kdump kernel creates an attack vector. I took this feedback seriously and have sought advice from my colleagues to implement the countermeasures ([PATCH 1/5] and [Patch 4/5]).
Quoted 7 lines
Quoted 1 line
Yes, I appreciate that. And it is perfectly ok if your customers accept the trade-off and security risk of handling the key this way.
Anyway, I feel we are going in circles here, and as it seems to be my fault, I do not want to sound grumpy as I am perhaps missing some context.
Actually I should thank you for your patience! You have been always offering your feedback on this work kindly and promptly starting with the first proposed solution [1].
Quoted 4 lines
Could you please talk to internal RH cryptsetup maintainers first and discuss your solution? They know what we can do here can help to find an acceptable solution. (I added cc to Ondra.)
Sure, I'll talk to them first. Thanks for letting Ondra know!
Quoted 4 lines
Thanks,
Milan
Signature · 8 lines
Best regards, Coiby _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec