kpatch-elf: fix null dereference when sym->sec is NULL

Make sure sym->sec is not NULL before checking for its rela section
(sym->sec->rela). This fixes a case where an object may have STT_FUNC
symbols whose the sections (sym->sec) were not selected for inclusion (or
are located in another object) and hence these symbols do not have sym->sec
set. This corner case only recently popped up after reusing kpatch_elf_open()
on objects that have been outputted by create-diff-object (and these
objects only contain the necessary sections needed for the patch module).

This will also automatically exclude livepatch symbols from the check,
because they do not have sections associated with them (i.e., sym->sec is
NULL). We do not have to check for fentry calls for klp (SHN_LIVEPATCH)
symbols, because [1] they do not have sections associated with them, [2]
they are not the target functions to be patched, and [3] they are
technically just placeholder symbols for symbol resolution in livepatch.
This commit is contained in:
Jessica Yu 2017-01-23 12:42:56 -08:00
parent 91909e9273
commit a3108de96a
1 changed files with 1 additions and 1 deletions

View File

@ -341,7 +341,7 @@ static void kpatch_find_fentry_calls(struct kpatch_elf *kelf)
struct symbol *sym;
struct rela *rela;
list_for_each_entry(sym, &kelf->symbols, list) {
if (sym->type != STT_FUNC || !sym->sec->rela)
if (sym->type != STT_FUNC || !sym->sec || !sym->sec->rela)
continue;
rela = list_first_entry(&sym->sec->rela->relas, struct rela,