Add support for secure falcon mode
cover Add support for secure falcon mode
Hi all,
During the implementation of falcon mode for TI's K3 devices [1], I encountered several limitations in regards to the current falcon mode support in U-Boot especially in ensuring a secure boot flow.
Although the current implementation allows for loading of a signed fitImage as the SPL payload, there are still a few edge cases that might allow bypassing the verified boot path.
This series is my attempt in adding a secure variant to the existing falcon boot mode. Overall the issues with current falcon mode can be boiled down to the following:
1) No fallback:
We currently fallback to regular boot flow if falcon mode fails, this might not be secure.
2) No arguments file:
We currently load a kernel file (which could be a raw image or FIT) alongside an args file (usually the DT). The args file here doesn't have any verification mechanism, so should be skipped altogether as the FIT can contain the DT.
3) No access to env:
In ext and fat fs boot, currently we also reads the environment to get the names of the kernel and the arg file. This should be disabled in secure falcon flow as the env might not be secure.
4) No raw image boot:
Boot should fail when the kernel file is a raw kernel image, only FIT should be allowed.
The series has been tested on TI's AM62x EVM with SPI, MMC Raw and MMC FS with the fitImage build following TI's linux SDK[2]. I'm looking for boot tests on platforms with existing falcon support to ensure no regressions as well as tests on NAND and NOR boot modes with/without secure falcon boot enabled.
Regards,
Anshul
[1]: https://lore.kernel.org/u-boot/[email protected]/
[2]: https://software-dl.ti.com/processor-sdk-linux/esd/AM62X/latest/exports/docs/linux/Foundational_Components/U-Boot/UG-Falcon-Mode.html#custom-fitimage-creation
Anshul Dalal (17):
spl: Kconfig: add SPL_OS_BOOT_SECURE config symbol
arm: Kconfig: add per device symbols for TI_SECURE
spl: Kconfig: allow K3 devices to use falcon mode
spl: fat: load kernel image before args in falcon
spl: ext: load kernel image before args in falcon
spl: mmc: load kernel image before args in falcon
spl: ext,fat: cleanup use of CONFIG_SPL_LIBCOMMON_SUPPORT
spl: mmc: split spl_mmc_do_fs_boot into regular/os_boot
spl: ubi: refactor spl_ubi_load_image for falcon mode
spl: spi: refactor spl_spi_load_image for falcon mode
spl: nor: refactor spl_nor_load_image for falcon mode
spl: nand: refactor spl_nand_load_image for falcon mode
spl: falcon: disable fallback to U-Boot on failure
spl: falcon: prevent loading args file in secure os boot
env: Kconfig: disable external env in secure os boot
Kconfig: disable raw image boot in secure falcon mode
arm: spl: use fdt addr if arg is unset in falcon mode
arch/arm/Kconfig | 8 +++ arch/arm/lib/spl.c | 2 + boot/Kconfig | 4 +- cmd/Kconfig | 3 +- common/spl/Kconfig | 29 +++++++--- common/spl/spl_ext.c | 63 ++++++++++++---------- common/spl/spl_fat.c | 60 ++++++++++++--------- common/spl/spl_mmc.c | 104 ++++++++++++++++++++++-------------- common/spl/spl_nand.c | 99 +++++++++++++++++++--------------- common/spl/spl_nor.c | 105 +++++++++++++++++++++---------------- common/spl/spl_spi.c | 38 +++++++++++--- common/spl/spl_ubi.c | 50 +++++++++++++----- env/Kconfig | 1 + include/system-constants.h | 2 +- 14 files changed, 358 insertions(+), 210 deletions(-)
Signature · 1 line
2.51.0
PATCH 1/17 spl: Kconfig: add SPL_OS_BOOT_SECURE config symbol
This patch adds the new SPL_OS_BOOT_SECURE symbol that enables secure boot flow in falcon mode. This symbol can be used to disable certain inherently insecure options during falcon boot.
--- common/spl/Kconfig | 8 ++++++++ 1 file changed, 8 insertions(+)
common/spl/Kconfig +8 -0
@@ -1206,6 +1206,14 @@ config SPL_OS_BOOT Enable booting directly to an OS from SPL. for more info read doc/README.falcon +config SPL_OS_BOOT_SECURE + bool "Allow Falcon Mode on secure devices" + depends on SPL_OS_BOOT + help + This allows for secure devices with signature verification capabilities + to use falcon mode by disabling certain inherently non-securable options + in the SPL boot flow. + config SPL_PAYLOAD_ARGS_ADDR hex "Address in memory to load 'args' file for Falcon Mode to" depends on SPL_OS_BOOT || SPL_LOAD_FIT_OPENSBI_OS_BOOT
Signature · 1 line
2.51.0
Re: [PATCH RFT v1 01/17] spl: Kconfig: add SPL_OS_BOOT_SECURE config symbol
Quoted 5 lines · Anshul Dalal
This patch adds the new
SPL_OS_BOOT_SECUREsymbol that enables secure boot flow in falcon mode. This symbol can be used to disable certain inherently insecure options during falcon boot.Signed-off-by Anshul Dalal <[email protected]>
Signature · 1 line
Tom
PATCH 2/17 arm: Kconfig: add per device symbols for TI_SECURE
In reply to Anshul DalalThe TI_SECURE_DEVICE config symbols enables support for HS devices. When enabled some insecure options are disabled such as falcon mode. Even though falcon mode can be enabled for k3 devices securely.
Thus to allow for more granular disablement of options, this patch introduces two new hidden symbols for legacy and k3 architectures.
--- arch/arm/Kconfig | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/arm/Kconfig +8 -0
@@ -2255,9 +2255,17 @@ config TFABOOT Enabling this option will make a U-Boot binary that is relying on other firmware layers to provide secure functionality. +config TI_SECURE_DEVICE_K2_OMAP2PLUS + bool + +config TI_SECURE_DEVICE_K3 + bool + config TI_SECURE_DEVICE bool "HS Device Type Support" depends on ARCH_KEYSTONE || ARCH_OMAP2PLUS || ARCH_K3 + select TI_SECURE_DEVICE_K2_OMAP2PLUS if ARCH_KEYSTONE || ARCH_OMAP2PLUS + select TI_SECURE_DEVICE_K3 if ARCH_K3 help If a high secure (HS) device type is being used, this config must be set. This option impacts various aspects of the
Signature · 1 line
2.51.0
PATCH 3/17 spl: Kconfig: allow K3 devices to use falcon mode
In reply to Anshul DalalFalcon mode was disabled for TI_SECURE_DEVICE at commit e95b9b4437bc ("ti_armv7_common: Disable Falcon Mode on HS devices") for older 32-bit HS devices and can be enabled on K3 devices.
For secure boot, the kernel with x509 headers can be packaged in a fit container (fitImage) signed with TIFS keys for authentication.
--- common/spl/Kconfig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
common/spl/Kconfig +2 -1
@@ -1201,7 +1201,8 @@ config SPL_ONENAND_SUPPORT config SPL_OS_BOOT bool "Activate Falcon Mode" - depends on !TI_SECURE_DEVICE + depends on !TI_SECURE_DEVICE_K2_OMAP2PLUS + select SPL_OS_BOOT_SECURE if TI_SECURE_DEVICE_K3 help Enable booting directly to an OS from SPL. for more info read doc/README.falcon
Signature · 1 line
2.51.0
Re: [PATCH RFT v1 03/17] spl: Kconfig: allow K3 devices to use falcon mode
Quoted 4 lines · Anshul Dalal
Falcon mode was disabled for
TI_SECURE_DEVICEat commite95b9b4437bc("ti_armv7_common: Disable Falcon Mode on HS devices") for older 32-bit HS devices and can be enabled on K3 devices.
The reason we disabled Falcon Mode for these devices is because it could not be done securely, this is exactly what your series here is intended to fix. If we have secure falcon boot, then we should enable it for 32-bit devices also. Enable this for all TI devices and you can drop the previous patch.
Andrew
Quoted 22 lines
For secure boot, the kernel with x509 headers can be packaged in a fit container (fitImage) signed with TIFS keys for authentication.
Signed-off-by Anshul Dalal <[email protected]>--- common/spl/Kconfig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)common/spl/Kconfig +2
-1@@ -1201,7 +1201,8 @@ config SPL_ONENAND_SUPPORT config SPL_OS_BOOT bool "Activate Falcon Mode" - depends on !TI_SECURE_DEVICE + depends on !TI_SECURE_DEVICE_K2_OMAP2PLUS + select SPL_OS_BOOT_SECURE if TI_SECURE_DEVICE_K3 help Enable booting directly to an OS from SPL. for more info read doc/README.falcon
PATCH 4/17 spl: fat: load kernel image before args in falcon
In reply to Anshul DalalCurrently in falcon mode, the FS and raw mmc boot loads the args file first followed by the kernel image whereas others load in the opposite order. This inconsistency means falcon boot doesn't behave the same across various boot media.
For example, in the case where the kernel file is a FIT with the kernel image present alongside the dtb and the args file is another DT, which DT should be picked? The one form the FIT or the one set by the args file? Currently this depends entirely on how the boot media handles falcon mode.
Therefore, this patch enforces the load order of the kernel image first followed by the args file in FAT FS boot. So in the above example, the args file would take precedence.
--- common/spl/spl_fat.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-)
common/spl/spl_fat.c +24 -17
@@ -119,32 +119,40 @@ int spl_load_image_fat_os(struct spl_image_info *spl_image,if (err)return err; -#if defined(CONFIG_SPL_ENV_SUPPORT ) && defined(CONFIG_SPL_OS_BOOT ) - file =env_get ("falcon_args_file" ); +if (!CONFIG_IS_ENABLED (ENV_SUPPORT )) + goto defaults; + + file =env_get ("falcon_image_file" );if (file) { - err =file_fat_read (file, (void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR ,0 ); -if (err <=0 ) { -printf ("spl: error reading image %s, err - %d, falling back to default\n" , - file, err); + err =spl_load_image_fat (spl_image, bootdev, block_dev, + partition, file); +if (err !=0 ) { +puts ("spl: falling back to default\n" ); goto defaults; } - file =env_get ("falcon_image_file" ); + + file =env_get ("falcon_args_file" );if (file) { - err =spl_load_image_fat (spl_image, bootdev, block_dev, - partition, file); -if (err !=0 ) { -puts ("spl: falling back to default\n" ); + err =file_fat_read ( + file, (void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR ,0 ); +if (err <=0 ) { +printf ("spl: error reading args %s, err - %d, falling back to default\n" , + file, err); goto defaults; } -return 0 ; }else -puts ("spl: falcon_image_file not set in environment, falling back to default\n" ); +puts ("spl: falcon_args_file not set in environment, falling back to default\n" ); }else -puts ("spl: falcon_args_file not set in environment, falling back to default\n" ); +puts ("spl: falcon_image_file not set in environment, falling back to default\n" ); defaults: -#endif + + err =spl_load_image_fat (spl_image, bootdev, block_dev, partition, +CONFIG_SPL_FS_LOAD_KERNEL_NAME ); + +if (err) +return err; err =file_fat_read (CONFIG_SPL_FS_LOAD_ARGS_NAME , (void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR ,0 );
@@ -156,8 +164,7 @@ defaults: return -1; } -return spl_load_image_fat (spl_image, bootdev, block_dev, partition, -CONFIG_SPL_FS_LOAD_KERNEL_NAME ); +return 0 ; }#else int spl_load_image_fat_os(struct spl_image_info *spl_image,
Signature · 1 line
2.51.0
Re: [PATCH RFT v1 04/17] spl: fat: load kernel image before args in falcon
Quoted 11 lines · Anshul Dalal
Currently in falcon mode, the FS and raw mmc boot loads the args file first followed by the kernel image whereas others load in the opposite order. This inconsistency means falcon boot doesn't behave the same across various boot media.
For example, in the case where the kernel file is a FIT with the kernel image present alongside the dtb and the args file is another DT, which DT should be picked? The one form the FIT or the one set by the args file? Currently this depends entirely on how the boot media handles falcon mode.
Quoted 5 lines
Therefore, this patch enforces the load order of the kernel image first followed by the args file in FAT FS boot. So in the above example, the args file would take precedence.
Signed-off-by Anshul Dalal <[email protected]>
Signature · 1 line
Tom
PATCH 5/17 spl: ext: load kernel image before args in falcon
In reply to Anshul DalalLoad the kernel image before args in falcon mode to be consistent with the load order for other boot media.
--- common/spl/spl_ext.c | 51 +++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 22 deletions(-)
common/spl/spl_ext.c +29 -22
@@ -96,39 +96,47 @@ int spl_load_image_ext_os(struct spl_image_info *spl_image,#endif return -1 ; } -#if defined(CONFIG_SPL_ENV_SUPPORT ) - file =env_get ("falcon_args_file" ); + +if (!CONFIG_IS_ENABLED (ENV_SUPPORT )) + goto defaults; + + file =env_get ("falcon_image_file" );if (file) { - err =ext4fs_open (file, &filelen); -if (err <0 ) { -puts ("spl: ext4fs_open failed\n" ); + err =spl_load_image_ext (spl_image, bootdev, block_dev, + partition, file); +if (err !=0 ) { +puts ("spl: falling back to default\n" ); goto defaults; } - err =ext4fs_read ((void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR ,0 , filelen, &actlen); -if (err <0 ) { -printf ("spl: error reading image %s, err - %d, falling back to default\n" , - file, err); - goto defaults; - } - file =env_get ("falcon_image_file" ); + file =env_get ("falcon_args_file" );if (file) { - err =spl_load_image_ext (spl_image, bootdev, block_dev, - partition, file); -if (err !=0 ) { -puts ("spl: falling back to default\n" ); + err =ext4fs_open (file, &filelen); +if (err <0 ) { +puts ("spl: ext4fs_open failed\n" ); + goto defaults; + } + err =ext4fs_read ((void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR , +0 , filelen, &actlen); +if (err <0 ) { +printf ("spl: error reading args %s, err - %d, falling back to default\n" , + file, err); goto defaults; } -return 0 ; }else { -puts ("spl: falcon_image_file not set in environment, falling back to default\n" ); +puts ("spl: falcon_args_file not set in environment, falling back to default\n" ); } }else { -puts ("spl: falcon_args_file not set in environment, falling back to default\n" ); +puts ("spl: falcon_image_file not set in environment, falling back to default\n" ); } defaults: -#endif + + err =spl_load_image_ext (spl_image, bootdev, block_dev, partition, +CONFIG_SPL_FS_LOAD_KERNEL_NAME ); + +if (err) +return err; err =ext4fs_open (CONFIG_SPL_FS_LOAD_ARGS_NAME , &filelen);if (err <0 )
@@ -143,8 +151,7 @@ defaults: return -1; } -return spl_load_image_ext (spl_image, bootdev, block_dev, partition, -CONFIG_SPL_FS_LOAD_KERNEL_NAME ); +return 0 ; }#else int spl_load_image_ext_os(struct spl_image_info *spl_image,
Signature · 1 line
2.51.0
Re: [PATCH RFT v1 05/17] spl: ext: load kernel image before args in falcon
Quoted 4 lines · Anshul Dalal
Load the kernel image before args in falcon mode to be consistent with the load order for other boot media.
Signed-off-by Anshul Dalal <[email protected]>
Signature · 1 line
Tom
PATCH 6/17 spl: mmc: load kernel image before args in falcon
In reply to Anshul DalalLoad the kernel image before args in falcon mode to be consistent with the load order for other boot media.
--- common/spl/spl_mmc.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
common/spl/spl_mmc.c +10 -10
@@ -152,6 +152,16 @@ static int mmc_load_image_raw_os(struct spl_image_info *spl_image, {int ret; + ret =mmc_load_image_raw_sector (spl_image, bootdev, mmc, +CONFIG_SYS_MMCSD_RAW_MODE_KERNEL_SECTOR ); +if (ret) +return ret; + +if (spl_image->os !=IH_OS_LINUX && spl_image->os !=IH_OS_TEE ) { +puts ("Expected image is not found. Trying to start U-Boot\n" ); +return -ENOENT ; + } +#if defined(CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR )unsigned long count;
@@ -165,16 +175,6 @@ static int mmc_load_image_raw_os(struct spl_image_info *spl_image, }#endif /* CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR */ - ret =mmc_load_image_raw_sector (spl_image, bootdev, mmc, -CONFIG_SYS_MMCSD_RAW_MODE_KERNEL_SECTOR ); -if (ret) -return ret; - -if (spl_image->os !=IH_OS_LINUX && spl_image->os !=IH_OS_TEE ) { -puts ("Expected image is not found. Trying to start U-Boot\n" ); -return -ENOENT ; - } -return 0 ; }#else
Signature · 1 line
2.51.0
Re: [PATCH RFT v1 06/17] spl: mmc: load kernel image before args in falcon
Quoted 7 lines · Anshul Dalal
Load the kernel image before args in falcon mode to be consistent with the load order for other boot media.
Signed-off-by Anshul Dalal <[email protected]>--- common/spl/spl_mmc.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
For the next iteration please CC some of the people who are using the TEE case here which I think is non-TI platforms. Doing "tools/qconfig.py -b" and then "tools/qconfig.py -f SOME_SYMBOL" will show what platforms enable a symbol (and you can list multiple and '~' means does not set a symbol) and should give some hints about users. Thanks!
Signature · 1 line
Tom
PATCH 7/17 spl: ext, fat: cleanup use of CONFIG_SPL_LIBCOMMON_SUPPORT
In reply to Anshul DalalMinor cleanup of spl_ext and spl_fat files, removing the outdated CONFIG_SPL_LIBCOMMON_SUPPORT symbols similar to the commit 1847129025e0 ("spl: mmc: Drop checks for CONFIG_SPL_LIBCOMMON_SUPPORT") and adding a few extra failure reports.
--- common/spl/spl_ext.c | 8 +++----- common/spl/spl_fat.c | 14 ++++++-------- 2 files changed, 9 insertions(+), 13 deletions(-)
common/spl/spl_ext.c +3 -5
@@ -47,9 +47,7 @@ int spl_load_image_ext(struct spl_image_info *spl_image, err =ext4fs_mount ();if (!err) { -#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT printf ("%s: ext4fs mount err - %d\n" , __func__, err); -#endif return -1 ; }
@@ -63,11 +61,9 @@ int spl_load_image_ext(struct spl_image_info *spl_image, err =spl_load (spl_image, bootdev, &load, filelen,0 ); end: -#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT if (err <0 )printf ("%s: error reading image %s, err - %d\n" , __func__, filename, err); -#endif return err <0 ; }
@@ -139,8 +135,10 @@ defaults:return err; err =ext4fs_open (CONFIG_SPL_FS_LOAD_ARGS_NAME , &filelen); -if (err <0 ) +if (err <0 ) {puts ("spl: ext4fs_open failed\n" ); +return err; + } err =ext4fs_read ((void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR ,0 , filelen, &actlen);if (err <0 ) {
common/spl/spl_fat.c +6 -8
@@ -98,11 +98,9 @@ int spl_load_image_fat(struct spl_image_info *spl_image, err =spl_load (spl_image, bootdev, &load, size,0 ); end: -#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT if (err <0 )printf ("%s: error reading image %s, err - %d\n" , __func__, filename, err); -#endif return err; }
@@ -116,8 +114,10 @@ int spl_load_image_fat_os(struct spl_image_info *spl_image,__maybe_unused char *file; err =spl_register_fat_device (block_dev, partition); -if (err) +if (err) { +printf ("%s: fat mount err - %d\n" , __func__, err);return err; + }if (!CONFIG_IS_ENABLED (ENV_SUPPORT )) goto defaults;
@@ -157,11 +157,9 @@ defaults: err =file_fat_read (CONFIG_SPL_FS_LOAD_ARGS_NAME , (void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR ,0 );if (err <=0 ) { -#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT -printf ("%s: error reading image %s, err - %d\n" , - __func__,CONFIG_SPL_FS_LOAD_ARGS_NAME , err); -#endif -return -1 ; +printf ("%s: error reading image %s, err - %d\n" , __func__, +CONFIG_SPL_FS_LOAD_ARGS_NAME , err); +return err; }return 0 ;
Signature · 1 line
2.51.0
Re: [PATCH RFT v1 07/17] spl: ext,fat: cleanup use of CONFIG_SPL_LIBCOMMON_SUPPORT
Quoted 6 lines · Anshul Dalal
Minor cleanup of
spl_extandspl_fatfiles, removing the outdatedCONFIG_SPL_LIBCOMMON_SUPPORTsymbols similar to the commit1847129025e0("spl: mmc: Drop checks forCONFIG_SPL_LIBCOMMON_SUPPORT") and adding a few extra failure reports.Signed-off-by Anshul Dalal <[email protected]>
Signature · 1 line
Tom
PATCH 8/17 spl: mmc: split spl_mmc_do_fs_boot into regular/os_boot
In reply to Anshul DalalCurrently the logic to handle falcon mode as well as the regular boot is inside spl_mmc_do_fs_boot, this prevents us from cleanly extending falcon mode functionality like toggleable fallback to U-Boot proper.
Therefore this patch splits the logic into spl_mmc_fs_load and spl_mmc_fs_load_os to handle the regular boot and falcon mode use case.
--- common/spl/spl_mmc.c | 80 +++++++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 30 deletions(-)
common/spl/spl_mmc.c +50 -30
@@ -193,6 +193,46 @@ int spl_start_uboot(void) }#endif +static int spl_mmc_fs_load_os (struct spl_image_info *spl_image, +struct spl_boot_device *bootdev, +struct blk_desc *blk_dev,int part) +{ +int err = -ENOSYS ; + +if (CONFIG_IS_ENABLED (FS_FAT )) { + err =spl_load_image_fat_os (spl_image, bootdev, blk_dev, part); +if (!err) +return 0 ; + } +if (CONFIG_IS_ENABLED (FS_EXT4 )) { + err =spl_load_image_ext_os (spl_image, bootdev, blk_dev, part); +if (!err) +return 0 ; + } + +return err; +} + +static int spl_mmc_fs_load (struct spl_image_info *spl_image, +struct spl_boot_device *bootdev, +struct blk_desc *blk_dev,int part,const char *file) +{ +int err = -ENOENT ; + +if (CONFIG_IS_ENABLED (FS_FAT )) { + err =spl_load_image_fat (spl_image, bootdev, blk_dev, part, file); +if (!err) +return 0 ; + } +if (CONFIG_IS_ENABLED (FS_EXT4 )) { + err =spl_load_image_ext (spl_image, bootdev, blk_dev, part, file); +if (!err) +return 0 ; + } + +return err; +} +#ifdef CONFIG_SYS_MMCSD_FS_BOOT static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image, struct spl_boot_device *bootdev,
@@ -225,42 +265,22 @@ static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image, }#endif -#ifdef CONFIG_SPL_FS_FAT if (!spl_start_uboot ()) { - ret =spl_load_image_fat_os (spl_image, bootdev,mmc_get_blk_desc (mmc), - partition); + ret =spl_mmc_fs_load_os (spl_image, bootdev, +mmc_get_blk_desc (mmc), partition);if (!ret)return 0 ; +printf ("%s, Failed to load falcon payload: %d\n" , __func__, + ret); +printf ("Fallback to U-Boot\n" ); } -#ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME - ret =spl_load_image_fat (spl_image, bootdev,mmc_get_blk_desc (mmc), - partition, - filename); -if (!ret) -return ret; -#endif -#endif -#ifdef CONFIG_SPL_FS_EXT4 -if (!spl_start_uboot ()) { - ret =spl_load_image_ext_os (spl_image, bootdev,mmc_get_blk_desc (mmc), - partition); -if (!ret) -return 0 ; - } -#ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME - ret =spl_load_image_ext (spl_image, bootdev,mmc_get_blk_desc (mmc), - partition, - filename); -if (!ret) -return 0 ; -#endif -#endif - -#if defined(CONFIG_SPL_FS_FAT ) || defined(CONFIG_SPL_FS_EXT4 ) - ret = -ENOENT ; -#endif +#ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME +return spl_mmc_fs_load (spl_image, bootdev,mmc_get_blk_desc (mmc), + partition, filename); +#else return ret; +#endif }#endif
Signature · 1 line
2.51.0
PATCH 9/17 spl: ubi: refactor spl_ubi_load_image for falcon mode
In reply to Anshul DalalThis patch moves the falcon mode handling logic out of spl_ubi_load_image to spl_ubi_load_image_os, this allows for cleaner handling for fallback to U-Boot in case falcon mode fails.
--- common/spl/spl_ubi.c | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-)
common/spl/spl_ubi.c +32 -12
@@ -11,6 +11,32 @@#include <ubispl.h> #include <spl.h> +#if CONFIG_IS_ENABLED (OS_BOOT ) +int spl_ubi_load_image_os (struct spl_image_info *spl_image, +struct spl_boot_device *bootdev, +struct ubispl_info *info) +{ +struct legacy_img_hdr *header; +struct ubispl_load volumes[2 ]; +int err; + + volumes[0 ].vol_id =CONFIG_SPL_UBI_LOAD_KERNEL_ID ; + volumes[0 ].load_addr = (void *)CONFIG_SYS_LOAD_ADDR ; + volumes[1 ].vol_id =CONFIG_SPL_UBI_LOAD_ARGS_ID ; + volumes[1 ].load_addr = (void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR ; + + err =ubispl_load_volumes (info, volumes,2 ); +if (err) +return err; + + header = (struct legacy_img_hdr *)volumes[0 ].load_addr; +spl_parse_image_header (spl_image, bootdev, header); +puts ("Linux loaded.\n" ); + +return 0 ; +} +#endif +int spl_ubi_load_image (struct spl_image_info *spl_image,struct spl_boot_device *bootdev) {
@@ -46,21 +72,15 @@ int spl_ubi_load_image(struct spl_image_info *spl_image,#if CONFIG_IS_ENABLED (OS_BOOT )if (!spl_start_uboot ()) { - volumes[0 ].vol_id =CONFIG_SPL_UBI_LOAD_KERNEL_ID ; - volumes[0 ].load_addr = (void *)CONFIG_SYS_LOAD_ADDR ; - volumes[1 ].vol_id =CONFIG_SPL_UBI_LOAD_ARGS_ID ; - volumes[1 ].load_addr = (void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR ; + ret =spl_ubi_load_image_os (spl_image, bootdev, &info); +if (!ret) +return 0 ; - ret =ubispl_load_volumes (&info, volumes,2 ); -if (!ret) { - header = (struct legacy_img_hdr *)volumes[0 ].load_addr; -spl_parse_image_header (spl_image, bootdev, header); -puts ("Linux loaded.\n" ); - goto out; - } -puts ("Loading Linux failed, falling back to U-Boot.\n" ); +printf ("%s: Failed in falcon boot: %d" , __func__, ret); +printf ("Fallback to U-Boot\n" ); }#endif + header =spl_get_load_buffer (-sizeof (*header),sizeof (header));#ifdef CONFIG_SPL_UBI_LOAD_BY_VOLNAME volumes[0 ].vol_id =-1 ;
Signature · 1 line
2.51.0
PATCH 10/17 spl: spi: refactor spl_spi_load_image for falcon mode
In reply to Anshul DalalThis patch moves the falcon mode handling logic out of spl_spi_load_image to spl_spi_load_image_os, this allows for cleaner handling for fallback to U-Boot in case falcon mode fails.
--- common/spl/spl_spi.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-)
common/spl/spl_spi.c +24 -7
@@ -49,6 +49,25 @@ u32 __weak spl_spi_boot_cs(void)return CONFIG_SF_DEFAULT_CS ; } +#if CONFIG_IS_ENABLED (OS_BOOT ) +static int spl_spi_load_image_os (struct spl_image_info *spl_image, +struct spl_boot_device *bootdev, +struct spi_flash *flash, +struct spl_load_info *load) +{ +int err =spl_load (spl_image, bootdev, load,0 , +CONFIG_SYS_SPI_KERNEL_OFFS ); + +if (err) +return err; + +/* Read device tree. */ +return spi_flash_read (flash,CONFIG_SYS_SPI_ARGS_OFFS , +CONFIG_SYS_SPI_ARGS_SIZE , + (void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR ); +} +#endif +/* * The main entry for SPI booting. It's necessary that SDRAM is already * configured and available since this code loads the main U-Boot image
@@ -81,15 +100,13 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,#if CONFIG_IS_ENABLED (OS_BOOT )if (!spl_start_uboot ()) { -int err =spl_load (spl_image, bootdev, &load,0 , -CONFIG_SYS_SPI_KERNEL_OFFS ); + err =spl_spi_load_image_os (spl_image, bootdev, flash, &load);if (!err) -/* Read device tree. */ -return spi_flash_read ( - flash,CONFIG_SYS_SPI_ARGS_OFFS , -CONFIG_SYS_SPI_ARGS_SIZE , - (void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR ); +return 0 ; + +printf ("%s: Failed in falcon boot: %d, fallback to U-Boot" , + __func__, err); }#endif
Signature · 1 line
2.51.0
PATCH 11/17 spl: nor: refactor spl_nor_load_image for falcon mode
In reply to Anshul DalalThis patch moves the falcon mode handling logic out of spl_nor_load_image to spl_nor_load_image_os, this allows for cleaner handling for fallback to U-Boot in case falcon mode fails.
--- common/spl/spl_nor.c | 103 ++++++++++++++++++++++++------------------- 1 file changed, 58 insertions(+), 45 deletions(-)
common/spl/spl_nor.c +58 -45
@@ -25,66 +25,79 @@ unsigned long __weak spl_nor_get_uboot_base(void)return CFG_SYS_UBOOT_BASE ; } -static int spl_nor_load_image (struct spl_image_info *spl_image, -struct spl_boot_device *bootdev) +#if CONFIG_IS_ENABLED (OS_BOOT ) +static int spl_nor_load_image_os (struct spl_image_info *spl_image, +struct spl_boot_device *bootdev) { -struct spl_load_info load; -/* -* Loading of the payload to SDRAM is done with skipping of -* the mkimage header in this SPL NOR driver +* Load Linux from its location in NOR flash to its defined +* location in SDRAM */ - spl_image->flags |=SPL_COPY_PAYLOAD_ONLY ; +const struct legacy_img_hdr *header = + (const struct legacy_img_hdr *)CONFIG_SYS_OS_BASE ; +struct spl_load_info load; -#if CONFIG_IS_ENABLED (OS_BOOT ) -if (!spl_start_uboot ()) { -/* -* Load Linux from its location in NOR flash to its defined -* location in SDRAM -*/ -const struct legacy_img_hdr *header = - (const struct legacy_img_hdr *)CONFIG_SYS_OS_BASE ;#ifdef CONFIG_SPL_LOAD_FIT -if (image_get_magic (header) ==FDT_MAGIC ) { -int ret; +if (image_get_magic (header) ==FDT_MAGIC ) { +int ret; -debug ("Found FIT\n" ); -spl_load_init (&load, spl_nor_load_read,NULL ,1 ); +debug ("Found FIT\n" ); +spl_load_init (&load, spl_nor_load_read,NULL ,1 ); - ret =spl_load_simple_fit (spl_image, &load, -CONFIG_SYS_OS_BASE , - (void *)header); + ret =spl_load_simple_fit (spl_image, &load,CONFIG_SYS_OS_BASE , + (void *)header);#if definedCONFIG_SPL_PAYLOAD_ARGS_ADDR && definedCONFIG_CMD_SPL_NOR_OFS -memcpy ((void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR , - (void *)CONFIG_CMD_SPL_NOR_OFS , -CONFIG_CMD_SPL_WRITE_SIZE ); +memcpy ((void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR , + (void *)CONFIG_CMD_SPL_NOR_OFS , +CONFIG_CMD_SPL_WRITE_SIZE );#endif -return ret; - } +return ret; + }#endif -if (image_get_os (header) ==IH_OS_LINUX ) { -/* happy - was a Linux */ -int ret; - - ret =spl_parse_image_header (spl_image, bootdev, header); -if (ret) -return ret; - -memcpy ((void *)spl_image->load_addr, - (void *)(CONFIG_SYS_OS_BASE + -sizeof (struct legacy_img_hdr )), - spl_image->size); +if (image_get_os (header) !=IH_OS_LINUX ) { +return -EINVAL ; + } + +/* happy - was a Linux */ +int ret; + + ret =spl_parse_image_header (spl_image, bootdev, header); +if (ret) +return ret; + +memcpy ((void *)spl_image->load_addr, + (void *)(CONFIG_SYS_OS_BASE +sizeof (struct legacy_img_hdr )), + spl_image->size); +#ifdef CONFIG_SPL_PAYLOAD_ARGS_ADDR - spl_image->arg = (void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR ; + spl_image->arg = (void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR ;#endif +return 0 ; +} +#endif + +static int spl_nor_load_image (struct spl_image_info *spl_image, +struct spl_boot_device *bootdev) +{ +int err; +struct spl_load_info load; + +/* +* Loading of the payload to SDRAM is done with skipping of +* the mkimage header in this SPL NOR driver +*/ + spl_image->flags |=SPL_COPY_PAYLOAD_ONLY ; + +#if CONFIG_IS_ENABLED (OS_BOOT ) +if (!spl_start_uboot ()) { + err =spl_nor_load_image_os (spl_image, bootdev); +if (!err)return 0 ; - }else { -puts ("The Expected Linux image was not found.\n" -"Please check your NOR configuration.\n" -"Trying to start u-boot now...\n" ); - } + +printf ("%s: Failed in falcon boot: %d, fallback to U-Boot" , + __func__, err); }#endif
Signature · 1 line
2.51.0
PATCH 12/17 spl: nand: refactor spl_nand_load_image for falcon mode
In reply to Anshul DalalThis patch moves the falcon mode handling logic out of spl_ubi_load_image to spl_ubi_load_image_os, this allows for cleaner handling for fallback to U-Boot in case falcon mode fails.
--- common/spl/spl_nand.c | 96 ++++++++++++++++++++++++------------------- 1 file changed, 53 insertions(+), 43 deletions(-)
common/spl/spl_nand.c +53 -43
@@ -75,6 +75,53 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,return spl_load (spl_image, bootdev, &load,0 , offset); } +#if CONFIG_IS_ENABLED (OS_BOOT ) +static int spl_nand_load_image_os (struct spl_image_info *spl_image, +struct spl_boot_device *bootdev) +{ +int *src, *dst, err; +struct legacy_img_hdr *header =spl_get_load_buffer (0 ,sizeof (*header)); + +/* load linux */ +nand_spl_load_image (CONFIG_SYS_NAND_SPL_KERNEL_OFFS ,sizeof (*header), + (void *)header); + err =spl_parse_image_header (spl_image, bootdev, header); +if (err) +return err; + +if (header->ih_os !=IH_OS_LINUX ) { +return -EINVAL ; + } + +/* happy - was a linux */ + err =nand_spl_load_image (CONFIG_SYS_NAND_SPL_KERNEL_OFFS , + spl_image->size, + (void *)spl_image->load_addr); +nand_deselect (); + +if (err) +return err; + +/* +* load parameter image load to temp position since nand_spl_load_image +* reads a whole block which is typically larger than +* CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite following sections +* like BSS +*/ +nand_spl_load_image (CONFIG_CMD_SPL_NAND_OFS ,CONFIG_CMD_SPL_WRITE_SIZE , + (void *)CONFIG_TEXT_BASE ); +/* copy to destintion */ +for (dst = (int *)CONFIG_SPL_PAYLOAD_ARGS_ADDR , + src = (int *)CONFIG_TEXT_BASE ; + src < (int *)(CONFIG_TEXT_BASE +CONFIG_CMD_SPL_WRITE_SIZE ); + src++, dst++) { +writel (readl (src), dst); + } + +return 0 ; +} +#endif +static int spl_nand_load_image (struct spl_image_info *spl_image,struct spl_boot_device *bootdev) {
@@ -89,51 +136,14 @@ static int spl_nand_load_image(struct spl_image_info *spl_image,#if CONFIG_IS_ENABLED (OS_BOOT )if (!spl_start_uboot ()) { -int *src, *dst; -struct legacy_img_hdr *header = -spl_get_load_buffer (0 ,sizeof (*header)); - -/* -* load parameter image -* load to temp position since nand_spl_load_image reads -* a whole block which is typically larger than -* CONFIG_CMD_SPL_WRITE_SIZE therefore may overwrite -* following sections like BSS -*/ -nand_spl_load_image (CONFIG_CMD_SPL_NAND_OFS , -CONFIG_CMD_SPL_WRITE_SIZE , - (void *)CONFIG_TEXT_BASE ); -/* copy to destintion */ -for (dst = (int *)CONFIG_SPL_PAYLOAD_ARGS_ADDR , - src = (int *)CONFIG_TEXT_BASE ; - src < (int *)(CONFIG_TEXT_BASE + -CONFIG_CMD_SPL_WRITE_SIZE ); - src++, dst++) { -writel (readl (src), dst); - } - -/* load linux */ -nand_spl_load_image (CONFIG_SYS_NAND_SPL_KERNEL_OFFS , -sizeof (*header), (void *)header); - err =spl_parse_image_header (spl_image, bootdev, header); -if (err) -return err; -if (header->ih_os ==IH_OS_LINUX ) { -/* happy - was a linux */ - err =nand_spl_load_image ( -CONFIG_SYS_NAND_SPL_KERNEL_OFFS , - spl_image->size, - (void *)spl_image->load_addr); -nand_deselect (); -return err; - }else { -puts ("The Expected Linux image was not " -"found. Please check your NAND " -"configuration.\n" ); -puts ("Trying to start u-boot now...\n" ); - } + err =spl_nand_load_image_os (spl_image, bootdev); +if (!err) +return 0 ; +printf ("%s: Failed in falcon boot: %d, fallback to U-Boot" , + __func__, err); }#endif +#ifdef CONFIG_NAND_ENV_DST spl_nand_load_element (spl_image, bootdev,CONFIG_ENV_OFFSET );#ifdef CONFIG_ENV_OFFSET_REDUND
Signature · 1 line
2.51.0
PATCH 13/17 spl: falcon: disable fallback to U-Boot on failure
In reply to Anshul DalalInstead of falling back to the standard U-Boot boot flow, we should just halt boot if the expected boot flow in falcon mode fails.
This prevents a malicious actor from accessing U-Boot proper if they can cause the boot failure on falcon mode.
--- common/spl/spl_mmc.c | 4 ++++ common/spl/spl_nand.c | 6 ++++-- common/spl/spl_nor.c | 6 ++++-- common/spl/spl_spi.c | 6 ++++-- common/spl/spl_ubi.c | 2 ++ 5 files changed, 18 insertions(+), 6 deletions(-)
common/spl/spl_mmc.c +4 -0
@@ -272,6 +272,8 @@ static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image,return 0 ;printf ("%s, Failed to load falcon payload: %d\n" , __func__, ret); +if (CONFIG_IS_ENABLED (OS_BOOT_SECURE )) +return ret;printf ("Fallback to U-Boot\n" ); }
@@ -412,6 +414,8 @@ int spl_mmc_load(struct spl_image_info *spl_image, ret =mmc_load_image_raw_os (spl_image, bootdev, mmc);if (!ret)return 0 ; +if (CONFIG_IS_ENABLED (OS_BOOT_SECURE )) +return ret; } raw_sect =spl_mmc_get_uboot_raw_sector (mmc, raw_sect);
common/spl/spl_nand.c +4 -2
@@ -139,8 +139,10 @@ static int spl_nand_load_image(struct spl_image_info *spl_image, err =spl_nand_load_image_os (spl_image, bootdev);if (!err)return 0 ; -printf ("%s: Failed in falcon boot: %d, fallback to U-Boot" , - __func__, err); +printf ("%s: Failed in falcon boot: %d" , __func__, err); +if (CONFIG_IS_ENABLED (OS_BOOT_SECURE )) +return err; + printf("Fallback to U-Boot\n"); }#endif
common/spl/spl_nor.c +4 -2
@@ -96,8 +96,10 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,if (!err)return 0 ; -printf ("%s: Failed in falcon boot: %d, fallback to U-Boot" , - __func__, err); +printf ("%s: Failed in falcon boot: %d" , __func__, err); +if (CONFIG_IS_ENABLED (OS_BOOT_SECURE )) +return err; + printf("Fallback to U-Boot\n"); }#endif
common/spl/spl_spi.c +4 -2
@@ -105,8 +105,10 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,if (!err)return 0 ; -printf ("%s: Failed in falcon boot: %d, fallback to U-Boot" , - __func__, err); +printf ("%s: Failed in falcon boot: %d" , __func__, err); +if (CONFIG_IS_ENABLED (OS_BOOT_SECURE )) +return err; + printf("Fallback to U-Boot\n"); }#endif
common/spl/spl_ubi.c +2 -0
@@ -77,6 +77,8 @@ int spl_ubi_load_image(struct spl_image_info *spl_image,return 0 ;printf ("%s: Failed in falcon boot: %d" , __func__, ret); +if (CONFIG_IS_ENABLED (OS_BOOT_SECURE )) +return ret; printf("Fallback to U-Boot\n"); }#endif
Signature · 1 line
2.51.0
PATCH 14/17 spl: falcon: prevent loading args file in secure os boot
In reply to Anshul DalalThe expected payload for the SPL in secure falcon mode is a fitImage that contains the kernel image and the DT. This removes the need to load an additional args file, which exposes an additional attack vector since it can not be verified.
Therefore this patch disables loading of the arg file when SPL_OS_BOOT_SECURE is set.
--- common/spl/Kconfig | 18 +++++++++++------- common/spl/spl_ext.c | 4 ++++ common/spl/spl_fat.c | 5 +++++ common/spl/spl_nand.c | 5 ++++- common/spl/spl_spi.c | 5 +++++ common/spl/spl_ubi.c | 4 ++++ include/system-constants.h | 2 +- 7 files changed, 34 insertions(+), 9 deletions(-)
common/spl/Kconfig +11 -7
@@ -796,6 +796,7 @@ config SPL_FS_LOAD_PAYLOAD_NAME config SPL_FS_LOAD_KERNEL_NAME string "File to load for the OS kernel from the filesystem" depends on (SPL_FS_EXT4 || SPL_FS_FAT || SPL_FS_SQUASHFS) && SPL_OS_BOOT + default "fitImage" if SPL_OS_BOOT_SECURE default "uImage" help Filename to read to load for the OS kernel when reading from the
@@ -803,7 +804,8 @@ config SPL_FS_LOAD_KERNEL_NAME config SPL_FS_LOAD_ARGS_NAME string "File to load for the OS kernel argument parameters from the filesystem" - depends on (SPL_FS_EXT4 || SPL_FS_FAT || SPL_FS_SQUASHFS) && SPL_OS_BOOT + depends on (SPL_FS_EXT4 || SPL_FS_FAT || SPL_FS_SQUASHFS) && SPL_OS_BOOT \ + && !(SPL_OS_BOOT_SECURE) default "args" help Filename to read to load for the OS kernel argument parameters from
@@ -1121,7 +1123,7 @@ config SPL_UBI_LOAD_KERNEL_ID config SPL_UBI_LOAD_ARGS_ID int "id of kernel args volume" - depends on SPL_OS_BOOT + depends on SPL_OS_BOOT && !SPL_OS_BOOT_SECURE help The UBI volume id from which to load the device tree
@@ -1217,7 +1219,8 @@ config SPL_OS_BOOT_SECURE config SPL_PAYLOAD_ARGS_ADDR hex "Address in memory to load 'args' file for Falcon Mode to" - depends on SPL_OS_BOOT || SPL_LOAD_FIT_OPENSBI_OS_BOOT + depends on (SPL_OS_BOOT || SPL_LOAD_FIT_OPENSBI_OS_BOOT) \ + && !SPL_OS_BOOT_SECURE default 0x88000000 if ARCH_OMAP2PLUS default 0x99000000 if ARCH_SC5XX && SC59X_64 default 0xA0000000 if ARCH_SC5XX && TARGET_SC594_SOM_EZKIT
@@ -1257,7 +1260,7 @@ config SYS_MMCSD_RAW_MODE_KERNEL_SECTOR config SYS_MMCSD_RAW_MODE_ARGS_SECTOR hex "Falcon mode: Sector to load 'args' from MMC" - depends on SPL_FALCON_BOOT_MMCSD + depends on SPL_FALCON_BOOT_MMCSD && !SPL_OS_BOOT_SECURE help When Falcon mode is used with an MMC or SD media, SPL needs to know where to look for the OS 'args', typically a device tree. The
@@ -1267,7 +1270,8 @@ config SYS_MMCSD_RAW_MODE_ARGS_SECTOR config SYS_MMCSD_RAW_MODE_ARGS_SECTORS hex "Falcon mode: Number of sectors to load for 'args' from MMC" - depends on SPL_FALCON_BOOT_MMCSD && SYS_MMCSD_RAW_MODE_ARGS_SECTOR != 0x0 + depends on SPL_FALCON_BOOT_MMCSD && SYS_MMCSD_RAW_MODE_ARGS_SECTOR != 0x0 \ + && !SPL_OS_BOOT_SECURE config SPL_PAYLOAD string "SPL payload"
@@ -1503,14 +1507,14 @@ config SYS_SPI_KERNEL_OFFS config SYS_SPI_ARGS_OFFS hex "Falcon mode: address of args payload in SPI flash" - depends on SPL_SPI_FLASH_SUPPORT && SPL_OS_BOOT + depends on SPL_SPI_FLASH_SUPPORT && SPL_OS_BOOT && !SPL_OS_BOOT_SECURE help Address within SPI-Flash from where the args payload (usually the dtb) is fetched in falcon boot. config SYS_SPI_ARGS_SIZE hex "Falcon mode: size of args payload in SPI flash" - depends on SPL_SPI_FLASH_SUPPORT && SPL_OS_BOOT + depends on SPL_SPI_FLASH_SUPPORT && SPL_OS_BOOT && !SPL_OS_BOOT_SECURE config SPL_THERMAL bool "Driver support for thermal devices"
common/spl/spl_ext.c +4 -0
@@ -104,6 +104,7 @@ int spl_load_image_ext_os(struct spl_image_info *spl_image,puts ("spl: falling back to default\n" ); goto defaults; } +#ifdef CONFIG_SPL_PAYLOAD_ARGS_ADDR file =env_get ("falcon_args_file" );if (file) { err =ext4fs_open (file, &filelen);
@@ -122,6 +123,7 @@ int spl_load_image_ext_os(struct spl_image_info *spl_image, } else {puts ("spl: falcon_args_file not set in environment, falling back to default\n" ); } +#endif }else {puts ("spl: falcon_image_file not set in environment, falling back to default\n" ); }
@@ -134,6 +136,7 @@ defaults:if (err)return err; +#ifdef CONFIG_SPL_PAYLOAD_ARGS_ADDR err =ext4fs_open (CONFIG_SPL_FS_LOAD_ARGS_NAME , &filelen);if (err <0 ) {puts ("spl: ext4fs_open failed\n" );
@@ -148,6 +151,7 @@ defaults:#endif return -1; } +#endif return 0 ; }
common/spl/spl_fat.c +5 -0
@@ -131,6 +131,7 @@ int spl_load_image_fat_os(struct spl_image_info *spl_image, goto defaults; } +#ifdef CONFIG_SPL_PAYLOAD_ARGS_ADDR file =env_get ("falcon_args_file" );if (file) { err = file_fat_read(
@@ -143,6 +144,8 @@ int spl_load_image_fat_os(struct spl_image_info *spl_image, return 0; }else puts ("spl: falcon_args_file not set in environment, falling back to default\n" ); +#endif + }else puts ("spl: falcon_image_file not set in environment, falling back to default\n" );
@@ -154,6 +157,7 @@ defaults:if (err)return err; +#ifdef CONFIG_SPL_PAYLOAD_ARGS_ADDR err =file_fat_read (CONFIG_SPL_FS_LOAD_ARGS_NAME , (void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR ,0 );if (err <=0 ) {
@@ -161,6 +165,7 @@ defaults: CONFIG_SPL_FS_LOAD_ARGS_NAME, err); return err; } +#endif return 0 ; }
common/spl/spl_nand.c +4 -1
@@ -79,7 +79,7 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,static int spl_nand_load_image_os (struct spl_image_info *spl_image,struct spl_boot_device *bootdev) { -int *src, *dst, err; +int err;struct legacy_img_hdr *header =spl_get_load_buffer (0 ,sizeof (*header));/* load linux */
@@ -102,6 +102,8 @@ static int spl_nand_load_image_os(struct spl_image_info *spl_image,if (err)return err; +#ifdef CONFIG_SPL_PAYLOAD_ARGS_ADDR +int *src, *dst;/* * load parameter image load to temp position since nand_spl_load_image * reads a whole block which is typically larger than
@@ -117,6 +119,7 @@ static int spl_nand_load_image_os(struct spl_image_info *spl_image, src++, dst++) {writel (readl (src), dst); } +#endif return 0 ; }
common/spl/spl_spi.c +5 -0
@@ -61,10 +61,15 @@ static int spl_spi_load_image_os(struct spl_image_info *spl_image,if (err)return err; +#ifdef CONFIG_SPL_PAYLOAD_ARGS_ADDR /* Read device tree. */ return spi_flash_read (flash,CONFIG_SYS_SPI_ARGS_OFFS ,CONFIG_SYS_SPI_ARGS_SIZE , (void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR ); +#else +return 0 ; +#endif + }#endif
common/spl/spl_ubi.c +4 -0
@@ -22,10 +22,14 @@ int spl_ubi_load_image_os(struct spl_image_info *spl_image, volumes[0 ].vol_id =CONFIG_SPL_UBI_LOAD_KERNEL_ID ; volumes[0 ].load_addr = (void *)CONFIG_SYS_LOAD_ADDR ; +#ifdef CONFIG_SPL_PAYLOAD_ARGS_ADDR volumes[1 ].vol_id =CONFIG_SPL_UBI_LOAD_ARGS_ID ; volumes[1 ].load_addr = (void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR ; err =ubispl_load_volumes (info, volumes,2 ); +#else + err =ubispl_load_volumes (info, volumes,1 ); +#endif if (err)return err;
include/system-constants.h +1 -1
@@ -37,7 +37,7 @@IF_ENABLED_INT (CONFIG_SPL_SYS_MALLOC ,CONFIG_SPL_SYS_MALLOC_SIZE ) /* deal with an optional value */ -#ifdef CONFIG_SPL_OS_BOOT +#ifdef CONFIG_SPL_PAYLOAD_ARGS_ADDR #define SPL_PAYLOAD_ARGS_ADDR CONFIG_SPL_PAYLOAD_ARGS_ADDR#else #define SPL_PAYLOAD_ARGS_ADDR 0
Signature · 1 line
2.51.0
Re: [PATCH RFT v1 14/17] spl: falcon: prevent loading args file in secure os boot
Quoted 11 lines · Anshul Dalal
The expected payload for the SPL in secure falcon mode is a fitImage that contains the kernel image and the DT. This removes the need to load an additional args file, which exposes an additional attack vector since it can not be verified.
Therefore this patch disables loading of the arg file when
SPL_OS_BOOT_SECUREis set.Signed-off-by Anshul Dalal <[email protected]>--- common/spl/Kconfig | 18 +++++++++++-------
I don't quite like how we're handling the "ARGS" part of this problem, and I think we need to clean that up first (which also means splitting this series up a bit). We should make having an "ARGS" CONFIG for any of the locations be optional as even non-secure use cases make use of FIT quite often. Then we make the "ARGS" options depend on !SPL_OS_BOOT_SECURE being set.
So the first series here would be the patches that make us consistently load kernel and then args as the first step. The second step in that series would be making args optional. The third step would be some of the related cleanups you're doing. The second series would be introducing SPL_OS_BOOT_SECURE and related. Thanks!
Signature · 1 line
Tom
PATCH 15/17 env: Kconfig: disable external env in secure os boot
In reply to Anshul DalalFalcon mode uses falcon_image_file from the env during mmc fs boot, but external env can be compromised. Therefore disable access to external env by setting SPL_ENV_IS_NOWHERE when SPL_OS_BOOT_SECURE is set.
--- env/Kconfig | 1 + 1 file changed, 1 insertion(+)
env/Kconfig +1 -0
@@ -827,6 +827,7 @@ if SPL_ENV_SUPPORT config SPL_ENV_IS_NOWHERE bool "SPL Environment is not stored" default y if ENV_IS_NOWHERE + default y if SPL_OS_BOOT_SECURE help Similar to ENV_IS_NOWHERE, used for SPL environment.
Signature · 1 line
2.51.0
Re: [PATCH RFT v1 15/17] env: Kconfig: disable external env in secure os boot
Quoted 14 lines · Anshul Dalal
Falcon mode uses
falcon_image_filefrom the env during mmc fs boot, but external env can be compromised. Therefore disable access to external env by settingSPL_ENV_IS_NOWHEREwhenSPL_OS_BOOT_SECUREis set.Signed-off-by Anshul Dalal <[email protected]>--- env/Kconfig | 1 + 1 file changed, 1 insertion(+)env/Kconfig +0
-0
env/Kconfig if SPL_ENV_SUPPORT · line 832
Quoted 6 lines
env/Kconfig +1
-0@@ -827,6 +827,7 @@ if SPL_ENV_SUPPORT config SPL_ENV_IS_NOWHERE bool "SPL Environment is not stored" default y if ENV_IS_NOWHERE + default y if SPL_OS_BOOT_SECURE help Similar to ENV_IS_NOWHERE, used for SPL environment.
You're going to need to do a bit more here on the symbols, this is the right default but you could still select other locations (so all of the SPL_ENV_... locations need a test on depends on .. && !SPL_OS_BOOT_SECURE too).
Signature · 1 line
Tom
PATCH 16/17 Kconfig: disable raw image boot in secure falcon mode
In reply to Anshul DalalCMD_BOOTI and CMD_BOOZ enable support for booting raw kernel images in falcon mode. This is insecure since raw images can not be authenticated, therefore disable those configs when SPL_OS_BOOT_SECURE is set.
--- boot/Kconfig | 4 ++-- cmd/Kconfig | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-)
boot/Kconfig +2 -2
@@ -422,8 +422,8 @@ config BOOT_DEFAULTS_CMDS select CMD_DHCP if CMD_NET select CMD_PING if CMD_NET select CMD_PXE if CMD_NET - select CMD_BOOTI if ARM64 - select CMD_BOOTZ if ARM && !ARM64 + select CMD_BOOTI if ARM64 && !SPL_OS_BOOT_SECURE + select CMD_BOOTZ if ARM && !ARM64 && !SPL_OS_BOOT_SECURE imply CMD_MII if NET config BOOT_DEFAULTS
cmd/Kconfig +2 -1
@@ -360,12 +360,13 @@ config BOOTM_ELF config CMD_BOOTZ bool "bootz" + depends on !SPL_OS_BOOT_SECURE help Boot the Linux zImage config CMD_BOOTI bool "booti" - depends on ARM64 || RISCV || SANDBOX + depends on (ARM64 || RISCV || SANDBOX) && !SPL_OS_BOOT_SECURE default y help Boot an AArch64 Linux Kernel image from memory.
Signature · 1 line
2.51.0
Re: [PATCH RFT v1 16/17] Kconfig: disable raw image boot in secure falcon mode
Quoted 34 lines · Anshul Dalal
CMD_BOOTIandCMD_BOOZenable support for booting raw kernel images in falcon mode. This is insecure since raw images can not be authenticated, therefore disable those configs whenSPL_OS_BOOT_SECUREis set.Signed-off-by Anshul Dalal <[email protected]>--- boot/Kconfig | 4 ++-- cmd/Kconfig | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-)boot/Kconfig +2
-2@@ -422,8 +422,8 @@ config BOOT_DEFAULTS_CMDS select CMD_DHCP if CMD_NET select CMD_PING if CMD_NET select CMD_PXE if CMD_NET - select CMD_BOOTI if ARM64 - select CMD_BOOTZ if ARM && !ARM64 + select CMD_BOOTI if ARM64 && !SPL_OS_BOOT_SECURE + select CMD_BOOTZ if ARM && !ARM64 && !SPL_OS_BOOT_SECURE imply CMD_MII if NET config BOOT_DEFAULTScmd/Kconfig +1
-0@@ -360,12 +360,13 @@ config BOOTM_ELF config CMD_BOOTZ bool "bootz" + depends on !SPL_OS_BOOT_SECURE
cmd/Kconfig config BOOTM_ELF · line 372
Quoted 10 lines
cmd/Kconfig +1
-1help Boot the Linux zImage config CMD_BOOTI bool "booti" - depends on ARM64 || RISCV || SANDBOX + depends on (ARM64 || RISCV || SANDBOX) && !SPL_OS_BOOT_SECURE default y help Boot an AArch64 Linux Kernel image from memory.
You need to think about this in another way, commands aren't present in SPL binaries. What's probably the best starting path is to ignore this particular problem, U-Boot has tons of security breaking options, and then a follow-up would be to figure out how to build (and also for binman/etc, package!) only SPL. Since really you don't want to flash a full U-Boot itself when falcon mode will panic if fail and not fall back to U-Boot.
Signature · 1 line
Tom
PATCH 17/17 arm: spl: use fdt addr if arg is unset in falcon mode
In reply to Anshul Dalalspl_image->arg is passed to the kernel as an argument in the x0 register. However in cases when the kernel is loaded from a FIT container along with a DT, the arg remains unset which leads to boot failure.
Therefore, this patch sets the arg to fdt address if it's null.
--- arch/arm/lib/spl.c | 2 ++ 1 file changed, 2 insertions(+)
arch/arm/lib/spl.c +2 -0
@@ -53,6 +53,8 @@ void __weak board_init_f(ulong dummy)#ifdef CONFIG_ARM64 void __noreturn jump_to_image_linux (struct spl_image_info *spl_image) { +if (!spl_image->arg) + spl_image->arg =spl_image_fdt_addr (spl_image);debug ("Entering kernel arg pointer: 0x%p\n" , spl_image->arg);cleanup_before_linux (); armv8_switch_to_el2((u64)spl_image->arg, 0, 0, 0,
Signature · 1 line
2.51.0
Re: [PATCH RFT v1 17/17] arm: spl: use fdt addr if arg is unset in falcon mode
Quoted 17 lines · Anshul Dalal
spl_image->argis passed to the kernel as an argument in the x0 register. However in cases when the kernel is loaded from a FIT container along with a DT, the arg remains unset which leads to boot failure.Therefore, this patch sets the arg to fdt address if it's null.
Signed-off-by Anshul Dalal <[email protected]>--- arch/arm/lib/spl.c | 2 ++ 1 file changed, 2 insertions(+)arch/arm/lib/spl.c +0
-0
arch/arm/lib/spl.c void __weak board_init_f(ulong dummy) · line 60
Quoted 8 lines
arch/arm/lib/spl.c +2
-0@@ -53,6 +53,8 @@ void __weak board_init_f(ulong dummy)#ifdef CONFIG_ARM64 void __noreturn jump_to_image_linux (struct spl_image_info *spl_image) { +if (!spl_image->arg) + spl_image->arg =spl_image_fdt_addr (spl_image);debug ("Entering kernel arg pointer: 0x%p\n" , spl_image->arg);cleanup_before_linux (); armv8_switch_to_el2((u64)spl_image->arg, 0, 0, 0,
This sounds like a standalone bugfix, that also needs to be more fully explained to make sure we're consistent about what we're doing. It might also be the case (I'm not sure without digging more!) that the caller in this case is in the wrong for having not set spl_image->arg already.
Signature · 1 line
Tom