[RFC,06/11] Initialize reglocs for VMCOREINFO

Message ID 20230206222513.1773039-7-iii@linux.ibm.com
State Committed
Headers
Series Add Memory Sanitizer support |

Commit Message

Ilya Leoshkevich Feb. 6, 2023, 10:25 p.m. UTC
  MSan complains:

    Uninitialized value was created by an allocation of 'reglocs' in the stack frame
       #0 0x562d35c686f0 in handle_core_note elfutils/src/readelf.c:12674:3
       #const Ebl_Register_Location *reglocs;
    ==1006199==WARNING: MemorySanitizer: use-of-uninitialized-value
       #0 0x562d35c68a2a in handle_core_note elfutils/src/readelf.c:12692:11
       #colno = handle_core_registers (ebl, ebl->elf, desc + regs_offset,
       #                               reglocs, nregloc);

Strictly speaking, this is not a problem, because nregloc == 0, but for
other note types we initialize it anyway, so do it here as well.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 backends/linux-core-note.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Mark Wielaard Feb. 8, 2023, 5:27 p.m. UTC | #1
Hi Ilya,

On Mon, 2023-02-06 at 23:25 +0100, Ilya Leoshkevich via Elfutils-devel
wrote:
> MSan complains:
> 
>     Uninitialized value was created by an allocation of 'reglocs' in the stack frame
>        #0 0x562d35c686f0 in handle_core_note elfutils/src/readelf.c:12674:3
>        #const Ebl_Register_Location *reglocs;
>     ==1006199==WARNING: MemorySanitizer: use-of-uninitialized-value
>        #0 0x562d35c68a2a in handle_core_note elfutils/src/readelf.c:12692:11
>        #colno = handle_core_registers (ebl, ebl->elf, desc + regs_offset,
>        #                               reglocs, nregloc);
> 
> Strictly speaking, this is not a problem, because nregloc == 0, but for
> other note types we initialize it anyway, so do it here as well.

Yeah, this is something valgrind wouldn't complain about since it
doesn't see passing of an undefined value as "use". But I think msan is
technically correct that passing an indeterminate value to a function
provokes undefined behavior. Also it is of course more consistent with
the rest of the code which does initialize reglocs even when nregloc is
zero.

Pushed as is.

Thanks,

Mark


> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
>  backends/linux-core-note.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/backends/linux-core-note.c b/backends/linux-core-note.c
> index 9faae4c3..238ec16d 100644
> --- a/backends/linux-core-note.c
> +++ b/backends/linux-core-note.c
> @@ -239,6 +239,7 @@ EBLHOOK(core_note) (const GElf_Nhdr *nhdr, const char *name,
>  	return 0;
>        *regs_offset = 0;
>        *nregloc = 0;
> +      *reglocs = NULL;
>        *nitems = 1;
>        *items = vmcoreinfo_items;
>        return 1;
  

Patch

diff --git a/backends/linux-core-note.c b/backends/linux-core-note.c
index 9faae4c3..238ec16d 100644
--- a/backends/linux-core-note.c
+++ b/backends/linux-core-note.c
@@ -239,6 +239,7 @@  EBLHOOK(core_note) (const GElf_Nhdr *nhdr, const char *name,
 	return 0;
       *regs_offset = 0;
       *nregloc = 0;
+      *reglocs = NULL;
       *nitems = 1;
       *items = vmcoreinfo_items;
       return 1;