Skip to content

Commit cecf494

Browse files
DavidZagurydavidpil2002kellyyeh
authored
[202211] Add support of secure warm-boot backport (#2819)
Backport of #2532 and #2715 * [Secure Boot] Add support of secure warm-boot (#2532) - What I did Add support of secure warm-boot to SONiC. Basically, warm-boot is supporting to load a new kernel without doing full/cold boot. That is by loading a new kernel and exec with kexec Linux command. As a result of that, even when the Secure Boot feature is enabled, still a user or a malicious user can load an unsigned kernel, so to avoid that we added the support of the secure warm boot. More Description about this feature can be found in the Secure Boot HLD: sonic-net/SONiC#1028 - How I did it In general, Linux support it, so I enabled this support by doing the follow steps: I added some special flags in Linux Kernel when user build the sonic-buildimage with secure boot feature enabled. I added a flag "-s" to the kexec command Note: more details in the HLD above. - How to verify it * Good flow: manually just install with sonic-installed a new secure image (a SONiC image that was build with Secure Boot flag enabled) after the secure image is installed, do: warm-reboot Check now that the new kernel is really loaded and switched. * Bad flow: Do the same steps 1-2 as a good flow but with an insecure image (SONiC image that was built without setting Secure Boot enabled) After the insecure image is installed, and triggered warm-boot you should get an error that the new unsigned kernel from the unsecured image was not loaded. Automation test - TBD * [Secure Boot] Fix non-zero status exit on non secure boot system (#2715) What I did Warm-reboot fails on kvm due to non-zero exit upon command bootctl status 2>/dev/null | grep -c "Secure Boot: enabled" How I did it Added || true to return 0 when previous command fails. Added CHECK_SECURE_UPGRADE_ENABLED to check output of previous command Added debug logs How to verify it Run warm-reboot on kvm and physical device when increased verbosity. Expects debug log to indicate secure/non secure boot. Successful warm reboot --------- Co-authored-by: davidpil2002 <[email protected]> Co-authored-by: kellyyeh <[email protected]>
1 parent 6d55f99 commit cecf494

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

scripts/fast-reboot

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ function request_pre_shutdown()
182182
{
183183
if [ -x ${DEVPATH}/${PLATFORM}/${PLATFORM_REBOOT_PRE_CHECK} ]; then
184184
debug "Requesting platform reboot pre-check ..."
185-
${DEVPATH}/${PLATFORM}/${PLATFORM_REBOOT_PRE_CHECK} ${REBOOT_TYPE}
185+
${DEVPATH}/${PLATFORM}/${PLATFORM_REBOOT_PRE_CHECK} ${REBOOT_TYPE}
186186
fi
187187
debug "Requesting pre-shutdown ..."
188188
STATE=$(timeout 5s docker exec syncd /usr/bin/syncd_request_shutdown --pre &> /dev/null; if [[ $? == 124 ]]; then echo "timed out"; fi)
@@ -447,9 +447,20 @@ function load_aboot_secureboot_kernel() {
447447
swipath=$next_image kexec=true loadonly=true ENV_EXTRA_CMDLINE="$BOOT_OPTIONS" bash -
448448
}
449449
450+
function invoke_kexec() {
451+
/sbin/kexec -l "$KERNEL_IMAGE" --initrd="$INITRD" --append="$BOOT_OPTIONS" $@
452+
}
453+
450454
function load_kernel() {
451455
# Load kernel into the memory
452-
/sbin/kexec -l "$KERNEL_IMAGE" --initrd="$INITRD" --append="$BOOT_OPTIONS"
456+
invoke_kexec -a
457+
}
458+
459+
function load_kernel_secure() {
460+
# Load kernel into the memory secure
461+
# -s flag is for enforcing the new load kernel(vmlinuz) to be signed and verify.
462+
# not using -a flag, this flag can fallback to an old kexec load that do not support Secure Boot verification
463+
invoke_kexec -s
453464
}
454465
455466
function unload_kernel()
@@ -607,7 +618,16 @@ fi
607618
if is_secureboot && grep -q aboot_machine= /host/machine.conf; then
608619
load_aboot_secureboot_kernel
609620
else
610-
load_kernel
621+
# check if secure boot is enable in UEFI
622+
CHECK_SECURE_UPGRADE_ENABLED=0
623+
SECURE_UPGRADE_ENABLED=$(bootctl status 2>/dev/null | grep -c "Secure Boot: enabled") || CHECK_SECURE_UPGRADE_ENABLED=$?
624+
if [[ CHECK_SECURE_UPGRADE_ENABLED -ne 0 ]]; then
625+
debug "Loading kernel without secure boot"
626+
load_kernel
627+
else
628+
debug "Loading kernel with secure boot"
629+
load_kernel_secure
630+
fi
611631
fi
612632
613633
init_warm_reboot_states

0 commit comments

Comments
 (0)