From 5a6ddaad8d829d18e0b1ce31b99a029010a17395 Mon Sep 17 00:00:00 2001 From: Joe Lawrence Date: Tue, 13 Dec 2016 16:38:48 -0500 Subject: [PATCH 1/2] smatch: fix kpatch_shadow_alloc cleanup The error paths in kpatch_shadow_alloc do not free an allocated kpatch_shadow structure (and it's not added to the kpatch_shadow_hash). Handle the kfree in the various error return paths. Fixes the smatch warning: kmod/core/shadow.c:97 kpatch_shadow_alloc() warn: possible memory leak of 'shadow' --- kmod/core/shadow.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kmod/core/shadow.c b/kmod/core/shadow.c index 5b973c4..627928a 100644 --- a/kmod/core/shadow.c +++ b/kmod/core/shadow.c @@ -93,8 +93,10 @@ void *kpatch_shadow_alloc(void *obj, char *var, size_t size, gfp_t gfp) shadow->obj = obj; shadow->var = kstrdup(var, gfp); - if (!shadow->var) + if (!shadow->var) { + kfree(shadow); return NULL; + } if (size <= sizeof(shadow->data)) { shadow->data = &shadow->data; @@ -103,6 +105,7 @@ void *kpatch_shadow_alloc(void *obj, char *var, size_t size, gfp_t gfp) shadow->data = kmalloc(size, gfp); if (!shadow->data) { kfree(shadow->var); + kfree(shadow); return NULL; } } From 501a63ad6d0a14362d6674055a834635740197bd Mon Sep 17 00:00:00 2001 From: Joe Lawrence Date: Tue, 13 Dec 2016 16:53:52 -0500 Subject: [PATCH 2/2] smatch,sparse: trivial code cleanups Fixes smatch warning: kmod/core/core.c:64:1: warning: symbol 'kpmod_list' was not declared. Should it be static? Fixes sparse warnings: kmod/core/core.c:680 kpatch_write_relocations() warn: inconsistent indenting kmod/core/core.c:750 kpatch_write_relocations() warn: inconsistent indenting --- kmod/core/core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kmod/core/core.c b/kmod/core/core.c index adad44d..cbfffe8 100644 --- a/kmod/core/core.c +++ b/kmod/core/core.c @@ -66,7 +66,7 @@ static DEFINE_HASHTABLE(kpatch_func_hash, KPATCH_HASH_BITS); static DEFINE_SEMAPHORE(kpatch_mutex); -LIST_HEAD(kpmod_list); +static LIST_HEAD(kpmod_list); static int kpatch_num_patched; @@ -641,11 +641,11 @@ static int kpatch_write_relocations(struct kpatch_module *kpmod, ( LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0) && \ UTS_UBUNTU_RELEASE_ABI >= 7 ) \ ) - unsigned long core = (unsigned long)kpmod->mod->core_layout.base; - unsigned long core_size = kpmod->mod->core_layout.size; + unsigned long core = (unsigned long)kpmod->mod->core_layout.base; + unsigned long core_size = kpmod->mod->core_layout.size; #else - unsigned long core = (unsigned long)kpmod->mod->module_core; - unsigned long core_size = kpmod->mod->core_size; + unsigned long core = (unsigned long)kpmod->mod->module_core; + unsigned long core_size = kpmod->mod->core_size; #endif list_for_each_entry(dynrela, &object->dynrelas, list) {