From: David van Moolenbroek Date: Thu, 3 Sep 2015 10:09:54 +0000 (+0200) Subject: VM/VFS: align ELF header buffer X-Git-Url: http://zhaoyanbai.com/repos/%22http:/static/doc/zpipe.c?a=commitdiff_plain;h=refs%2Fchanges%2F70%2F3170%2F1;p=minix.git VM/VFS: align ELF header buffer The libexec ELF parser expects to be given a word-aligned buffer, but the ASR pass may cause VM and VFS to pass it an arbitrarily aligned buffer, causing libexec to refuse loading the executable. This patch aligns the buffers explicitly. Change-Id: Ic2d5fd3a8f204c3e4f000cffdb7ac71c8339257a --- diff --git a/minix/servers/vfs/exec.c b/minix/servers/vfs/exec.c index 90e19c057..6d105e2de 100644 --- a/minix/servers/vfs/exec.c +++ b/minix/servers/vfs/exec.c @@ -740,7 +740,12 @@ static int map_header(struct vfs_exec_info *execi) int r; size_t cum_io; off_t pos, new_pos; - static char hdr[PAGE_SIZE]; /* Assume that header is not larger than a page */ + /* Assume that header is not larger than a page. Align the buffer reasonably + * well, because libexec casts it to a structure directly and therefore + * expects it to be aligned appropriately. From here we can only guess the + * proper alignment, but 64 bits should work for all versions of ELF.. + */ + static char hdr[PAGE_SIZE] __aligned(8); pos = 0; /* Read from the start of the file */ diff --git a/minix/servers/vm/main.c b/minix/servers/vm/main.c index b6b305698..884fb43e1 100644 --- a/minix/servers/vm/main.c +++ b/minix/servers/vm/main.c @@ -333,7 +333,8 @@ static void exec_bootproc(struct vmproc *vmp, struct boot_image *ip) { struct vm_exec_info vmexeci; struct exec_info *execi = &vmexeci.execi; - char hdr[VM_PAGE_SIZE]; + /* libexec need proper alignment for casting to structures */ + char hdr[VM_PAGE_SIZE] __aligned(8); size_t frame_size = 0; /* Size of the new initial stack. */ int argc = 0; /* Argument count. */