From 310d1df1c7f1409879c733f2d52f2d54f8f9525f Mon Sep 17 00:00:00 2001 From: Samuel Angebault Date: Fri, 17 Jul 2020 08:03:04 -0700 Subject: [PATCH] Add secure fast-reboot support for Aboot Instead of having multiple implementation of preparing a SWI image for secureboot, fast-reboot now reuses boot0. SWI images booting in regular mode will keep using the old behavior. --- scripts/fast-reboot | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/scripts/fast-reboot b/scripts/fast-reboot index e18af200c3..27c22f2497 100755 --- a/scripts/fast-reboot +++ b/scripts/fast-reboot @@ -271,14 +271,23 @@ function teardown_control_plane_assistant() fi } +function is_secureboot() { + grep -Eq 'secure_boot_enable=[1y]' /proc/cmdline +} + function setup_reboot_variables() { # Kernel and initrd image NEXT_SONIC_IMAGE=$(sonic-installer list | grep "Next: " | cut -d ' ' -f 2) IMAGE_PATH="/host/image-${NEXT_SONIC_IMAGE#SONiC-OS-}" if grep -q aboot_platform= /host/machine.conf; then - KERNEL_IMAGE="$(ls $IMAGE_PATH/boot/vmlinuz-*)" - BOOT_OPTIONS="$(cat "$IMAGE_PATH/kernel-cmdline" | tr '\n' ' ') SONIC_BOOT_TYPE=${BOOT_TYPE_ARG}" + if is_secureboot; then + KERNEL_IMAGE="" + BOOT_OPTIONS="SONIC_BOOT_TYPE=${BOOT_TYPE_ARG} secure_boot_enable=1" + else + KERNEL_IMAGE="$(ls $IMAGE_PATH/boot/vmlinuz-*)" + BOOT_OPTIONS="$(cat "$IMAGE_PATH/kernel-cmdline" | tr '\n' ' ') SONIC_BOOT_TYPE=${BOOT_TYPE_ARG}" + fi elif grep -q onie_platform= /host/machine.conf; then KERNEL_OPTIONS=$(cat /host/grub/grub.cfg | sed "/$NEXT_SONIC_IMAGE'/,/}/"'!'"g" | grep linux) KERNEL_IMAGE="/host$(echo $KERNEL_OPTIONS | cut -d ' ' -f 2)" @@ -332,6 +341,18 @@ function reboot_pre_check() fi } +function load_aboot_secureboot_kernel() { + local next_image="$IMAGE_PATH/sonic.swi" + echo "Loading next image from $next_image" + unzip -qp "$next_image" boot0 | \ + swipath=$next_image kexec=true loadonly=true ENV_EXTRA_CMDLINE="$BOOT_OPTIONS" bash - +} + +function load_kernel() { + # Load kernel into the memory + /sbin/kexec -l "$KERNEL_IMAGE" --initrd="$INITRD" --append="$BOOT_OPTIONS" +} + function unload_kernel() { # Unload the previously loaded kernel if any loaded @@ -412,8 +433,12 @@ if [[ "$sonic_asic_type" == "mellanox" ]]; then fi fi -# Load kernel into the memory -/sbin/kexec -l "$KERNEL_IMAGE" --initrd="$INITRD" --append="$BOOT_OPTIONS" + +if is_secureboot && grep -q aboot_machine= /host/machine.conf; then + load_aboot_secureboot_kernel +else + load_kernel +fi if [[ "$REBOOT_TYPE" = "fast-reboot" ]]; then # Dump the ARP and FDB tables to files also as default routes for both IPv4 and IPv6