From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ozlabs.org ([103.22.144.67]:38023 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752578AbdBKJJA (ORCPT ); Sat, 11 Feb 2017 04:09:00 -0500 From: Rusty Russell To: "Luis R. Rodriguez" , jeyu@redhat.com Cc: mbenes@suse.cz, atomlin@redhat.com, pmladek@suse.com, hare@suse.com, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, "Luis R. Rodriguez" , "stable # v2 . 6 . 30" Subject: Re: [PATCH] module: fix memory leak on early load_module() failures In-Reply-To: <20170210220622.5220-1-mcgrof@kernel.org> References: <20170210220622.5220-1-mcgrof@kernel.org> Date: Sat, 11 Feb 2017 19:28:58 +1030 Message-ID: <874m01rtm5.fsf@rustcorp.com.au> MIME-Version: 1.0 Content-Type: text/plain Sender: stable-owner@vger.kernel.org List-ID: "Luis R. Rodriguez" writes: > While looking for early possible module loading failures I was > able to reproduce a memory leak possible with kmemleak. There > are a few rare ways to trigger a failure: > > o we've run into a failure while processing kernel parameters > (parse_args() returns an error) > o mod_sysfs_setup() fails > o we're a live patch module and copy_module_elf() fails > > Chances of running into this issue is really low. Good catch! Reviewed-by: Rusty Russell Cheers, Rusty. > > kmemleak splat: > > unreferenced object 0xffff9f2c4ada1b00 (size 32): > comm "kworker/u16:4", pid 82, jiffies 4294897636 (age 681.816s) > hex dump (first 32 bytes): > 6d 65 6d 73 74 69 63 6b 30 00 00 00 00 00 00 00 memstick0....... > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ > backtrace: > [] kmemleak_alloc+0x4a/0xa0 > [] __kmalloc_track_caller+0x126/0x230 > [] kstrdup+0x31/0x60 > [] kstrdup_const+0x24/0x30 > [] kvasprintf_const+0x7a/0x90 > [] kobject_set_name_vargs+0x21/0x90 > [] dev_set_name+0x47/0x50 > [] memstick_check+0x95/0x33c [memstick] > [] process_one_work+0x1f3/0x4b0 > [] worker_thread+0x48/0x4e0 > [] kthread+0xc9/0xe0 > [] ret_from_fork+0x1f/0x40 > [] 0xffffffffffffffff > > Cc: stable # v2.6.30 > Fixes: e180a6b7759a ("param: fix charp parameters set via sysfs") > Reviewed-by: Miroslav Benes > Reviewed-by: Aaron Tomlin > Signed-off-by: Luis R. Rodriguez > --- > kernel/module.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/kernel/module.c b/kernel/module.c > index 38d4270925d4..8409a82424d2 100644 > --- a/kernel/module.c > +++ b/kernel/module.c > @@ -3722,6 +3722,7 @@ static int load_module(struct load_info *info, const char __user *uargs, > mod_sysfs_teardown(mod); > coming_cleanup: > mod->state = MODULE_STATE_GOING; > + destroy_params(mod->kp, mod->num_kp); > blocking_notifier_call_chain(&module_notify_list, > MODULE_STATE_GOING, mod); > klp_module_going(mod); > -- > 2.10.2