diff mbox

[for-4.9,v3,2/3] xen/livepatch: Use zeroed memory allocations for arrays

Message ID 1498155329-4752-3-git-send-email-andrew.cooper3@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Andrew Cooper June 22, 2017, 6:15 p.m. UTC
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 <andrew.cooper3@citrix.com>
---
CC: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
CC: Ross Lagerwall <ross.lagerwall@citrix.com>

* new in v3
---
 xen/common/livepatch.c     | 4 ++--
 xen/common/livepatch_elf.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

Comments

Konrad Rzeszutek Wilk June 23, 2017, 2:55 a.m. UTC | #1
On Thu, Jun 22, 2017 at 07:15:28PM +0100, Andrew Cooper wrote:
> 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 <andrew.cooper3@citrix.com>
> ---
> CC: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

Tested-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
[x86 and ARM32]
> CC: Ross Lagerwall <ross.lagerwall@citrix.com>
> 
> * new in v3
> ---
>  xen/common/livepatch.c     | 4 ++--
>  xen/common/livepatch_elf.c | 4 ++--
>  2 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c
> index df67a1a..66d532d 100644
> --- a/xen/common/livepatch.c
> +++ b/xen/common/livepatch.c
> @@ -771,8 +771,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 c4a9633..b69e271 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",
> -- 
> 2.1.4
>
Ross Lagerwall June 23, 2017, 12:31 p.m. UTC | #2
On 06/22/2017 07:15 PM, Andrew Cooper wrote:
> 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 <andrew.cooper3@citrix.com>

Reviewed-by: Ross Lagerwall <ross.lagerwall@citrix.com>
diff mbox

Patch

diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c
index df67a1a..66d532d 100644
--- a/xen/common/livepatch.c
+++ b/xen/common/livepatch.c
@@ -771,8 +771,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 c4a9633..b69e271 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",