x86/mm/sme: fix the kdump kernel breakage on SME system when CONFIG_IMA_KEXEC=y
Subsystems (4)
PATCH 1/1 x86/mm/sme: fix the kdump kernel breakage on SME system when CONFIG_IMA_KEXEC=y
Recently, it's reported that kdump kernel is broken during bootup on SME system when CONFIG_IMA_KEXEC=y. When debugging, I noticed this can be traced back to commit ("b69a2afd5afc x86/kexec: Carry forward IMA measurement log on kexec"). Just nobody ever tested it on SME system when enabling CONFIG_IMA_KEXEC.
--------------------------------------------------
ima: No TPM chip found, activating TPM-bypass!
Loading compiled-in module X.509 certificates
Loaded X.509 cert 'Build time autogenerated kernel key: 18ae0bc7e79b64700122bb1d6a904b070fef2656'
ima: Allocated hash algorithm: sha256
Oops: general protection fault, probably for non-canonical address 0xcfacfdfe6660003e: 0000 [#1] PREEMPT SMP NOPTI CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.11.0-rc2+ #14 Hardware name: Dell Inc. PowerEdge R7425/02MJ3T, BIOS 1.20.0 05/03/2023 RIP: 0010:ima_restore_measurement_list+0xdc/0x420 Code: ff 48 c7 85 10 ff ff ff 00 00 00 00 48 c7 85 18 ff ff ff 00 00 00 00 48 85 f6 0f 84 09 03 00 00 48 83 fa 17 0f 86 ff 02 00 00 <66> 83 3e 01 49 89 f4 0f 85 90 94 7d 00 48 83 7e 10 ff 0f 84 74 94 RSP: 0018:ffffc90000053c80 EFLAGS: 00010286 RAX: 0000000000000000 RBX: ffffc90000053d03 RCX: 0000000000000000 RDX: e48066052d5df359 RSI: cfacfdfe6660003e RDI: cfacfdfe66600056 RBP: ffffc90000053d80 R08: 0000000000000000 R09: ffffffff82de1a88 R10: ffffc90000053da0 R11: 0000000000000003 R12: 00000000000001a4 R13: ffffc90000053df0 R14: 0000000000000000 R15: 0000000000000000 FS: 0000000000000000(0000) GS:ffff888040200000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f2c744050e8 CR3: 000080004110e000 CR4: 00000000003506b0 Call Trace: <TASK> ? show_trace_log_lvl+0x1b0/0x2f0 ? show_trace_log_lvl+0x1b0/0x2f0 ? ima_load_kexec_buffer+0x6e/0xf0 ? __die_body.cold+0x8/0x12 ? die_addr+0x3c/0x60 ? exc_general_protection+0x178/0x410 ? asm_exc_general_protection+0x26/0x30 ? ima_restore_measurement_list+0xdc/0x420 ? vprintk_emit+0x1f0/0x270 ? ima_load_kexec_buffer+0x6e/0xf0 ima_load_kexec_buffer+0x6e/0xf0 ima_init+0x52/0xb0 ? __pfx_init_ima+0x10/0x10 init_ima+0x26/0xc0 ? __pfx_init_ima+0x10/0x10 do_one_initcall+0x5b/0x300 do_initcalls+0xdf/0x100 ? __pfx_kernel_init+0x10/0x10 kernel_init_freeable+0x147/0x1a0 kernel_init+0x1a/0x140 ret_from_fork+0x34/0x50 ? __pfx_kernel_init+0x10/0x10 ret_from_fork_asm+0x1a/0x30 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:ima_restore_measurement_list+0xdc/0x420 Code: ff 48 c7 85 10 ff ff ff 00 00 00 00 48 c7 85 18 ff ff ff 00 00 00 00 48 85 f6 0f 84 09 03 00 00 48 83 fa 17 0f 86 ff 02 00 00 <66> 83 3e 01 49 89 f4 0f 85 90 94 7d 00 48 83 7e 10 ff 0f 84 74 94 RSP: 0018:ffffc90000053c80 EFLAGS: 00010286 RAX: 0000000000000000 RBX: ffffc90000053d03 RCX: 0000000000000000 RDX: e48066052d5df359 RSI: cfacfdfe6660003e RDI: cfacfdfe66600056 RBP: ffffc90000053d80 R08: 0000000000000000 R09: ffffffff82de1a88 R10: ffffc90000053da0 R11: 0000000000000003 R12: 00000000000001a4 R13: ffffc90000053df0 R14: 0000000000000000 R15: 0000000000000000 FS: 0000000000000000(0000) GS:ffff888040200000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f2c744050e8 CR3: 000080004110e000 CR4: 00000000003506b0 Kernel panic - not syncing: Fatal exception Kernel Offset: disabled Rebooting in 10 seconds..
From debugging printing, the stored addr and size of ima_kexec buffer are not decrypted correctly like:
------
ima: ima_load_kexec_buffer, buffer:0xcfacfdfe6660003e, size:0xe48066052d5df359
------
There are three pieces of setup_data info passed to kexec/kdump kernel:SETUP_EFI, SETUP_IMA and SETUP_RNG_SEED. However, among them, only ima_kexec buffer suffered from the incorrect decryption. After debugging, it's because of the code bug in early_memremap_is_setup_data() where checking the embedded content inside setup_data takes wrong range calculation.
The length of efi data, rng_seed and ima_kexec are 0x70, 0x20, 0x10, and the length of setup_data is 0x10. When checking if data is inside the embedded conent of setup_data, the starting address of efi data and rng_seed happened to land in the wrong calculated range. While the ima_kexec's starting address unluckily doesn't pass the checking, then error occurred.
Here fix the code bug to make kexec/kdump kernel boot up successfully.
--- arch/x86/mm/ioremap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/mm/ioremap.c +1 -1
@@ -717,7 +717,7 @@ static bool __init early_memremap_is_setup_data(resource_size_t phys_addr, paddr_next = data->next; len = data->len; -if ((phys_addr > paddr) && (phys_addr < (paddr + len))) { +if ((phys_addr > paddr) && (phys_addr < (paddr + size + len))) {early_memunmap (data,sizeof (*data));return true; }
Signature · 1 line
2.41.0
Quoted 88 lines · Baoquan He
Recently, it's reported that kdump kernel is broken during bootup on SME system when
CONFIG_IMA_KEXEC=y. When debugging, I noticed this can be traced back to commit ("b69a2afd5afcx86/kexec: Carry forward IMA measurement log on kexec"). Just nobody ever tested it on SME system when enablingCONFIG_IMA_KEXEC.--------------------------------------------------
ima: No TPM chip found, activating TPM-bypass!
Loading compiled-in module X.509 certificates
Loaded X.509 cert 'Build time autogenerated kernel key:18ae0bc7e79b64700122bb1d6a904b070fef2656'
ima: Allocated hash algorithm: sha256Oops: general protection fault, probably for non-canonical address 0xcfacfdfe6660003e: 0000 [#1] PREEMPT SMP NOPTI CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.11.0-rc2+ #14 Hardware name: Dell Inc. PowerEdge R7425/02MJ3T, BIOS 1.20.0 05/03/2023 RIP: 0010:ima_restore_measurement_list+0xdc/0x420 Code: ff 48 c7 85 10 ff ff ff 00 00 00 00 48 c7 85 18 ff ff ff 00 00 00 00 48 85 f6 0f 84 09 03 00 00 48 83 fa 17 0f 86 ff 02 00 00 <66> 83 3e 01 49 89 f4 0f 85 90 94 7d 00 48 83 7e 10 ff 0f 84 74 94 RSP: 0018:ffffc90000053c80 EFLAGS: 00010286 RAX: 0000000000000000 RBX: ffffc90000053d03 RCX: 0000000000000000 RDX: e48066052d5df359 RSI: cfacfdfe6660003e RDI: cfacfdfe66600056 RBP: ffffc90000053d80 R08: 0000000000000000 R09: ffffffff82de1a88 R10: ffffc90000053da0 R11: 0000000000000003 R12: 00000000000001a4 R13: ffffc90000053df0 R14: 0000000000000000 R15: 0000000000000000 FS: 0000000000000000(0000) GS:ffff888040200000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f2c744050e8 CR3: 000080004110e000 CR4: 00000000003506b0 Call Trace: <TASK> ? show_trace_log_lvl+0x1b0/0x2f0 ? show_trace_log_lvl+0x1b0/0x2f0 ? ima_load_kexec_buffer+0x6e/0xf0 ? __die_body.cold+0x8/0x12 ? die_addr+0x3c/0x60 ? exc_general_protection+0x178/0x410 ? asm_exc_general_protection+0x26/0x30 ? ima_restore_measurement_list+0xdc/0x420 ? vprintk_emit+0x1f0/0x270 ? ima_load_kexec_buffer+0x6e/0xf0 ima_load_kexec_buffer+0x6e/0xf0 ima_init+0x52/0xb0 ? __pfx_init_ima+0x10/0x10 init_ima+0x26/0xc0 ? __pfx_init_ima+0x10/0x10 do_one_initcall+0x5b/0x300 do_initcalls+0xdf/0x100 ? __pfx_kernel_init+0x10/0x10 kernel_init_freeable+0x147/0x1a0 kernel_init+0x1a/0x140 ret_from_fork+0x34/0x50 ? __pfx_kernel_init+0x10/0x10 ret_from_fork_asm+0x1a/0x30 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:ima_restore_measurement_list+0xdc/0x420 Code: ff 48 c7 85 10 ff ff ff 00 00 00 00 48 c7 85 18 ff ff ff 00 00 00 00 48 85 f6 0f 84 09 03 00 00 48 83 fa 17 0f 86 ff 02 00 00 <66> 83 3e 01 49 89 f4 0f 85 90 94 7d 00 48 83 7e 10 ff 0f 84 74 94 RSP: 0018:ffffc90000053c80 EFLAGS: 00010286 RAX: 0000000000000000 RBX: ffffc90000053d03 RCX: 0000000000000000 RDX: e48066052d5df359 RSI: cfacfdfe6660003e RDI: cfacfdfe66600056 RBP: ffffc90000053d80 R08: 0000000000000000 R09: ffffffff82de1a88 R10: ffffc90000053da0 R11: 0000000000000003 R12: 00000000000001a4 R13: ffffc90000053df0 R14: 0000000000000000 R15: 0000000000000000 FS: 0000000000000000(0000) GS:ffff888040200000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f2c744050e8 CR3: 000080004110e000 CR4: 00000000003506b0 Kernel panic - not syncing: Fatal exception Kernel Offset: disabled Rebooting in 10 seconds..From debugging printing, the stored addr and size of
ima_kexecbuffer are not decrypted correctly like:
------
ima:ima_load_kexec_buffer, buffer:0xcfacfdfe6660003e, size:0xe48066052d5df359
------There are three pieces of
setup_datainfo passed to kexec/kdump kernel:SETUP_EFI,SETUP_IMAandSETUP_RNG_SEED. However, among them, onlyima_kexecbuffer suffered from the incorrect decryption. After debugging, it's because of the code bug inearly_memremap_is_setup_data()where checking the embedded content insidesetup_datatakes wrong range calculation.The length of efi data,
rng_seedandima_kexecare0x70,0x20,0x10, and the length ofsetup_datais0x10. When checking if data is inside the embedded conent ofsetup_data, the starting address of efi data andrng_seedhappened to land in the wrong calculated range. While the ima_kexec's starting address unluckily doesn't pass the checking, then error occurred.
Quoted 3 lines
Here fix the code bug to make kexec/kdump kernel boot up successfully.
Fixes 8f716c9b5feb ("x86/mm: Add support to access boot related data in the clear")
The check that was modified was added by:
b3c72fc9a78e ("x86/boot: Introduce setup_indirect")The SETUP_INDIRECT patches seem to be the issue here.
Quoted 10 lines
Signed-off-by Baoquan He <[email protected]>--- arch/x86/mm/ioremap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/mm/ioremap.c +0
-0
arch/x86/mm/ioremap.c static bool __init early_memremap_is_setup_data(resource_size_t phys_addr, · line 720
Quoted 5 lines
arch/x86/mm/ioremap.c +1
-1@@ -717,7 +717,7 @@ static bool __init early_memremap_is_setup_data(resource_size_t phys_addr, paddr_next = data->next; len = data->len; -if ((phys_addr > paddr) && (phys_addr < (paddr + len))) { +if ((phys_addr > paddr) && (phys_addr < (paddr + size + len))) {
I don't think this is correct. You are adding the requested size to the length of the setup data element. The length is the true length of the setup data and should not be increased.
It looks like there were some major changes to this function to support SETUP_INDIRECT. Is the IMA log setup data marked SETUP_INDIRECT?
It might be helpful to instrument the code to see exactly what is happening during the execution of that function for the IMA log address.
Thanks,
Tom
Quoted 3 lines
arch/x86/mm/ioremap.c +0
-0early_memunmap (data,sizeof (*data));return true; }
Quoted 112 lines · Tom Lendacky
Quoted 88 lines · Baoquan He
Recently, it's reported that kdump kernel is broken during bootup on SME system when
CONFIG_IMA_KEXEC=y. When debugging, I noticed this can be traced back to commit ("b69a2afd5afcx86/kexec: Carry forward IMA measurement log on kexec"). Just nobody ever tested it on SME system when enablingCONFIG_IMA_KEXEC.--------------------------------------------------
ima: No TPM chip found, activating TPM-bypass!
Loading compiled-in module X.509 certificates
Loaded X.509 cert 'Build time autogenerated kernel key:18ae0bc7e79b64700122bb1d6a904b070fef2656'
ima: Allocated hash algorithm: sha256Oops: general protection fault, probably for non-canonical address 0xcfacfdfe6660003e: 0000 [#1] PREEMPT SMP NOPTI CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.11.0-rc2+ #14 Hardware name: Dell Inc. PowerEdge R7425/02MJ3T, BIOS 1.20.0 05/03/2023 RIP: 0010:ima_restore_measurement_list+0xdc/0x420 Code: ff 48 c7 85 10 ff ff ff 00 00 00 00 48 c7 85 18 ff ff ff 00 00 00 00 48 85 f6 0f 84 09 03 00 00 48 83 fa 17 0f 86 ff 02 00 00 <66> 83 3e 01 49 89 f4 0f 85 90 94 7d 00 48 83 7e 10 ff 0f 84 74 94 RSP: 0018:ffffc90000053c80 EFLAGS: 00010286 RAX: 0000000000000000 RBX: ffffc90000053d03 RCX: 0000000000000000 RDX: e48066052d5df359 RSI: cfacfdfe6660003e RDI: cfacfdfe66600056 RBP: ffffc90000053d80 R08: 0000000000000000 R09: ffffffff82de1a88 R10: ffffc90000053da0 R11: 0000000000000003 R12: 00000000000001a4 R13: ffffc90000053df0 R14: 0000000000000000 R15: 0000000000000000 FS: 0000000000000000(0000) GS:ffff888040200000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f2c744050e8 CR3: 000080004110e000 CR4: 00000000003506b0 Call Trace: <TASK> ? show_trace_log_lvl+0x1b0/0x2f0 ? show_trace_log_lvl+0x1b0/0x2f0 ? ima_load_kexec_buffer+0x6e/0xf0 ? __die_body.cold+0x8/0x12 ? die_addr+0x3c/0x60 ? exc_general_protection+0x178/0x410 ? asm_exc_general_protection+0x26/0x30 ? ima_restore_measurement_list+0xdc/0x420 ? vprintk_emit+0x1f0/0x270 ? ima_load_kexec_buffer+0x6e/0xf0 ima_load_kexec_buffer+0x6e/0xf0 ima_init+0x52/0xb0 ? __pfx_init_ima+0x10/0x10 init_ima+0x26/0xc0 ? __pfx_init_ima+0x10/0x10 do_one_initcall+0x5b/0x300 do_initcalls+0xdf/0x100 ? __pfx_kernel_init+0x10/0x10 kernel_init_freeable+0x147/0x1a0 kernel_init+0x1a/0x140 ret_from_fork+0x34/0x50 ? __pfx_kernel_init+0x10/0x10 ret_from_fork_asm+0x1a/0x30 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:ima_restore_measurement_list+0xdc/0x420 Code: ff 48 c7 85 10 ff ff ff 00 00 00 00 48 c7 85 18 ff ff ff 00 00 00 00 48 85 f6 0f 84 09 03 00 00 48 83 fa 17 0f 86 ff 02 00 00 <66> 83 3e 01 49 89 f4 0f 85 90 94 7d 00 48 83 7e 10 ff 0f 84 74 94 RSP: 0018:ffffc90000053c80 EFLAGS: 00010286 RAX: 0000000000000000 RBX: ffffc90000053d03 RCX: 0000000000000000 RDX: e48066052d5df359 RSI: cfacfdfe6660003e RDI: cfacfdfe66600056 RBP: ffffc90000053d80 R08: 0000000000000000 R09: ffffffff82de1a88 R10: ffffc90000053da0 R11: 0000000000000003 R12: 00000000000001a4 R13: ffffc90000053df0 R14: 0000000000000000 R15: 0000000000000000 FS: 0000000000000000(0000) GS:ffff888040200000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f2c744050e8 CR3: 000080004110e000 CR4: 00000000003506b0 Kernel panic - not syncing: Fatal exception Kernel Offset: disabled Rebooting in 10 seconds..From debugging printing, the stored addr and size of
ima_kexecbuffer are not decrypted correctly like:
------
ima:ima_load_kexec_buffer, buffer:0xcfacfdfe6660003e, size:0xe48066052d5df359
------There are three pieces of
setup_datainfo passed to kexec/kdump kernel:SETUP_EFI,SETUP_IMAandSETUP_RNG_SEED. However, among them, onlyima_kexecbuffer suffered from the incorrect decryption. After debugging, it's because of the code bug inearly_memremap_is_setup_data()where checking the embedded content insidesetup_datatakes wrong range calculation.The length of efi data,
rng_seedandima_kexecare0x70,0x20,0x10, and the length ofsetup_datais0x10. When checking if data is inside the embedded conent ofsetup_data, the starting address of efi data andrng_seedhappened to land in the wrong calculated range. While the ima_kexec's starting address unluckily doesn't pass the checking, then error occurred.Quoted 3 lines
Here fix the code bug to make kexec/kdump kernel boot up successfully.
Fixes 8f716c9b5feb ("x86/mm: Add support to access boot related data in the clear")The check that was modified was added by:
b3c72fc9a78e ("x86/boot: Introduce setup_indirect")The
SETUP_INDIRECTpatches seem to be the issue here.Quoted 13 lines
Signed-off-by Baoquan He <[email protected]>--- arch/x86/mm/ioremap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/mm/ioremap.c +0
-0@@ -717,7 +717,7 @@ static bool __init early_memremap_is_setup_data(resource_size_t phys_addr, paddr_next = data->next; len = data->len;
Quoted 6 lines
arch/x86/mm/ioremap.c static bool __init early_memremap_is_setup_data(resource_size_t phys_addr, · line 720
Quoted 2 lines
arch/x86/mm/ioremap.c +1
-1-if ((phys_addr > paddr) && (phys_addr < (paddr + len))) { +if ((phys_addr > paddr) && (phys_addr < (paddr + size + len))) {I don't think this is correct. You are adding the requested size to the length of the setup data element. The length is the true length of the setup data and should not be increased.
I think here size should be sizeof(struct setup_data) instead like below:
if ((phys_addr > paddr) && (phys_addr < (paddr + sizeof(struct
setup_data) + len)))
Baoquan, does the above work?
Quoted 14 lines
It looks like there were some major changes to this function to support
SETUP_INDIRECT. Is the IMA log setup data markedSETUP_INDIRECT?It might be helpful to instrument the code to see exactly what is happening during the execution of that function for the IMA log address.
Thanks,
TomQuoted 3 lines
arch/x86/mm/ioremap.c +0
-0early_memunmap (data,sizeof (*data));return true; }
Quoted 121 lines · Dave Young
Quoted 112 lines · Tom Lendacky
Quoted 88 lines · Baoquan He
Recently, it's reported that kdump kernel is broken during bootup on SME system when
CONFIG_IMA_KEXEC=y. When debugging, I noticed this can be traced back to commit ("b69a2afd5afcx86/kexec: Carry forward IMA measurement log on kexec"). Just nobody ever tested it on SME system when enablingCONFIG_IMA_KEXEC.--------------------------------------------------
ima: No TPM chip found, activating TPM-bypass!
Loading compiled-in module X.509 certificates
Loaded X.509 cert 'Build time autogenerated kernel key:18ae0bc7e79b64700122bb1d6a904b070fef2656'
ima: Allocated hash algorithm: sha256Oops: general protection fault, probably for non-canonical address 0xcfacfdfe6660003e: 0000 [#1] PREEMPT SMP NOPTI CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.11.0-rc2+ #14 Hardware name: Dell Inc. PowerEdge R7425/02MJ3T, BIOS 1.20.0 05/03/2023 RIP: 0010:ima_restore_measurement_list+0xdc/0x420 Code: ff 48 c7 85 10 ff ff ff 00 00 00 00 48 c7 85 18 ff ff ff 00 00 00 00 48 85 f6 0f 84 09 03 00 00 48 83 fa 17 0f 86 ff 02 00 00 <66> 83 3e 01 49 89 f4 0f 85 90 94 7d 00 48 83 7e 10 ff 0f 84 74 94 RSP: 0018:ffffc90000053c80 EFLAGS: 00010286 RAX: 0000000000000000 RBX: ffffc90000053d03 RCX: 0000000000000000 RDX: e48066052d5df359 RSI: cfacfdfe6660003e RDI: cfacfdfe66600056 RBP: ffffc90000053d80 R08: 0000000000000000 R09: ffffffff82de1a88 R10: ffffc90000053da0 R11: 0000000000000003 R12: 00000000000001a4 R13: ffffc90000053df0 R14: 0000000000000000 R15: 0000000000000000 FS: 0000000000000000(0000) GS:ffff888040200000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f2c744050e8 CR3: 000080004110e000 CR4: 00000000003506b0 Call Trace: <TASK> ? show_trace_log_lvl+0x1b0/0x2f0 ? show_trace_log_lvl+0x1b0/0x2f0 ? ima_load_kexec_buffer+0x6e/0xf0 ? __die_body.cold+0x8/0x12 ? die_addr+0x3c/0x60 ? exc_general_protection+0x178/0x410 ? asm_exc_general_protection+0x26/0x30 ? ima_restore_measurement_list+0xdc/0x420 ? vprintk_emit+0x1f0/0x270 ? ima_load_kexec_buffer+0x6e/0xf0 ima_load_kexec_buffer+0x6e/0xf0 ima_init+0x52/0xb0 ? __pfx_init_ima+0x10/0x10 init_ima+0x26/0xc0 ? __pfx_init_ima+0x10/0x10 do_one_initcall+0x5b/0x300 do_initcalls+0xdf/0x100 ? __pfx_kernel_init+0x10/0x10 kernel_init_freeable+0x147/0x1a0 kernel_init+0x1a/0x140 ret_from_fork+0x34/0x50 ? __pfx_kernel_init+0x10/0x10 ret_from_fork_asm+0x1a/0x30 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:ima_restore_measurement_list+0xdc/0x420 Code: ff 48 c7 85 10 ff ff ff 00 00 00 00 48 c7 85 18 ff ff ff 00 00 00 00 48 85 f6 0f 84 09 03 00 00 48 83 fa 17 0f 86 ff 02 00 00 <66> 83 3e 01 49 89 f4 0f 85 90 94 7d 00 48 83 7e 10 ff 0f 84 74 94 RSP: 0018:ffffc90000053c80 EFLAGS: 00010286 RAX: 0000000000000000 RBX: ffffc90000053d03 RCX: 0000000000000000 RDX: e48066052d5df359 RSI: cfacfdfe6660003e RDI: cfacfdfe66600056 RBP: ffffc90000053d80 R08: 0000000000000000 R09: ffffffff82de1a88 R10: ffffc90000053da0 R11: 0000000000000003 R12: 00000000000001a4 R13: ffffc90000053df0 R14: 0000000000000000 R15: 0000000000000000 FS: 0000000000000000(0000) GS:ffff888040200000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f2c744050e8 CR3: 000080004110e000 CR4: 00000000003506b0 Kernel panic - not syncing: Fatal exception Kernel Offset: disabled Rebooting in 10 seconds..From debugging printing, the stored addr and size of
ima_kexecbuffer are not decrypted correctly like:
------
ima:ima_load_kexec_buffer, buffer:0xcfacfdfe6660003e, size:0xe48066052d5df359
------There are three pieces of
setup_datainfo passed to kexec/kdump kernel:SETUP_EFI,SETUP_IMAandSETUP_RNG_SEED. However, among them, onlyima_kexecbuffer suffered from the incorrect decryption. After debugging, it's because of the code bug inearly_memremap_is_setup_data()where checking the embedded content insidesetup_datatakes wrong range calculation.The length of efi data,
rng_seedandima_kexecare0x70,0x20,0x10, and the length ofsetup_datais0x10. When checking if data is inside the embedded conent ofsetup_data, the starting address of efi data andrng_seedhappened to land in the wrong calculated range. While the ima_kexec's starting address unluckily doesn't pass the checking, then error occurred.Quoted 3 lines
Here fix the code bug to make kexec/kdump kernel boot up successfully.
Fixes 8f716c9b5feb ("x86/mm: Add support to access boot related data in the clear")The check that was modified was added by:
b3c72fc9a78e ("x86/boot: Introduce setup_indirect")The
SETUP_INDIRECTpatches seem to be the issue here.Quoted 13 lines
Signed-off-by Baoquan He <[email protected]>--- arch/x86/mm/ioremap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/mm/ioremap.c +0
-0@@ -717,7 +717,7 @@ static bool __init early_memremap_is_setup_data(resource_size_t phys_addr, paddr_next = data->next; len = data->len;Quoted 6 lines
arch/x86/mm/ioremap.c static bool __init early_memremap_is_setup_data(resource_size_t phys_addr, · line 720
Quoted 2 lines
arch/x86/mm/ioremap.c +1
-1-if ((phys_addr > paddr) && (phys_addr < (paddr + len))) { +if ((phys_addr > paddr) && (phys_addr < (paddr + size + len))) {I don't think this is correct. You are adding the requested size to the length of the setup data element. The length is the true length of the setup data and should not be increased.
Quoted 3 lines
I think here size should be
sizeof(struct setup_data)instead like below:if ((phys_addr > paddr) && (phys_addr < (paddr + sizeof(struct
setup_data) + len)))
Hmm, strictly it should be (webmail wrapped the line, please ignore that):
if ((phys_addr >= paddr) && (phys_addr < (paddr + sizeof(struct setup_data) + len)))
Quoted 16 lines
Baoquan, does the above work?
Quoted 14 lines
It looks like there were some major changes to this function to support
SETUP_INDIRECT. Is the IMA log setup data markedSETUP_INDIRECT?It might be helpful to instrument the code to see exactly what is happening during the execution of that function for the IMA log address.
Thanks,
TomQuoted 3 lines
arch/x86/mm/ioremap.c +0
-0early_memunmap (data,sizeof (*data));return true; }
Quoted 122 lines · Dave Young
Quoted 121 lines · Dave Young
Quoted 118 lines · Tom Lendacky
Quoted 88 lines · Baoquan He
Recently, it's reported that kdump kernel is broken during bootup on SME system when
CONFIG_IMA_KEXEC=y. When debugging, I noticed this can be traced back to commit ("b69a2afd5afcx86/kexec: Carry forward IMA measurement log on kexec"). Just nobody ever tested it on SME system when enablingCONFIG_IMA_KEXEC.--------------------------------------------------
ima: No TPM chip found, activating TPM-bypass!
Loading compiled-in module X.509 certificates
Loaded X.509 cert 'Build time autogenerated kernel key:18ae0bc7e79b64700122bb1d6a904b070fef2656'
ima: Allocated hash algorithm: sha256Oops: general protection fault, probably for non-canonical address 0xcfacfdfe6660003e: 0000 [#1] PREEMPT SMP NOPTI CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.11.0-rc2+ #14 Hardware name: Dell Inc. PowerEdge R7425/02MJ3T, BIOS 1.20.0 05/03/2023 RIP: 0010:ima_restore_measurement_list+0xdc/0x420 Code: ff 48 c7 85 10 ff ff ff 00 00 00 00 48 c7 85 18 ff ff ff 00 00 00 00 48 85 f6 0f 84 09 03 00 00 48 83 fa 17 0f 86 ff 02 00 00 <66> 83 3e 01 49 89 f4 0f 85 90 94 7d 00 48 83 7e 10 ff 0f 84 74 94 RSP: 0018:ffffc90000053c80 EFLAGS: 00010286 RAX: 0000000000000000 RBX: ffffc90000053d03 RCX: 0000000000000000 RDX: e48066052d5df359 RSI: cfacfdfe6660003e RDI: cfacfdfe66600056 RBP: ffffc90000053d80 R08: 0000000000000000 R09: ffffffff82de1a88 R10: ffffc90000053da0 R11: 0000000000000003 R12: 00000000000001a4 R13: ffffc90000053df0 R14: 0000000000000000 R15: 0000000000000000 FS: 0000000000000000(0000) GS:ffff888040200000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f2c744050e8 CR3: 000080004110e000 CR4: 00000000003506b0 Call Trace: <TASK> ? show_trace_log_lvl+0x1b0/0x2f0 ? show_trace_log_lvl+0x1b0/0x2f0 ? ima_load_kexec_buffer+0x6e/0xf0 ? __die_body.cold+0x8/0x12 ? die_addr+0x3c/0x60 ? exc_general_protection+0x178/0x410 ? asm_exc_general_protection+0x26/0x30 ? ima_restore_measurement_list+0xdc/0x420 ? vprintk_emit+0x1f0/0x270 ? ima_load_kexec_buffer+0x6e/0xf0 ima_load_kexec_buffer+0x6e/0xf0 ima_init+0x52/0xb0 ? __pfx_init_ima+0x10/0x10 init_ima+0x26/0xc0 ? __pfx_init_ima+0x10/0x10 do_one_initcall+0x5b/0x300 do_initcalls+0xdf/0x100 ? __pfx_kernel_init+0x10/0x10 kernel_init_freeable+0x147/0x1a0 kernel_init+0x1a/0x140 ret_from_fork+0x34/0x50 ? __pfx_kernel_init+0x10/0x10 ret_from_fork_asm+0x1a/0x30 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:ima_restore_measurement_list+0xdc/0x420 Code: ff 48 c7 85 10 ff ff ff 00 00 00 00 48 c7 85 18 ff ff ff 00 00 00 00 48 85 f6 0f 84 09 03 00 00 48 83 fa 17 0f 86 ff 02 00 00 <66> 83 3e 01 49 89 f4 0f 85 90 94 7d 00 48 83 7e 10 ff 0f 84 74 94 RSP: 0018:ffffc90000053c80 EFLAGS: 00010286 RAX: 0000000000000000 RBX: ffffc90000053d03 RCX: 0000000000000000 RDX: e48066052d5df359 RSI: cfacfdfe6660003e RDI: cfacfdfe66600056 RBP: ffffc90000053d80 R08: 0000000000000000 R09: ffffffff82de1a88 R10: ffffc90000053da0 R11: 0000000000000003 R12: 00000000000001a4 R13: ffffc90000053df0 R14: 0000000000000000 R15: 0000000000000000 FS: 0000000000000000(0000) GS:ffff888040200000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f2c744050e8 CR3: 000080004110e000 CR4: 00000000003506b0 Kernel panic - not syncing: Fatal exception Kernel Offset: disabled Rebooting in 10 seconds..From debugging printing, the stored addr and size of
ima_kexecbuffer are not decrypted correctly like:
------
ima:ima_load_kexec_buffer, buffer:0xcfacfdfe6660003e, size:0xe48066052d5df359
------There are three pieces of
setup_datainfo passed to kexec/kdump kernel:SETUP_EFI,SETUP_IMAandSETUP_RNG_SEED. However, among them, onlyima_kexecbuffer suffered from the incorrect decryption. After debugging, it's because of the code bug inearly_memremap_is_setup_data()where checking the embedded content insidesetup_datatakes wrong range calculation.The length of efi data,
rng_seedandima_kexecare0x70,0x20,0x10, and the length ofsetup_datais0x10. When checking if data is inside the embedded conent ofsetup_data, the starting address of efi data andrng_seedhappened to land in the wrong calculated range. While the ima_kexec's starting address unluckily doesn't pass the checking, then error occurred.Quoted 3 lines
Here fix the code bug to make kexec/kdump kernel boot up successfully.
Fixes 8f716c9b5feb ("x86/mm: Add support to access boot related data in the clear")The check that was modified was added by:
b3c72fc9a78e ("x86/boot: Introduce setup_indirect")The
SETUP_INDIRECTpatches seem to be the issue here.Quoted 10 lines
Signed-off-by Baoquan He <[email protected]>--- arch/x86/mm/ioremap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/mm/ioremap.c +0
-0arch/x86/mm/ioremap.c static bool __init early_memremap_is_setup_data(resource_size_t phys_addr, · line 720
Quoted 5 lines
arch/x86/mm/ioremap.c +1
-1@@ -717,7 +717,7 @@ static bool __init early_memremap_is_setup_data(resource_size_t phys_addr, paddr_next = data->next; len = data->len; -if ((phys_addr > paddr) && (phys_addr < (paddr + len))) { +if ((phys_addr > paddr) && (phys_addr < (paddr + size + len))) {I don't think this is correct. You are adding the requested size to the length of the setup data element. The length is the true length of the setup data and should not be increased.
Quoted 10 lines
Quoted 3 lines
I think here size should be
sizeof(struct setup_data)instead like below:if ((phys_addr > paddr) && (phys_addr < (paddr + sizeof(struct
setup_data) + len)))Hmm, strictly it should be (webmail wrapped the line, please ignore that):
if ((phys_addr>= paddr) && (phys_addr< (paddr +sizeof(struct setup_data)+ len)))Quoted 2 lines
Baoquan, does the above work?
Both of my change and above change work because they are almost equal. I changed like below at the very beginning, but using 'size' is simpler. Please see below comment.
static bool __init early_memremap_is_setup_data(resource_size_t phys_addr,
unsigned long size)
{
struct setup_indirect *indirect;
struct setup_data *data;
u64 paddr, paddr_next;
paddr = boot_params.hdr.setup_data;
while (paddr) {
......
size = sizeof(*data); // size = sizeof(stuct setup_data);
.......
}
...
}Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
It looks like there were some major changes to this function to support
SETUP_INDIRECT. Is the IMA log setup data markedSETUP_INDIRECT?It might be helpful to instrument the code to see exactly what is happening during the execution of that function for the IMA log address.
Thanks,
TomQuoted 3 lines
arch/x86/mm/ioremap.c +0
-0early_memunmap (data,sizeof (*data));return true; }
Quoted 89 lines · Tom Lendacky
Quoted 88 lines · Baoquan He
Recently, it's reported that kdump kernel is broken during bootup on SME system when
CONFIG_IMA_KEXEC=y. When debugging, I noticed this can be traced back to commit ("b69a2afd5afcx86/kexec: Carry forward IMA measurement log on kexec"). Just nobody ever tested it on SME system when enablingCONFIG_IMA_KEXEC.--------------------------------------------------
ima: No TPM chip found, activating TPM-bypass!
Loading compiled-in module X.509 certificates
Loaded X.509 cert 'Build time autogenerated kernel key:18ae0bc7e79b64700122bb1d6a904b070fef2656'
ima: Allocated hash algorithm: sha256Oops: general protection fault, probably for non-canonical address 0xcfacfdfe6660003e: 0000 [#1] PREEMPT SMP NOPTI CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.11.0-rc2+ #14 Hardware name: Dell Inc. PowerEdge R7425/02MJ3T, BIOS 1.20.0 05/03/2023 RIP: 0010:ima_restore_measurement_list+0xdc/0x420 Code: ff 48 c7 85 10 ff ff ff 00 00 00 00 48 c7 85 18 ff ff ff 00 00 00 00 48 85 f6 0f 84 09 03 00 00 48 83 fa 17 0f 86 ff 02 00 00 <66> 83 3e 01 49 89 f4 0f 85 90 94 7d 00 48 83 7e 10 ff 0f 84 74 94 RSP: 0018:ffffc90000053c80 EFLAGS: 00010286 RAX: 0000000000000000 RBX: ffffc90000053d03 RCX: 0000000000000000 RDX: e48066052d5df359 RSI: cfacfdfe6660003e RDI: cfacfdfe66600056 RBP: ffffc90000053d80 R08: 0000000000000000 R09: ffffffff82de1a88 R10: ffffc90000053da0 R11: 0000000000000003 R12: 00000000000001a4 R13: ffffc90000053df0 R14: 0000000000000000 R15: 0000000000000000 FS: 0000000000000000(0000) GS:ffff888040200000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f2c744050e8 CR3: 000080004110e000 CR4: 00000000003506b0 Call Trace: <TASK> ? show_trace_log_lvl+0x1b0/0x2f0 ? show_trace_log_lvl+0x1b0/0x2f0 ? ima_load_kexec_buffer+0x6e/0xf0 ? __die_body.cold+0x8/0x12 ? die_addr+0x3c/0x60 ? exc_general_protection+0x178/0x410 ? asm_exc_general_protection+0x26/0x30 ? ima_restore_measurement_list+0xdc/0x420 ? vprintk_emit+0x1f0/0x270 ? ima_load_kexec_buffer+0x6e/0xf0 ima_load_kexec_buffer+0x6e/0xf0 ima_init+0x52/0xb0 ? __pfx_init_ima+0x10/0x10 init_ima+0x26/0xc0 ? __pfx_init_ima+0x10/0x10 do_one_initcall+0x5b/0x300 do_initcalls+0xdf/0x100 ? __pfx_kernel_init+0x10/0x10 kernel_init_freeable+0x147/0x1a0 kernel_init+0x1a/0x140 ret_from_fork+0x34/0x50 ? __pfx_kernel_init+0x10/0x10 ret_from_fork_asm+0x1a/0x30 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:ima_restore_measurement_list+0xdc/0x420 Code: ff 48 c7 85 10 ff ff ff 00 00 00 00 48 c7 85 18 ff ff ff 00 00 00 00 48 85 f6 0f 84 09 03 00 00 48 83 fa 17 0f 86 ff 02 00 00 <66> 83 3e 01 49 89 f4 0f 85 90 94 7d 00 48 83 7e 10 ff 0f 84 74 94 RSP: 0018:ffffc90000053c80 EFLAGS: 00010286 RAX: 0000000000000000 RBX: ffffc90000053d03 RCX: 0000000000000000 RDX: e48066052d5df359 RSI: cfacfdfe6660003e RDI: cfacfdfe66600056 RBP: ffffc90000053d80 R08: 0000000000000000 R09: ffffffff82de1a88 R10: ffffc90000053da0 R11: 0000000000000003 R12: 00000000000001a4 R13: ffffc90000053df0 R14: 0000000000000000 R15: 0000000000000000 FS: 0000000000000000(0000) GS:ffff888040200000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f2c744050e8 CR3: 000080004110e000 CR4: 00000000003506b0 Kernel panic - not syncing: Fatal exception Kernel Offset: disabled Rebooting in 10 seconds..From debugging printing, the stored addr and size of
ima_kexecbuffer are not decrypted correctly like:
------
ima:ima_load_kexec_buffer, buffer:0xcfacfdfe6660003e, size:0xe48066052d5df359
------There are three pieces of
setup_datainfo passed to kexec/kdump kernel:SETUP_EFI,SETUP_IMAandSETUP_RNG_SEED. However, among them, onlyima_kexecbuffer suffered from the incorrect decryption. After debugging, it's because of the code bug inearly_memremap_is_setup_data()where checking the embedded content insidesetup_datatakes wrong range calculation.The length of efi data,
rng_seedandima_kexecare0x70,0x20,0x10, and the length ofsetup_datais0x10. When checking if data is inside the embedded conent ofsetup_data, the starting address of efi data andrng_seedhappened to land in the wrong calculated range. While the ima_kexec's starting address unluckily doesn't pass the checking, then error occurred.
Quoted 8 lines
Quoted 3 lines
Here fix the code bug to make kexec/kdump kernel boot up successfully.
Fixes 8f716c9b5feb ("x86/mm: Add support to access boot related data in the clear")The check that was modified was added by:
b3c72fc9a78e ("x86/boot: Introduce setup_indirect")The
SETUP_INDIRECTpatches seem to be the issue here.
Hmm, I didn't check it carefully, thanks for addding this info. While after checking commit b3c72fc9a78e, I feel the adding code was trying to fix your original early_memremap_is_setup_data(). Even though SETUP_INDIRECT type of setup_data has been added, the original early_memremap_is_setup_data() only check the starting address and the content of struct setup_data, that's obviously wrong.
arch/x86/include/uapi/asm/setup_data.h:
/* extensible setup data list node */
struct setup_data {
__u64 next;
__u32 type;
__u32 len;
__u8 data[];
};As you can see, the zero-length will embed the carried data which is actually expected and adjacent to its carrier, the struct setup_data.
Quoted 14 lines
Quoted 14 lines
Signed-off-by Baoquan He <[email protected]>--- arch/x86/mm/ioremap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/mm/ioremap.c +0
-0@@ -717,7 +717,7 @@ static bool __init early_memremap_is_setup_data(resource_size_t phys_addr, paddr_next = data->next; len = data->len;
Quoted 6 lines
arch/x86/mm/ioremap.c static bool __init early_memremap_is_setup_data(resource_size_t phys_addr, · line 720
Quoted 2 lines
arch/x86/mm/ioremap.c +1
-1-if ((phys_addr > paddr) && (phys_addr < (paddr + len))) { +if ((phys_addr > paddr) && (phys_addr < (paddr + size + len))) {I don't think this is correct. You are adding the requested size to the length of the setup data element. The length is the true length of the setup data and should not be increased.
Please see the inline comment among code lines.
static bool __init early_memremap_is_setup_data(resource_size_t phys_addr,
unsigned long size)
{
struct setup_indirect *indirect;
struct setup_data *data;
u64 paddr, paddr_next;
paddr = boot_params.hdr.setup_data; //paddr point at struct steup_data;
while (paddr) {
unsigned int len, size;
if (phys_addr == paddr) // check the starting addr of setup_data
return true;
data = early_memremap_decrypted(paddr, sizeof(*data));
if (!data) {
pr_warn("failed to early memremap setup_data entry\n");
return false;
}
size = sizeof(*data); //size is the length of struct setup_data
paddr_next = data->next;
len = data->len; // len is the length of carried data,
//e.g sizeof(ima_setup_data) if ima_kexec buffer
// or sizeof(struct setup_indirect) if
// it's SETUP_INDIRECT type. Note that SETUP_INDIRECT
//data is also setup_data info even
//though it's intermideate info.
//Here I check if phys_addr is inside (paddr, paddr + sizeof(struct setup_data) + len)
//means it check if phys_addr is inside struct
//setup_data or struct ima_setup_data if ima_kexec case.
if ((phys_addr > paddr) && (phys_addr < (paddr + size + len))) {
early_memunmap(data, sizeof(*data));
return true;
}
if (data->type == SETUP_INDIRECT) {
......
if (indirect->type != SETUP_INDIRECT) {
paddr = indirect->addr;
len = indirect->len;
}
// it's checking the indirect dat, and the paddr
// is adjusted here. Wondering if indirect data
//can be nested, e.g
//setup_data->indirect->indirect->acutal data
}
...
}
...
}Quoted 3 lines
It looks like there were some major changes to this function to support
SETUP_INDIRECT. Is the IMA log setup data markedSETUP_INDIRECT?
No, ima_kexec buffer is marked as SETUP_IMA, it's not indirect data.
arch/x86/kernel/kexec-bzimage64.c:bzImage64_load()
->setup_boot_parameters()
->setup_ima_state()Quoted 3 lines
It might be helpful to instrument the code to see exactly what is happening during the execution of that function for the IMA log address.
I almost have printed all needed information because kexec/kdump passed three types of setup_data, but only ima_kexec buffer is not got right. The behaviour is very bizarre at the beginning.
Quoted 16 lines · Baoquan He
Quoted 15 lines · Tom Lendacky
Quoted 10 lines · Baoquan He
Recently, it's reported that kdump kernel is broken during bootup on SME system when
CONFIG_IMA_KEXEC=y. When debugging, I noticed this can be traced back to commit ("b69a2afd5afcx86/kexec: Carry forward IMA measurement log on kexec"). Just nobody ever tested it on SME system when enablingCONFIG_IMA_KEXEC.Here fix the code bug to make kexec/kdump kernel boot up successfully.
Fixes 8f716c9b5feb ("x86/mm: Add support to access boot related data in the clear")The check that was modified was added by:
b3c72fc9a78e ("x86/boot: Introduce setup_indirect")
Quoted 8 lines
Quoted 1 line
The
SETUP_INDIRECTpatches seem to be the issue here.Hmm, I didn't check it carefully, thanks for addding this info. While after checking commit
b3c72fc9a78e, I feel the adding code was trying to fix your originalearly_memremap_is_setup_data(). Even thoughSETUP_INDIRECTtype ofsetup_datahas been added, the originalearly_memremap_is_setup_data()only check the starting address and the content of structsetup_data, that's obviously wrong.
IIRC, when this function was created, the value of "len" in setup_data included the length of "data", so the calculation was correct. Everything was contiguous in a setup_data element.
Quoted 10 lines
arch/x86/include/uapi/asm/setup_data.h:
/* extensible setup data list node */struct setup_data { __u64 next; __u32 type; __u32 len; __u8 data[]; };
Quoted 2 lines
As you can see, the zero-length will embed the carried data which is actually expected and adjacent to its carrier, the struct
setup_data.
Right, and "len" is the length of that data. So paddr + len goes to the end of the overall setup_data.
Thanks,
Tom
Quoted 2 lines
Quoted 2 lines
Quoted 40 lines · Tom Lendacky
Quoted 16 lines · Baoquan He
Quoted 15 lines · Tom Lendacky
Quoted 10 lines · Baoquan He
Recently, it's reported that kdump kernel is broken during bootup on SME system when
CONFIG_IMA_KEXEC=y. When debugging, I noticed this can be traced back to commit ("b69a2afd5afcx86/kexec: Carry forward IMA measurement log on kexec"). Just nobody ever tested it on SME system when enablingCONFIG_IMA_KEXEC.Here fix the code bug to make kexec/kdump kernel boot up successfully.
Fixes 8f716c9b5feb ("x86/mm: Add support to access boot related data in the clear")The check that was modified was added by:
b3c72fc9a78e ("x86/boot: Introduce setup_indirect")Quoted 8 lines
Quoted 1 line
The
SETUP_INDIRECTpatches seem to be the issue here.Hmm, I didn't check it carefully, thanks for addding this info. While after checking commit
b3c72fc9a78e, I feel the adding code was trying to fix your originalearly_memremap_is_setup_data(). Even thoughSETUP_INDIRECTtype ofsetup_datahas been added, the originalearly_memremap_is_setup_data()only check the starting address and the content of structsetup_data, that's obviously wrong.IIRC, when this function was created, the value of "len" in
setup_dataincluded the length of "data", so the calculation was correct. Everything was contiguous in asetup_dataelement.Quoted 10 lines
arch/x86/include/uapi/asm/setup_data.h:
/* extensible setup data list node */struct setup_data { __u64 next; __u32 type; __u32 len; __u8 data[]; };
Quoted 5 lines
Quoted 2 lines
As you can see, the zero-length will embed the carried data which is actually expected and adjacent to its carrier, the struct
setup_data.Right, and "len" is the length of that data. So paddr + len goes to the end of the overall
setup_data.
Ah, I see what you're saying. "len" doesn't include the size of the setup_data structure, only the data. If so, then, yes, adding a sizeof() to the calculation in the if statement is correct.
Thanks,
Tom
Quoted 6 lines
Thanks,
TomQuoted 2 lines
Quoted 2 lines
Quoted 44 lines · Tom Lendacky
Quoted 43 lines · Tom Lendacky
Quoted 16 lines · Baoquan He
Quoted 15 lines · Tom Lendacky
Quoted 10 lines · Baoquan He
Recently, it's reported that kdump kernel is broken during bootup on SME system when
CONFIG_IMA_KEXEC=y. When debugging, I noticed this can be traced back to commit ("b69a2afd5afcx86/kexec: Carry forward IMA measurement log on kexec"). Just nobody ever tested it on SME system when enablingCONFIG_IMA_KEXEC.Here fix the code bug to make kexec/kdump kernel boot up successfully.
Fixes 8f716c9b5feb ("x86/mm: Add support to access boot related data in the clear")The check that was modified was added by:
b3c72fc9a78e ("x86/boot: Introduce setup_indirect")Quoted 8 lines
Quoted 1 line
The
SETUP_INDIRECTpatches seem to be the issue here.Hmm, I didn't check it carefully, thanks for addding this info. While after checking commit
b3c72fc9a78e, I feel the adding code was trying to fix your originalearly_memremap_is_setup_data(). Even thoughSETUP_INDIRECTtype ofsetup_datahas been added, the originalearly_memremap_is_setup_data()only check the starting address and the content of structsetup_data, that's obviously wrong.IIRC, when this function was created, the value of "len" in
setup_dataincluded the length of "data", so the calculation was correct. Everything was contiguous in asetup_dataelement.Quoted 12 lines
arch/x86/include/uapi/asm/setup_data.h:
/* extensible setup data list node */struct setup_data { __u64 next; __u32 type; __u32 len; __u8 data[]; };As you can see, the zero-length will embed the carried data which is actually expected and adjacent to its carrier, the struct
setup_data.
Quoted 6 lines
Quoted 2 lines
Right, and "len" is the length of that data. So paddr + len goes to the end of the overall
setup_data.Ah, I see what you're saying. "len" doesn't include the size of the
setup_datastructure, only the data. If so, then, yes, adding asizeof()to the calculation in the if statement is correct.
Exactly. That could confuse people sometime.
Quoted 111 lines · Tom Lendacky
Quoted 88 lines · Baoquan He
Recently, it's reported that kdump kernel is broken during bootup on SME system when
CONFIG_IMA_KEXEC=y. When debugging, I noticed this can be traced back to commit ("b69a2afd5afcx86/kexec: Carry forward IMA measurement log on kexec"). Just nobody ever tested it on SME system when enablingCONFIG_IMA_KEXEC.--------------------------------------------------
ima: No TPM chip found, activating TPM-bypass!
Loading compiled-in module X.509 certificates
Loaded X.509 cert 'Build time autogenerated kernel key:18ae0bc7e79b64700122bb1d6a904b070fef2656'
ima: Allocated hash algorithm: sha256Oops: general protection fault, probably for non-canonical address 0xcfacfdfe6660003e: 0000 [#1] PREEMPT SMP NOPTI CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.11.0-rc2+ #14 Hardware name: Dell Inc. PowerEdge R7425/02MJ3T, BIOS 1.20.0 05/03/2023 RIP: 0010:ima_restore_measurement_list+0xdc/0x420 Code: ff 48 c7 85 10 ff ff ff 00 00 00 00 48 c7 85 18 ff ff ff 00 00 00 00 48 85 f6 0f 84 09 03 00 00 48 83 fa 17 0f 86 ff 02 00 00 <66> 83 3e 01 49 89 f4 0f 85 90 94 7d 00 48 83 7e 10 ff 0f 84 74 94 RSP: 0018:ffffc90000053c80 EFLAGS: 00010286 RAX: 0000000000000000 RBX: ffffc90000053d03 RCX: 0000000000000000 RDX: e48066052d5df359 RSI: cfacfdfe6660003e RDI: cfacfdfe66600056 RBP: ffffc90000053d80 R08: 0000000000000000 R09: ffffffff82de1a88 R10: ffffc90000053da0 R11: 0000000000000003 R12: 00000000000001a4 R13: ffffc90000053df0 R14: 0000000000000000 R15: 0000000000000000 FS: 0000000000000000(0000) GS:ffff888040200000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f2c744050e8 CR3: 000080004110e000 CR4: 00000000003506b0 Call Trace: <TASK> ? show_trace_log_lvl+0x1b0/0x2f0 ? show_trace_log_lvl+0x1b0/0x2f0 ? ima_load_kexec_buffer+0x6e/0xf0 ? __die_body.cold+0x8/0x12 ? die_addr+0x3c/0x60 ? exc_general_protection+0x178/0x410 ? asm_exc_general_protection+0x26/0x30 ? ima_restore_measurement_list+0xdc/0x420 ? vprintk_emit+0x1f0/0x270 ? ima_load_kexec_buffer+0x6e/0xf0 ima_load_kexec_buffer+0x6e/0xf0 ima_init+0x52/0xb0 ? __pfx_init_ima+0x10/0x10 init_ima+0x26/0xc0 ? __pfx_init_ima+0x10/0x10 do_one_initcall+0x5b/0x300 do_initcalls+0xdf/0x100 ? __pfx_kernel_init+0x10/0x10 kernel_init_freeable+0x147/0x1a0 kernel_init+0x1a/0x140 ret_from_fork+0x34/0x50 ? __pfx_kernel_init+0x10/0x10 ret_from_fork_asm+0x1a/0x30 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:ima_restore_measurement_list+0xdc/0x420 Code: ff 48 c7 85 10 ff ff ff 00 00 00 00 48 c7 85 18 ff ff ff 00 00 00 00 48 85 f6 0f 84 09 03 00 00 48 83 fa 17 0f 86 ff 02 00 00 <66> 83 3e 01 49 89 f4 0f 85 90 94 7d 00 48 83 7e 10 ff 0f 84 74 94 RSP: 0018:ffffc90000053c80 EFLAGS: 00010286 RAX: 0000000000000000 RBX: ffffc90000053d03 RCX: 0000000000000000 RDX: e48066052d5df359 RSI: cfacfdfe6660003e RDI: cfacfdfe66600056 RBP: ffffc90000053d80 R08: 0000000000000000 R09: ffffffff82de1a88 R10: ffffc90000053da0 R11: 0000000000000003 R12: 00000000000001a4 R13: ffffc90000053df0 R14: 0000000000000000 R15: 0000000000000000 FS: 0000000000000000(0000) GS:ffff888040200000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f2c744050e8 CR3: 000080004110e000 CR4: 00000000003506b0 Kernel panic - not syncing: Fatal exception Kernel Offset: disabled Rebooting in 10 seconds..From debugging printing, the stored addr and size of
ima_kexecbuffer are not decrypted correctly like:
------
ima:ima_load_kexec_buffer, buffer:0xcfacfdfe6660003e, size:0xe48066052d5df359
------There are three pieces of
setup_datainfo passed to kexec/kdump kernel:SETUP_EFI,SETUP_IMAandSETUP_RNG_SEED. However, among them, onlyima_kexecbuffer suffered from the incorrect decryption. After debugging, it's because of the code bug inearly_memremap_is_setup_data()where checking the embedded content insidesetup_datatakes wrong range calculation.The length of efi data,
rng_seedandima_kexecare0x70,0x20,0x10, and the length ofsetup_datais0x10. When checking if data is inside the embedded conent ofsetup_data, the starting address of efi data andrng_seedhappened to land in the wrong calculated range. While the ima_kexec's starting address unluckily doesn't pass the checking, then error occurred.Quoted 3 lines
Here fix the code bug to make kexec/kdump kernel boot up successfully.
Fixes 8f716c9b5feb ("x86/mm: Add support to access boot related data in the clear")The check that was modified was added by:
b3c72fc9a78e ("x86/boot: Introduce setup_indirect")The
SETUP_INDIRECTpatches seem to be the issue here.Quoted 13 lines
Signed-off-by Baoquan He <[email protected]>--- arch/x86/mm/ioremap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/mm/ioremap.c +0
-0@@ -717,7 +717,7 @@ static bool __init early_memremap_is_setup_data(resource_size_t phys_addr, paddr_next = data->next; len = data->len;
Quoted 6 lines
arch/x86/mm/ioremap.c static bool __init early_memremap_is_setup_data(resource_size_t phys_addr, · line 720
Quoted 2 lines
arch/x86/mm/ioremap.c +1
-1-if ((phys_addr > paddr) && (phys_addr < (paddr + len))) { +if ((phys_addr > paddr) && (phys_addr < (paddr + size + len))) {I don't think this is correct. You are adding the requested size to the length of the setup data element. The length is the true length of the setup data and should not be increased.
I talked to Dave, he reminded me that people could mix the passed in parameter 'size' and the local variable 'size' defined inside the while loop, not sure which 'size' you are referring to.
Quoted 120 lines · Baoquan He
Quoted 111 lines · Tom Lendacky
Quoted 88 lines · Baoquan He
Recently, it's reported that kdump kernel is broken during bootup on SME system when
CONFIG_IMA_KEXEC=y. When debugging, I noticed this can be traced back to commit ("b69a2afd5afcx86/kexec: Carry forward IMA measurement log on kexec"). Just nobody ever tested it on SME system when enablingCONFIG_IMA_KEXEC.--------------------------------------------------
ima: No TPM chip found, activating TPM-bypass!
Loading compiled-in module X.509 certificates
Loaded X.509 cert 'Build time autogenerated kernel key:18ae0bc7e79b64700122bb1d6a904b070fef2656'
ima: Allocated hash algorithm: sha256Oops: general protection fault, probably for non-canonical address 0xcfacfdfe6660003e: 0000 [#1] PREEMPT SMP NOPTI CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.11.0-rc2+ #14 Hardware name: Dell Inc. PowerEdge R7425/02MJ3T, BIOS 1.20.0 05/03/2023 RIP: 0010:ima_restore_measurement_list+0xdc/0x420 Code: ff 48 c7 85 10 ff ff ff 00 00 00 00 48 c7 85 18 ff ff ff 00 00 00 00 48 85 f6 0f 84 09 03 00 00 48 83 fa 17 0f 86 ff 02 00 00 <66> 83 3e 01 49 89 f4 0f 85 90 94 7d 00 48 83 7e 10 ff 0f 84 74 94 RSP: 0018:ffffc90000053c80 EFLAGS: 00010286 RAX: 0000000000000000 RBX: ffffc90000053d03 RCX: 0000000000000000 RDX: e48066052d5df359 RSI: cfacfdfe6660003e RDI: cfacfdfe66600056 RBP: ffffc90000053d80 R08: 0000000000000000 R09: ffffffff82de1a88 R10: ffffc90000053da0 R11: 0000000000000003 R12: 00000000000001a4 R13: ffffc90000053df0 R14: 0000000000000000 R15: 0000000000000000 FS: 0000000000000000(0000) GS:ffff888040200000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f2c744050e8 CR3: 000080004110e000 CR4: 00000000003506b0 Call Trace: <TASK> ? show_trace_log_lvl+0x1b0/0x2f0 ? show_trace_log_lvl+0x1b0/0x2f0 ? ima_load_kexec_buffer+0x6e/0xf0 ? __die_body.cold+0x8/0x12 ? die_addr+0x3c/0x60 ? exc_general_protection+0x178/0x410 ? asm_exc_general_protection+0x26/0x30 ? ima_restore_measurement_list+0xdc/0x420 ? vprintk_emit+0x1f0/0x270 ? ima_load_kexec_buffer+0x6e/0xf0 ima_load_kexec_buffer+0x6e/0xf0 ima_init+0x52/0xb0 ? __pfx_init_ima+0x10/0x10 init_ima+0x26/0xc0 ? __pfx_init_ima+0x10/0x10 do_one_initcall+0x5b/0x300 do_initcalls+0xdf/0x100 ? __pfx_kernel_init+0x10/0x10 kernel_init_freeable+0x147/0x1a0 kernel_init+0x1a/0x140 ret_from_fork+0x34/0x50 ? __pfx_kernel_init+0x10/0x10 ret_from_fork_asm+0x1a/0x30 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:ima_restore_measurement_list+0xdc/0x420 Code: ff 48 c7 85 10 ff ff ff 00 00 00 00 48 c7 85 18 ff ff ff 00 00 00 00 48 85 f6 0f 84 09 03 00 00 48 83 fa 17 0f 86 ff 02 00 00 <66> 83 3e 01 49 89 f4 0f 85 90 94 7d 00 48 83 7e 10 ff 0f 84 74 94 RSP: 0018:ffffc90000053c80 EFLAGS: 00010286 RAX: 0000000000000000 RBX: ffffc90000053d03 RCX: 0000000000000000 RDX: e48066052d5df359 RSI: cfacfdfe6660003e RDI: cfacfdfe66600056 RBP: ffffc90000053d80 R08: 0000000000000000 R09: ffffffff82de1a88 R10: ffffc90000053da0 R11: 0000000000000003 R12: 00000000000001a4 R13: ffffc90000053df0 R14: 0000000000000000 R15: 0000000000000000 FS: 0000000000000000(0000) GS:ffff888040200000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f2c744050e8 CR3: 000080004110e000 CR4: 00000000003506b0 Kernel panic - not syncing: Fatal exception Kernel Offset: disabled Rebooting in 10 seconds..From debugging printing, the stored addr and size of
ima_kexecbuffer are not decrypted correctly like:
------
ima:ima_load_kexec_buffer, buffer:0xcfacfdfe6660003e, size:0xe48066052d5df359
------There are three pieces of
setup_datainfo passed to kexec/kdump kernel:SETUP_EFI,SETUP_IMAandSETUP_RNG_SEED. However, among them, onlyima_kexecbuffer suffered from the incorrect decryption. After debugging, it's because of the code bug inearly_memremap_is_setup_data()where checking the embedded content insidesetup_datatakes wrong range calculation.The length of efi data,
rng_seedandima_kexecare0x70,0x20,0x10, and the length ofsetup_datais0x10. When checking if data is inside the embedded conent ofsetup_data, the starting address of efi data andrng_seedhappened to land in the wrong calculated range. While the ima_kexec's starting address unluckily doesn't pass the checking, then error occurred.Quoted 3 lines
Here fix the code bug to make kexec/kdump kernel boot up successfully.
Fixes 8f716c9b5feb ("x86/mm: Add support to access boot related data in the clear")The check that was modified was added by:
b3c72fc9a78e ("x86/boot: Introduce setup_indirect")The
SETUP_INDIRECTpatches seem to be the issue here.Quoted 13 lines
Signed-off-by Baoquan He <[email protected]>--- arch/x86/mm/ioremap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/mm/ioremap.c +0
-0@@ -717,7 +717,7 @@ static bool __init early_memremap_is_setup_data(resource_size_t phys_addr, paddr_next = data->next; len = data->len;Quoted 6 lines
arch/x86/mm/ioremap.c static bool __init early_memremap_is_setup_data(resource_size_t phys_addr, · line 720
Quoted 2 lines
arch/x86/mm/ioremap.c +1
-1-if ((phys_addr > paddr) && (phys_addr < (paddr + len))) { +if ((phys_addr > paddr) && (phys_addr < (paddr + size + len))) {I don't think this is correct. You are adding the requested size to the length of the setup data element. The length is the true length of the setup data and should not be increased.
Quoted 4 lines
I talked to Dave, he reminded me that people could mix the passed in parameter 'size' and the local variable 'size' defined inside the while loop, not sure which 'size' you are referring to.
Baoquan, you are right, but I think I mistakenly read the code in memremap_is_setup_data instead of early_memremap_is_setup_data. You can check the memremap_is_setup_data, no "size = sizeof (*data)", so these two functions could both need fixes.
Otherwise it would be better to change the function internal variable name, it could cause confusion even if the actual result is correct.
Thanks
Dave
Quoted 4 lines · Dave Young
Quoted 3 lines · Baoquan He
Quoted 1 line · Tom Lendacky
On 8/25/24 21:44, Baoquan He wrote:
......
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 9 lines
--- arch/x86/mm/ioremap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/mm/ioremap.c +0
-0arch/x86/mm/ioremap.c static bool __init early_memremap_is_setup_data(resource_size_t phys_addr, · line 720
Quoted 5 lines
arch/x86/mm/ioremap.c +1
-1@@ -717,7 +717,7 @@ static bool __init early_memremap_is_setup_data(resource_size_t phys_addr, paddr_next = data->next; len = data->len; -if ((phys_addr > paddr) && (phys_addr < (paddr + len))) { +if ((phys_addr > paddr) && (phys_addr < (paddr + size + len))) {I don't think this is correct. You are adding the requested size to the length of the setup data element. The length is the true length of the setup data and should not be increased.
Quoted 8 lines
Quoted 4 lines
I talked to Dave, he reminded me that people could mix the passed in parameter 'size' and the local variable 'size' defined inside the while loop, not sure which 'size' you are referring to.
Baoquan, you are right, but I think I mistakenly read the code in
memremap_is_setup_datainstead ofearly_memremap_is_setup_data. You can check thememremap_is_setup_data, no "size = sizeof (*data)", so these two functions could both need fixes.
Agree, memremap_is_setup_data() has the same drawback in code.
Quoted 3 lines
Otherwise it would be better to change the function internal variable name, it could cause confusion even if the actual result is correct.
Ok, will consider to change when spinning v2.
Quoted 12 lines · Dave Young
Quoted 11 lines · Baoquan He
Quoted 7 lines · Tom Lendacky
Quoted 6 lines · Baoquan He
Recently, it's reported that kdump kernel is broken during bootup on SME system when
CONFIG_IMA_KEXEC=y. When debugging, I noticed this can be traced back to commit ("b69a2afd5afcx86/kexec: Carry forward IMA measurement log on kexec"). Just nobody ever tested it on SME system when enablingCONFIG_IMA_KEXEC.
Quoted 6 lines
Quoted 4 lines
I talked to Dave, he reminded me that people could mix the passed in parameter 'size' and the local variable 'size' defined inside the while loop, not sure which 'size' you are referring to.
Baoquan, you are right, but I think I mistakenly read the code in
memremap_is_setup_datainstead ofearly_memremap_is_setup_data. You
Ditto.
Quoted 5 lines
can check the
memremap_is_setup_data, no "size = sizeof (*data)", so these two functions could both need fixes.Otherwise it would be better to change the function internal variable name, it could cause confusion even if the actual result is correct.
Yes, the use of size as a local variable while being passed in as a parameter is very confusing.
Thanks,
Tom
Quoted 4 lines
Thanks
Dave
Quoted 112 lines · Tom Lendacky
Quoted 88 lines · Baoquan He
Recently, it's reported that kdump kernel is broken during bootup on SME system when
CONFIG_IMA_KEXEC=y. When debugging, I noticed this can be traced back to commit ("b69a2afd5afcx86/kexec: Carry forward IMA measurement log on kexec"). Just nobody ever tested it on SME system when enablingCONFIG_IMA_KEXEC.--------------------------------------------------
ima: No TPM chip found, activating TPM-bypass!
Loading compiled-in module X.509 certificates
Loaded X.509 cert 'Build time autogenerated kernel key:18ae0bc7e79b64700122bb1d6a904b070fef2656'
ima: Allocated hash algorithm: sha256Oops: general protection fault, probably for non-canonical address 0xcfacfdfe6660003e: 0000 [#1] PREEMPT SMP NOPTI CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.11.0-rc2+ #14 Hardware name: Dell Inc. PowerEdge R7425/02MJ3T, BIOS 1.20.0 05/03/2023 RIP: 0010:ima_restore_measurement_list+0xdc/0x420 Code: ff 48 c7 85 10 ff ff ff 00 00 00 00 48 c7 85 18 ff ff ff 00 00 00 00 48 85 f6 0f 84 09 03 00 00 48 83 fa 17 0f 86 ff 02 00 00 <66> 83 3e 01 49 89 f4 0f 85 90 94 7d 00 48 83 7e 10 ff 0f 84 74 94 RSP: 0018:ffffc90000053c80 EFLAGS: 00010286 RAX: 0000000000000000 RBX: ffffc90000053d03 RCX: 0000000000000000 RDX: e48066052d5df359 RSI: cfacfdfe6660003e RDI: cfacfdfe66600056 RBP: ffffc90000053d80 R08: 0000000000000000 R09: ffffffff82de1a88 R10: ffffc90000053da0 R11: 0000000000000003 R12: 00000000000001a4 R13: ffffc90000053df0 R14: 0000000000000000 R15: 0000000000000000 FS: 0000000000000000(0000) GS:ffff888040200000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f2c744050e8 CR3: 000080004110e000 CR4: 00000000003506b0 Call Trace: <TASK> ? show_trace_log_lvl+0x1b0/0x2f0 ? show_trace_log_lvl+0x1b0/0x2f0 ? ima_load_kexec_buffer+0x6e/0xf0 ? __die_body.cold+0x8/0x12 ? die_addr+0x3c/0x60 ? exc_general_protection+0x178/0x410 ? asm_exc_general_protection+0x26/0x30 ? ima_restore_measurement_list+0xdc/0x420 ? vprintk_emit+0x1f0/0x270 ? ima_load_kexec_buffer+0x6e/0xf0 ima_load_kexec_buffer+0x6e/0xf0 ima_init+0x52/0xb0 ? __pfx_init_ima+0x10/0x10 init_ima+0x26/0xc0 ? __pfx_init_ima+0x10/0x10 do_one_initcall+0x5b/0x300 do_initcalls+0xdf/0x100 ? __pfx_kernel_init+0x10/0x10 kernel_init_freeable+0x147/0x1a0 kernel_init+0x1a/0x140 ret_from_fork+0x34/0x50 ? __pfx_kernel_init+0x10/0x10 ret_from_fork_asm+0x1a/0x30 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:ima_restore_measurement_list+0xdc/0x420 Code: ff 48 c7 85 10 ff ff ff 00 00 00 00 48 c7 85 18 ff ff ff 00 00 00 00 48 85 f6 0f 84 09 03 00 00 48 83 fa 17 0f 86 ff 02 00 00 <66> 83 3e 01 49 89 f4 0f 85 90 94 7d 00 48 83 7e 10 ff 0f 84 74 94 RSP: 0018:ffffc90000053c80 EFLAGS: 00010286 RAX: 0000000000000000 RBX: ffffc90000053d03 RCX: 0000000000000000 RDX: e48066052d5df359 RSI: cfacfdfe6660003e RDI: cfacfdfe66600056 RBP: ffffc90000053d80 R08: 0000000000000000 R09: ffffffff82de1a88 R10: ffffc90000053da0 R11: 0000000000000003 R12: 00000000000001a4 R13: ffffc90000053df0 R14: 0000000000000000 R15: 0000000000000000 FS: 0000000000000000(0000) GS:ffff888040200000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f2c744050e8 CR3: 000080004110e000 CR4: 00000000003506b0 Kernel panic - not syncing: Fatal exception Kernel Offset: disabled Rebooting in 10 seconds..From debugging printing, the stored addr and size of
ima_kexecbuffer are not decrypted correctly like:
------
ima:ima_load_kexec_buffer, buffer:0xcfacfdfe6660003e, size:0xe48066052d5df359
------There are three pieces of
setup_datainfo passed to kexec/kdump kernel:SETUP_EFI,SETUP_IMAandSETUP_RNG_SEED. However, among them, onlyima_kexecbuffer suffered from the incorrect decryption. After debugging, it's because of the code bug inearly_memremap_is_setup_data()where checking the embedded content insidesetup_datatakes wrong range calculation.The length of efi data,
rng_seedandima_kexecare0x70,0x20,0x10, and the length ofsetup_datais0x10. When checking if data is inside the embedded conent ofsetup_data, the starting address of efi data andrng_seedhappened to land in the wrong calculated range. While the ima_kexec's starting address unluckily doesn't pass the checking, then error occurred.Quoted 3 lines
Here fix the code bug to make kexec/kdump kernel boot up successfully.
Fixes 8f716c9b5feb ("x86/mm: Add support to access boot related data in the clear")The check that was modified was added by:
b3c72fc9a78e ("x86/boot: Introduce setup_indirect")The
SETUP_INDIRECTpatches seem to be the issue here.Quoted 13 lines
Signed-off-by Baoquan He <[email protected]>--- arch/x86/mm/ioremap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/mm/ioremap.c +0
-0@@ -717,7 +717,7 @@ static bool __init early_memremap_is_setup_data(resource_size_t phys_addr, paddr_next = data->next; len = data->len;
Quoted 3 lines
arch/x86/mm/ioremap.c static bool __init early_memremap_is_setup_data(resource_size_t phys_addr, · line 720
Quoted 2 lines
arch/x86/mm/ioremap.c +1
-1-if ((phys_addr > paddr) && (phys_addr < (paddr + len))) { +if ((phys_addr > paddr) && (phys_addr < (paddr + size + len))) {
Tom, I have an old laptop with AMD cpu, according to dmesg below I
assume SME is enabled:
[ 0.082438] Memory Encryption Features active: AMD SME
I tried kexec with mem_encrypt=on, but I can not reproduce Baoquan's problem, it seems either ENC or NOENC works, it is weird to me. Any idea about this?
Otherwise I tried earlycon=efi, early printk does not work. It works with "NOENC" mapping though:
@@ -59,7 +62,8 @@ static __ref void *efi_earlycon_map(unsigned long start, unsigned long len)
if (efi_fb)
return efi_fb + start;- fb_prot = fb_wb ? PAGE_KERNEL : pgprot_writecombine(PAGE_KERNEL);
+ //fb_prot = fb_wb ? PAGE_KERNEL : pgprot_writecombine(PAGE_KERNEL);
+ fb_prot = fb_wb ? PAGE_KERNEL_NOENC :
pgprot_writecombine(PAGE_KERNEL_NOENC);
return early_memremap_prot(fb_base + start, len, pgprot_val(fb_prot));}