Skip to contentSkip to conversation

xen: arm: correct off-by-one error in consider_modules

PATCH In review Ian Campbell 3 participants 6 messages Dec 21, 2014 – Jan 20, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen: arm: correct off-by-one error in consider_modules

By iterating up to <= mi->nr_mods we are running off the end of the boot modules, but more importantly it causes us to then skip the first FDT reserved region, meaning we might clobber it.

---
For 4.5: I think this bug fix should go in, it fixes a real issue and is low risk.

I'll also add to my list of things to consider for backport to 4.4.

---
 xen/arch/arm/setup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/setup.c +1 -1
index 3991d64..f49569d 100644
@@ -286,7 +286,7 @@ static paddr_t __init consider_modules(paddr_t s, paddr_t e,
         return 0;
 
     /* First check the boot modules */
-    for ( i = first_mod; i <= mi->nr_mods; i++ )
+    for ( i = first_mod; i < mi->nr_mods; i++ )
     {
         paddr_t mod_s = mi->module[i].start;
         paddr_t mod_e = mod_s + mi->module[i].size;
Signature · 1 line
2.1.3
Reviewed-by on v1 1/1
#1 lore raw

Hi Ian,

Quoted 3 lines · Ian Campbell

By iterating up to <= mi->nr_mods we are running off the end of the boot modules, but more importantly it causes us to then skip the first FDT reserved region, meaning we might clobber it.

Oops. Good catch!

OOI, how did you find it?

Quoted 1 line
Quoted 3 lines

---
For 4.5: I think this bug fix should go in, it fixes a real issue and is low risk.

Agreed.

Quoted 1 line

I'll also add to my list of things to consider for backport to 4.4.

Ditto.

Regards,

Signature · 1 line
Julien Grall
#2 lore raw
Quoted 10 lines · Julien Grall

Hi Ian,

Quoted 3 lines · Ian Campbell

By iterating up to <= mi->nr_mods we are running off the end of the boot modules, but more importantly it causes us to then skip the first FDT reserved region, meaning we might clobber it.

Oops. Good catch!

OOI, how did you find it?

U-boot on Jetson was locating the PSCI handling code at the top of RAM and reserving it in the DT, but Xen was still relocating itself over it, causing secondary CPU bringup to hang the board.

(This is an experimental u-boot, so it doesn't actually enforce the security of the PSCI region yet, if it did I'd have expected a fault on relocation instead of a hang on CPU up).

Ian.

#3 lore raw
In reply to Julien Grall
Quoted 7 lines · Julien Grall

Hi Ian,

Quoted 3 lines · Ian Campbell

By iterating up to <= mi->nr_mods we are running off the end of the boot modules, but more importantly it causes us to then skip the first FDT reserved region, meaning we might clobber it.

Quoted 11 lines

Oops. Good catch!

OOI, how did you find it?

Quoted 1 line
Quoted 3 lines

---
For 4.5: I think this bug fix should go in, it fixes a real issue and is low risk.

Quoted 11 lines

Agreed.

Quoted 1 line

I'll also add to my list of things to consider for backport to 4.4.

Ditto.

Regards,

Signature · 1 line
Julien Grall
author Applied
#4 lore raw
Quoted 14 lines · Konrad Rzeszutek Wilk
Quoted 13 lines · Julien Grall

Hi Ian,

Quoted 3 lines · Ian Campbell

By iterating up to <= mi->nr_mods we are running off the end of the boot modules, but more importantly it causes us to then skip the first FDT reserved region, meaning we might clobber it.

Oops. Good catch!

OOI, how did you find it?

Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

---
For 4.5: I think this bug fix should go in, it fixes a real issue and is low risk.

Applied, thanks.

#5 lore raw
In reply to Ian Campbell
Quoted 10 lines · Ian Campbell

By iterating up to <= mi->nr_mods we are running off the end of the boot modules, but more importantly it causes us to then skip the first FDT reserved region, meaning we might clobber it.

---
For 4.5: I think this bug fix should go in, it fixes a real issue and is low risk.

I'll also add to my list of things to consider for backport to 4.4.

In 4.4 nr_mods was, confusingly, the index of the highest mod present, not the nr. This changed in e73b7d6619c8 "xen: arm: store per-boot module type instead of relying on index", which is how this off by one came to be.

e73b7d6619c8 is not in 4.4, consequently I don't think it would be correct to backport this either.

Ian.

Quoted 17 lines
---
 xen/arch/arm/setup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/setup.c +1 -1
index 3991d64..f49569d 100644
@@ -286,7 +286,7 @@ static paddr_t __init consider_modules(paddr_t s, paddr_t e,
         return 0;
 
     /* First check the boot modules */
-    for ( i = first_mod; i <= mi->nr_mods; i++ )
+    for ( i = first_mod; i < mi->nr_mods; i++ )
     {
         paddr_t mod_s = mi->module[i].start;
         paddr_t mod_e = mod_s + mi->module[i].size;