diff mbox series

[v4,20/21] sandbox: Always allocate aligned buffers

Message ID 20180618152315.34233-21-agraf@suse.de
State New
Headers show
Series sandbox: efi_loader support | expand

Commit Message

Alexander Graf June 18, 2018, 3:23 p.m. UTC
In some code paths we check whether host virtual addresses are sane.
That only works if at least alignments between host and U-Boot address
spaces match.

So let's always map U-Boot addresses with 64kb alignment. That should
be enough to ensure that the actual RAM ends up in a different page
from the header on all architectures.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 arch/sandbox/cpu/os.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 9fa79a8843..4dc6483922 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -143,14 +143,15 @@  void os_tty_raw(int fd, bool allow_sigs)
 void *os_malloc(size_t length)
 {
 	struct os_mem_hdr *hdr;
+	size_t alloc_length = length + (64 * 1024);
 
-	hdr = mmap(NULL, length + sizeof(*hdr), PROT_READ | PROT_WRITE,
+	hdr = mmap(NULL, alloc_length, PROT_READ | PROT_WRITE,
 		   MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 	if (hdr == MAP_FAILED)
 		return NULL;
 	hdr->length = length;
 
-	return hdr + 1;
+	return (void*)hdr + (64 * 1024);
 }
 
 void os_free(void *ptr)