linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] module: fix memory leak on early load_module() failures
@ 2017-02-10 22:06 Luis R. Rodriguez
  2017-02-11  8:58 ` Rusty Russell
  2017-02-13 18:33 ` Jessica Yu
  0 siblings, 2 replies; 3+ messages in thread
From: Luis R. Rodriguez @ 2017-02-10 22:06 UTC (permalink / raw)
  To: jeyu, rusty
  Cc: mbenes, atomlin, pmladek, hare, akpm, linux-kernel,
	Luis R. Rodriguez, stable # v2 . 6 . 30

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.

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:
    [<ffffffff8c6cfeba>] kmemleak_alloc+0x4a/0xa0
    [<ffffffff8c200046>] __kmalloc_track_caller+0x126/0x230
    [<ffffffff8c1bc581>] kstrdup+0x31/0x60
    [<ffffffff8c1bc5d4>] kstrdup_const+0x24/0x30
    [<ffffffff8c3c23aa>] kvasprintf_const+0x7a/0x90
    [<ffffffff8c3b5481>] kobject_set_name_vargs+0x21/0x90
    [<ffffffff8c4fbdd7>] dev_set_name+0x47/0x50
    [<ffffffffc07819e5>] memstick_check+0x95/0x33c [memstick]
    [<ffffffff8c09c893>] process_one_work+0x1f3/0x4b0
    [<ffffffff8c09cb98>] worker_thread+0x48/0x4e0
    [<ffffffff8c0a2b79>] kthread+0xc9/0xe0
    [<ffffffff8c6dab5f>] ret_from_fork+0x1f/0x40
    [<ffffffffffffffff>] 0xffffffffffffffff

Cc: stable <stable@vger.kernel.org> # v2.6.30
Fixes: e180a6b7759a ("param: fix charp parameters set via sysfs")
Reviewed-by: Miroslav Benes <mbenes@suse.cz>
Reviewed-by: Aaron Tomlin <atomlin@redhat.com>
Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] module: fix memory leak on early load_module() failures
  2017-02-10 22:06 [PATCH] module: fix memory leak on early load_module() failures Luis R. Rodriguez
@ 2017-02-11  8:58 ` Rusty Russell
  2017-02-13 18:33 ` Jessica Yu
  1 sibling, 0 replies; 3+ messages in thread
From: Rusty Russell @ 2017-02-11  8:58 UTC (permalink / raw)
  To: Luis R. Rodriguez, jeyu
  Cc: mbenes, atomlin, pmladek, hare, akpm, linux-kernel,
	Luis R. Rodriguez, stable # v2 . 6 . 30

"Luis R. Rodriguez" <mcgrof@kernel.org> 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 <rusty@rustcorp.com.au>

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:
>     [<ffffffff8c6cfeba>] kmemleak_alloc+0x4a/0xa0
>     [<ffffffff8c200046>] __kmalloc_track_caller+0x126/0x230
>     [<ffffffff8c1bc581>] kstrdup+0x31/0x60
>     [<ffffffff8c1bc5d4>] kstrdup_const+0x24/0x30
>     [<ffffffff8c3c23aa>] kvasprintf_const+0x7a/0x90
>     [<ffffffff8c3b5481>] kobject_set_name_vargs+0x21/0x90
>     [<ffffffff8c4fbdd7>] dev_set_name+0x47/0x50
>     [<ffffffffc07819e5>] memstick_check+0x95/0x33c [memstick]
>     [<ffffffff8c09c893>] process_one_work+0x1f3/0x4b0
>     [<ffffffff8c09cb98>] worker_thread+0x48/0x4e0
>     [<ffffffff8c0a2b79>] kthread+0xc9/0xe0
>     [<ffffffff8c6dab5f>] ret_from_fork+0x1f/0x40
>     [<ffffffffffffffff>] 0xffffffffffffffff
>
> Cc: stable <stable@vger.kernel.org> # v2.6.30
> Fixes: e180a6b7759a ("param: fix charp parameters set via sysfs")
> Reviewed-by: Miroslav Benes <mbenes@suse.cz>
> Reviewed-by: Aaron Tomlin <atomlin@redhat.com>
> Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
> ---
>  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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: module: fix memory leak on early load_module() failures
  2017-02-10 22:06 [PATCH] module: fix memory leak on early load_module() failures Luis R. Rodriguez
  2017-02-11  8:58 ` Rusty Russell
@ 2017-02-13 18:33 ` Jessica Yu
  1 sibling, 0 replies; 3+ messages in thread
From: Jessica Yu @ 2017-02-13 18:33 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: rusty, mbenes, atomlin, pmladek, hare, akpm, linux-kernel,
	stable # v2 . 6 . 30

+++ Luis R. Rodriguez [10/02/17 14:06 -0800]:
>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.
>
>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:
>    [<ffffffff8c6cfeba>] kmemleak_alloc+0x4a/0xa0
>    [<ffffffff8c200046>] __kmalloc_track_caller+0x126/0x230
>    [<ffffffff8c1bc581>] kstrdup+0x31/0x60
>    [<ffffffff8c1bc5d4>] kstrdup_const+0x24/0x30
>    [<ffffffff8c3c23aa>] kvasprintf_const+0x7a/0x90
>    [<ffffffff8c3b5481>] kobject_set_name_vargs+0x21/0x90
>    [<ffffffff8c4fbdd7>] dev_set_name+0x47/0x50
>    [<ffffffffc07819e5>] memstick_check+0x95/0x33c [memstick]
>    [<ffffffff8c09c893>] process_one_work+0x1f3/0x4b0
>    [<ffffffff8c09cb98>] worker_thread+0x48/0x4e0
>    [<ffffffff8c0a2b79>] kthread+0xc9/0xe0
>    [<ffffffff8c6dab5f>] ret_from_fork+0x1f/0x40
>    [<ffffffffffffffff>] 0xffffffffffffffff
>
>Cc: stable <stable@vger.kernel.org> # v2.6.30
>Fixes: e180a6b7759a ("param: fix charp parameters set via sysfs")
>Reviewed-by: Miroslav Benes <mbenes@suse.cz>
>Reviewed-by: Aaron Tomlin <atomlin@redhat.com>
>Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>

Pushed out. Thanks Luis!

>---
> 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
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-02-13 18:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-10 22:06 [PATCH] module: fix memory leak on early load_module() failures Luis R. Rodriguez
2017-02-11  8:58 ` Rusty Russell
2017-02-13 18:33 ` Jessica Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).