From 3998784d71068e3427815d620c38fdc573204b4f Mon Sep 17 00:00:00 2001 From: Balbir singh Date: Thu, 17 Jan 2019 19:53:46 +1100 Subject: [PATCH] Fix NULL pointer deref in main due to base_locals For fun I tried to create a livepatch of upstream patch ad211f3e94b314a910d4af03178a0b52a7d1ee0a for my kernel. This caused kpatch-build to fail with a NULL pointer derefence because base_locals was NULL (returned via kpatch_elf_locals(), which can return a NULL pointer). This patch fixes the SIGSEGV via a NULL check. The end result is a live patch is created and loaded. Signed-off-by: Balbir singh --- kpatch-build/create-diff-object.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c index e167890..7a4dbfe 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c @@ -3332,7 +3332,7 @@ int main(int argc, char *argv[]) /* create symbol lookup table */ lookup = lookup_open(parent_symtab, mod_symvers, hint, base_locals); - for (sym_comp = base_locals; sym_comp->name; sym_comp++) { + for (sym_comp = base_locals; sym_comp && sym_comp->name; sym_comp++) { free(sym_comp->name); } free(base_locals);