From 23c232d3c198bf94a71a20b4d14c996037c74b36 Mon Sep 17 00:00:00 2001 From: chenzefeng Date: Mon, 3 Jun 2019 10:26:55 +0800 Subject: [PATCH] kpatch-elf: fix Segmentation fault when d_type not set properly kpatch-elf::create_section_pair would create new rela section, and the relasec->data->d_type is not set, which is a random value, and it will use in kpatch-elf::kpatch_write_output_elf data->d_type = sec->data->d_type; which would cause Segmentation fault in kpatch_write_output_elf::elf_update. Program received signal SIGSEGV, Segmentation fault. (gdb) bt 0 0x00007ffff7bcd8d2 in __elf64_updatefile at elf64_updatefile.c 1 0x00007ffff7bc9bed in write_file at elf_update.c 2 0x00007ffff7bc9f16 in elf_update at elf_update.c 3 0x000000000040ca3d in kpatch_write_output_elf at kpatch-elf.c 4 0x0000000000409a92 in main at create-diff-object.c Signed-off-by: chenzefeng --- 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 5802c46..7f90e36 100644 --- a/kpatch-build/kpatch-elf.c +++ b/kpatch-build/kpatch-elf.c @@ -647,6 +647,7 @@ struct section *create_section_pair(struct kpatch_elf *kelf, char *name, relasec->data = malloc(sizeof(*relasec->data)); if (!relasec->data) ERROR("malloc"); + relasec->data->d_type = ELF_T_RELA; /* set section header */ relasec->sh.sh_type = SHT_RELA;