kpatch-elf: Ensure stale references are not used

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>
This commit is contained in:
Julien Thierry 2019-10-09 11:25:27 +01:00
parent e0bd024c18
commit 770f529225

View File

@ -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));
@ -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);
}