From: Andrew Cooper Date: Mon, 28 Aug 2017 09:45:02 +0000 (+0200) Subject: xen/livepatch: Use zeroed memory allocations for arrays X-Git-Tag: RELEASE-4.8.2~9 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=68c4ef23e96e37ae1f10c34b7388e40fe07c880d;p=xen.git xen/livepatch: Use zeroed memory allocations for arrays Each of these arrays is sparse. Use zeroed allocations to cause uninitialised array elements to contain deterministic values, most importantly for the embedded pointers. Signed-off-by: Andrew Cooper Reviewed-by: Konrad Rzeszutek Wilk Tested-by: Konrad Rzeszutek Wilk [x86 and arm32] Reviewed-by: Ross Lagerwall master commit: bd53b85156aaf0330181ab9b82d9a6c52fb30f8c master date: 2017-06-23 15:00:37 +0100 --- diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c index 8aaaad289e..3a1a3db337 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -770,8 +770,8 @@ static int build_symbol_table(struct payload *payload, } } - symtab = xmalloc_array(struct livepatch_symbol, nsyms); - strtab = xmalloc_array(char, strtab_len); + symtab = xzalloc_array(struct livepatch_symbol, nsyms); + strtab = xzalloc_array(char, strtab_len); if ( !strtab || !symtab ) { diff --git a/xen/common/livepatch_elf.c b/xen/common/livepatch_elf.c index c4a9633078..b69e2718dd 100644 --- a/xen/common/livepatch_elf.c +++ b/xen/common/livepatch_elf.c @@ -52,7 +52,7 @@ static int elf_resolve_sections(struct livepatch_elf *elf, const void *data) int rc; /* livepatch_elf_load sanity checked e_shnum. */ - sec = xmalloc_array(struct livepatch_elf_sec, elf->hdr->e_shnum); + sec = xzalloc_array(struct livepatch_elf_sec, elf->hdr->e_shnum); if ( !sec ) { dprintk(XENLOG_ERR, LIVEPATCH"%s: Could not allocate memory for section table!\n", @@ -225,7 +225,7 @@ static int elf_get_sym(struct livepatch_elf *elf, const void *data) /* No need to check values as elf_resolve_sections did it. */ nsym = symtab_sec->sec->sh_size / symtab_sec->sec->sh_entsize; - sym = xmalloc_array(struct livepatch_elf_sym, nsym); + sym = xzalloc_array(struct livepatch_elf_sym, nsym); if ( !sym ) { dprintk(XENLOG_ERR, LIVEPATCH "%s: Could not allocate memory for symbols\n",