Skip to contentSkip to conversation

hvmloader: Fix scratch_alloc to avoid overlaps

PATCH Superseded Anthony PERARD 1 participant 1 message Feb 9, 2016

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 hvmloader: Fix scratch_alloc to avoid overlaps

scratch_alloc() set scratch_start to the last byte of the current allocation. The value of scratch_start is then reused as is (if it is already aligned) in the next allocation. This result in a potential reuse of the last byte of the previous allocation.

---
Change in v3:
- change to be similair to mem_alloc()

---
 tools/firmware/hvmloader/util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/firmware/hvmloader/util.c +1 -1
index d779fd7..9382709 100644
@@ -478,7 +478,7 @@ void *scratch_alloc(uint32_t size, uint32_t align)
     if ( align < 16 )
         align = 16;
 
-    s = (scratch_start + align - 1) & ~(align - 1);
+    s = (scratch_start + align) & ~(align - 1);
     e = s + size - 1;
 
     BUG_ON(e < s);
Signature · 1 line
Anthony PERARD