diff --git a/executer/include/uprotocol.h b/executer/include/uprotocol.h index e0506cb0..c8f43877 100644 --- a/executer/include/uprotocol.h +++ b/executer/include/uprotocol.h @@ -111,7 +111,10 @@ typedef unsigned long __cpu_set_unit; #define MPOL_NO_BSS 0x04 #define MPOL_SHM_PREMAP 0x08 +#define PLD_MAGIC 0xcafecafe44332211UL + struct program_load_desc { + unsigned long magic; int num_sections; int cpu; int pid; diff --git a/executer/user/mcexec.c b/executer/user/mcexec.c index dbf44fd7..e4a04048 100644 --- a/executer/user/mcexec.c +++ b/executer/user/mcexec.c @@ -276,6 +276,7 @@ struct program_load_desc *load_elf(FILE *fp, char **interp_pathp) + sizeof(struct program_image_section) * nhdrs); memset(desc, '\0', sizeof(struct program_load_desc) + sizeof(struct program_image_section) * nhdrs); + desc->magic = PLD_MAGIC; fseek(fp, hdr.e_phoff, SEEK_SET); j = 0; desc->num_sections = nhdrs; diff --git a/kernel/host.c b/kernel/host.c index 3b876661..3d59669c 100644 --- a/kernel/host.c +++ b/kernel/host.c @@ -441,6 +441,13 @@ static int process_msg_prepare_process(unsigned long rphys) return -ENOMEM; } + if (p->magic != PLD_MAGIC) { + kprintf("%s: broken mcexec program_load_desc\n", __func__); + ihk_mc_unmap_virtual(p, npages); + ihk_mc_unmap_memory(NULL, phys, sz); + return -EFAULT; + } + n = p->num_sections; if (n > 16 || 0 >= n) { kprintf("%s: ERROR: ELF sections other than 1 to 16 ??\n", diff --git a/kernel/include/syscall.h b/kernel/include/syscall.h index 6f4822b9..4fd5682f 100644 --- a/kernel/include/syscall.h +++ b/kernel/include/syscall.h @@ -174,7 +174,10 @@ typedef unsigned long __cpu_set_unit; #define MPOL_NO_BSS 0x04 #define MPOL_SHM_PREMAP 0x08 +#define PLD_MAGIC 0xcafecafe44332211UL + struct program_load_desc { + unsigned long magic; int num_sections; int cpu; int pid;