Skip to content

Commit

Permalink
kpatch-elf: Ensure stale references are not used
Browse files Browse the repository at this point in the history
When freeing a kpatch_elf, another object might have symbols and
sections twined with elements that are getting freed.

Clear the twin references, so if they are used after the object they
reference is freed, the program will crash.

Signed-off-by: Julien Thierry <jthierry@redhat.com>
  • Loading branch information
Julien Thierry committed Oct 29, 2019
1 parent e0bd024 commit 770f529
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions kpatch-build/kpatch-elf.c
Expand Up @@ -847,6 +847,8 @@ void kpatch_elf_teardown(struct kpatch_elf *kelf)
struct rela *rela, *saferela;

list_for_each_entry_safe(sec, safesec, &kelf->sections, list) {
if (sec->twin)
sec->twin->twin = NULL;
if (is_rela_section(sec)) {
list_for_each_entry_safe(rela, saferela, &sec->relas, list) {
memset(rela, 0, sizeof(*rela));
Expand All @@ -858,6 +860,8 @@ void kpatch_elf_teardown(struct kpatch_elf *kelf)
}

list_for_each_entry_safe(sym, safesym, &kelf->symbols, list) {
if (sym->twin)
sym->twin->twin = NULL;
memset(sym, 0, sizeof(*sym));
free(sym);
}
Expand Down

0 comments on commit 770f529

Please sign in to comment.