Skip to contentSkip to conversation

spl: fix the new position of gd and stack

PATCH New Peng Donglin 1 participant 2 messages Oct 30, 2018 – Dec 27, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spl: fix the new position of gd and stack

If we enable CONFIG_SPL_SYS_MALLOC_SIMPLE and set CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN, the new gd and stack will inside malloc area,so there is a overwrite risk.

We can place the new position of gd and stack under the malloc area to fix this issue.

---
 common/spl/spl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
common/spl/spl.c +1 -1
index 292e659c9a..e85a153869 100644
@@ -628,7 +628,7 @@ ulong spl_relocate_stack_gd(void)
 	}
 #endif
 	/* Get stack position: use 8-byte alignment for ABI compliance */
-	ptr = CONFIG_SPL_STACK_R_ADDR - roundup(sizeof(gd_t),16);
+	ptr -= roundup(sizeof(gd_t), 16);
 	new_gd = (gd_t *)ptr;
 	memcpy(new_gd, (void *)gd, sizeof(gd_t));
 #if CONFIG_IS_ENABLED(DM)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 spl: fix the new position of gd and stack

Quoted 27 lines · Peng Donglin

If we enable CONFIG_SPL_SYS_MALLOC_SIMPLE and set CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN, the new gd and stack will inside malloc area,so there is a overwrite risk.

We can place the new position of gd and stack under the malloc area to fix this issue.

---
 common/spl/spl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
common/spl/spl.c +1 -2
index 292e659c9a..e85a153869 100644
@@ -628,7 +628,7 @@ ulong spl_relocate_stack_gd(void)
        }
 #endif
        /* Get stack position: use 8-byte alignment for ABI compliance */
-       ptr = CONFIG_SPL_STACK_R_ADDR - roundup(sizeof(gd_t),16);
+       ptr -= roundup(sizeof(gd_t), 16);
        new_gd = (gd_t *)ptr;
        memcpy(new_gd, (void *)gd, sizeof(gd_t));
 #if CONFIG_IS_ENABLED(DM)
--
Quoted 2 lines

2.17.1

any suggestion?