spl: spl_legacy: Fix spl_end address
Subsystems (2)
PATCH 1/1 spl: spl_legacy: Fix spl_end address
From: Fabio Estevam <[email protected]>
Currently, spl_end points to the __bss_end address, which is an external RAM address instead of the end of the SPL text section in the internal RAM.
This causes boot failures on imx6-colibri, for example:
``` Trying to boot from MMC1 SPL: Image overlaps SPL resetting ... ```
Fix this problem by assigning spl_end to the _image_binary_end, as this symbol properly represents the end of the SPL text section.
From u-boot-spl.map:
.end
*(.__end)
0x00000000009121a4 _image_binary_end = .
---
Tom,
As 2023.07 is coming in a few days, maybe it is safer to revert 77aed22b48ab in master and then squash 77aed22b48ab + this fix to next.
77aed22b48ab has been applied to 2023.07-rc5, which is too late in the cycle.
common/spl/spl_legacy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
common/spl/spl_legacy.c +1 -1
@@ -19,7 +19,7 @@static void spl_parse_legacy_validate (uintptr_t start,uintptr_t size) {uintptr_t spl_start = (uintptr_t )_start; -uintptr_t spl_end = (uintptr_t )__bss_end; +uintptr_t spl_end = (uintptr_t )_image_binary_end;uintptr_t end = start + size; if ((start >= spl_start && start < spl_end) ||
Signature · 1 line
2.34.1
Quoted 25 lines · Fabio Estevam
From: Fabio Estevam <[email protected]>
Currently,
spl_endpoints to the__bss_endaddress, which is an external RAM address instead of the end of the SPL text section in the internal RAM.This causes boot failures on imx6-colibri, for example:
``` Trying to boot from MMC1 SPL: Image overlaps SPL resetting ... ```Fix this problem by assigning
spl_endto the_image_binary_end, as this symbol properly represents the end of the SPL text section.From u-boot-spl.map:
.end
*(.__end)0x00000000009121a4 _image_binary_end = .Fixes 77aed22b48ab ("spl: spl_legacy: Add extra address checks")Reported-by Francesco Dolcini <[email protected]>Signed-off-by Fabio Estevam <[email protected]>
Quoted 7 lines
---
Tom,As 2023.07 is coming in a few days, maybe it is safer to revert
77aed22b48abin master and then squash77aed22b48ab+ this fix to next.
77aed22b48abhas been applied to 2023.07-rc5, which is too late in the cycle.
I want to see what Marek says about which changes are the most critical for the security issue aspect of this and then figure out what's next.
Signature · 1 line
Tom
Quoted 18 lines · Fabio Estevam
From: Fabio Estevam <[email protected]>
Currently,
spl_endpoints to the__bss_endaddress, which is an external RAM address instead of the end of the SPL text section in the internal RAM.This causes boot failures on imx6-colibri, for example:
``` Trying to boot from MMC1 SPL: Image overlaps SPL resetting ... ```Fix this problem by assigning
spl_endto the_image_binary_end, as this symbol properly represents the end of the SPL text section.From u-boot-spl.map:
Quoted 7 lines
.end
*(.__end)0x00000000009121a4 _image_binary_end = .Fixes 77aed22b48ab ("spl: spl_legacy: Add extra address checks")Reported-by Francesco Dolcini <[email protected]>Signed-off-by Fabio Estevam <[email protected]>
On mx6cuboxi,
Signature · 1 line
Tom
common/spl/spl_legacy.c line 23
Quoted 11 lines · Fabio Estevam
common/spl/spl_legacy.c +1
-1@@ -19,7 +19,7 @@static void spl_parse_legacy_validate (uintptr_t start,uintptr_t size) {uintptr_t spl_start = (uintptr_t )_start; -uintptr_t spl_end = (uintptr_t )__bss_end; +uintptr_t spl_end = (uintptr_t )_image_binary_end;uintptr_t end = start + size;
I have been thinking more about this and it seems we need to take CONFIG_SPL_SEPARATE_BSS
into account.
Should we do this instead?
common/spl/spl_legacy.c +6 -1
@@ -19,9 +19,14 @@static void spl_parse_legacy_validate (uintptr_t start,uintptr_t size) {uintptr_t spl_start = (uintptr_t )_start; -uintptr_t spl_end = (uintptr_t )__bss_end; +uintptr_t spl_end;uintptr_t end = start + size; +if (IS_ENABLED (CONFIG_SPL_SEPARATE_BSS )) + spl_end = (uintptr_t )_image_binary_end; +else + spl_end = (uintptr_t )__bss_end; + if ((start >= spl_start && start < spl_end) || (end > spl_start && end <= spl_end) || (start < spl_start && end >= spl_end) ||
common/spl/spl_legacy.c line 29
Quoted 5 lines · Fabio Estevam
common/spl/spl_legacy.c +5
-0+if (IS_ENABLED (CONFIG_SPL_SEPARATE_BSS )) + spl_end = (uintptr_t )_image_binary_end; +else + spl_end = (uintptr_t )__bss_end; +
I tested this with CONFIG_SPL_SEPARATE_BSS=n and it failed.
The original patch works fine on both cases for me.
Quoted 1 line · Fabio Estevam
I tested this with
CONFIG_SPL_SEPARATE_BSS=nand it failed.
Tested this one with CONFIG_SPL_SEPARATE_BSS enabled and disabled:
common/spl/spl_legacy.c +10 -2
@@ -18,9 +18,17 @@static void spl_parse_legacy_validate (uintptr_t start,uintptr_t size) { -uintptr_t spl_start = (uintptr_t )_start; -uintptr_t spl_end = (uintptr_t )__bss_end;uintptr_t end = start + size; +uintptr_t spl_start; +uintptr_t spl_end; + +if (IS_ENABLED (CONFIG_SPL_SEPARATE_BSS )) { + spl_start = (uintptr_t )_start; + spl_end = (uintptr_t )_image_binary_end; + }else { + spl_start = (uintptr_t )__bss_start; + spl_end = (uintptr_t )__bss_end; + }
Does it look okay?
Quoted 26 lines · Fabio Estevam
Quoted 1 line · Fabio Estevam
I tested this with
CONFIG_SPL_SEPARATE_BSS=nand it failed.Tested this one with
CONFIG_SPL_SEPARATE_BSSenabled and disabled:common/spl/spl_legacy.c +10
-2@@ -18,9 +18,17 @@static void spl_parse_legacy_validate (uintptr_t start,uintptr_t size) { -uintptr_t spl_start = (uintptr_t )_start; -uintptr_t spl_end = (uintptr_t )__bss_end;uintptr_t end = start + size; +uintptr_t spl_start; +uintptr_t spl_end; + +if (IS_ENABLED (CONFIG_SPL_SEPARATE_BSS )) { + spl_start = (uintptr_t )_start; + spl_end = (uintptr_t )_image_binary_end; + }else { + spl_start = (uintptr_t )__bss_start; + spl_end = (uintptr_t )__bss_end; + }
Quoted 1 line
Does it look okay?
Probably? But have you thrown this at CI, or a world build?
Signature · 1 line
Tom
Quoted 1 line · Tom Rini
Probably? But have you thrown this at CI, or a world build?
I threw this at CI, but it failed at test.py qemu_m68k:
https://github.com/u-boot/u-boot/pull/327#partial-pull-merging
Quoted 7 lines · Fabio Estevam
Quoted 1 line · Tom Rini
Probably? But have you thrown this at CI, or a world build?
I threw this at CI, but it failed at
test.pyqemu_m68k:https://github.com/u-boot/u-boot/pull/327#partial-pull-merging
Yeah, just hit re-run when that happens, sadly.
Signature · 1 line
Tom
Quoted 1 line · Tom Rini
Yeah, just hit re-run when that happens, sadly.
Ok, only sunxi failed.
If I try:
arch/arm/cpu/arm926ejs/sunxi/u-boot-spl.lds +2 -0
@@ -37,6 +37,8 @@ SECTIONS __image_copy_end = .; _end = .; + _image_binary_end = .; + .bss : { . = ALIGN(4);
(quoted diff) +0 -0
b/arch/arm/cpu/armv7/sunxi/u-boot-spl.lds
index 306a4ddf3cd2..0787dfff8fb7 100644
arch/arm/cpu/armv7/sunxi/u-boot-spl.lds +2 -0
@@ -46,6 +46,8 @@ SECTIONS __image_copy_end = .; _end = .; + _image_binary_end = .; + .bss : { . = ALIGN(4);
Then it builds fine.
I am thinking of sending the sunxi lds change as part of a series in v2.
So v2 would become:
1/2: the sunxi lds change above
2/2 the original patch:
common/spl/spl_legacy.c +1 -1
@@ -19,7 +19,7 @@static void spl_parse_legacy_validate (uintptr_t start,uintptr_t size) {uintptr_t spl_start = (uintptr_t )_start; -uintptr_t spl_end = (uintptr_t )__bss_end; +uintptr_t spl_end = (uintptr_t )_image_binary_end;uintptr_t end = start + size;
Quoted 47 lines · Fabio Estevam
Quoted 1 line · Tom Rini
Yeah, just hit re-run when that happens, sadly.
Ok, only sunxi failed.
If I try:
arch/arm/cpu/arm926ejs/sunxi/u-boot-spl.lds +2
-0@@ -37,6 +37,8 @@ SECTIONS __image_copy_end = .; _end = .; + _image_binary_end = .; + .bss : { . = ALIGN(4);arch/arm/cpu/armv7/sunxi/u-boot-spl.lds +2
-0@@ -46,6 +46,8 @@ SECTIONS __image_copy_end = .; _end = .; + _image_binary_end = .; + .bss : { . = ALIGN(4);Then it builds fine.
I am thinking of sending the sunxi lds change as part of a series in v2.
So v2 would become:
1/2: the sunxi lds change above
2/2 the original patch:
common/spl/spl_legacy.c line 23
Quoted 6 lines
common/spl/spl_legacy.c +1
-1@@ -19,7 +19,7 @@static void spl_parse_legacy_validate (uintptr_t start,uintptr_t size) {uintptr_t spl_start = (uintptr_t )_start; -uintptr_t spl_end = (uintptr_t )__bss_end; +uintptr_t spl_end = (uintptr_t )_image_binary_end;uintptr_t end = start + size;
Sounds good.
Signature · 1 line
Tom