Skip to contentSkip to conversation

spl: spl_legacy: Fix spl_end address

PATCH In review Fabio Estevam 2 participants 11 messages Jun 30, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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 = .
Fixes 77aed22b48ab ("spl: spl_legacy: Add extra address checks")

---
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
index d34bc5492e8d..095443c63d8d 100644
@@ -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
#1 lore raw
Quoted 25 lines · Fabio Estevam

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 = .
Fixes 77aed22b48ab ("spl: spl_legacy: Add extra address checks")
Quoted 7 lines

---
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.

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
Tested-by on v1 1/1
#2 lore raw
In reply to Fabio Estevam
Quoted 18 lines · Fabio Estevam

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:

Quoted 7 lines

.end
*(.__end)

                0x00000000009121a4                _image_binary_end = .
Fixes 77aed22b48ab ("spl: spl_legacy: Add extra address checks")

On mx6cuboxi,

Signature · 1 line
Tom
#3 lore raw
In reply to Fabio Estevam

common/spl/spl_legacy.c line 23

Quoted 11 lines · Fabio Estevam
common/spl/spl_legacy.c +1 -1
index d34bc5492e8d..095443c63d8d 100644
@@ -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) ||
#4 lore raw

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.

#5 lore raw
Quoted 1 line · Fabio Estevam

I tested this with CONFIG_SPL_SEPARATE_BSS=n and 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?

#6 lore raw
Quoted 26 lines · Fabio Estevam
Quoted 1 line · Fabio Estevam

I tested this with CONFIG_SPL_SEPARATE_BSS=n and 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;
+       }
 
Quoted 1 line

Does it look okay?

Probably? But have you thrown this at CI, or a world build?

Signature · 1 line
Tom
#9 lore raw
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;
#10 lore raw
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
index 306a4ddf3cd2..0787dfff8fb7 100644
@@ -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