From 321bbf941768011c08898517171bc71fe03f2323 Mon Sep 17 00:00:00 2001 From: Joe Lawrence Date: Tue, 3 Oct 2017 16:36:19 -0400 Subject: [PATCH] kpatch-build: clear Elf_Data d_buf buffer on allocation Valgrind complains about uninitialized bytes passed to pwrite64(buf) from kpatch_write_output_elf()'s call to elf_update(): ==32378== Syscall param pwrite64(buf) points to uninitialised byte(s) ==32378== at 0x5141A03: __pwrite_nocancel (in /usr/lib64/libc-2.23.so) ==32378== by 0x4E46846: ??? (in /usr/lib64/libelf-0.168.so) ==32378== by 0x4E42B88: elf_update (in /usr/lib64/libelf-0.168.so) ==32378== by 0x40C57A: kpatch_write_output_elf (kpatch-elf.c:895) ==32378== by 0x40926F: main (create-diff-object.c:2851) ==32378== Address 0x28d52300 is 0 bytes inside a block of size 56 alloc'd ==32378== at 0x4C2BBAD: malloc (vg_replace_malloc.c:299) ==32378== by 0x40B86A: create_section_pair (kpatch-elf.c:707) ==32378== by 0x406CAE: kpatch_create_patches_sections (create-diff-object.c:2109) ==32378== by 0x4090C5: main (create-diff-object.c:2815) These are fields which we don't need to populate (like a funcs[index].new_addr value that will be filled by relocation). The easiest way to appease valgrind and not clutter the code is to just zero-out this entire buffer on allocation. Signed-off-by: Joe Lawrence --- kpatch-build/kpatch-elf.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kpatch-build/kpatch-elf.c b/kpatch-build/kpatch-elf.c index 54abad3..7b79dd3 100644 --- a/kpatch-build/kpatch-elf.c +++ b/kpatch-build/kpatch-elf.c @@ -626,6 +626,7 @@ struct section *create_section_pair(struct kpatch_elf *kelf, char *name, sec->data->d_buf = malloc(size); if (!sec->data->d_buf) ERROR("malloc"); + memset(sec->data->d_buf, 0, size); sec->data->d_size = size; sec->data->d_type = ELF_T_BYTE;