From: David Woodhouse <dwmw2@infradead.org>
To: "rusty@rustcorp.com.au" <rusty@rustcorp.com.au>
Cc: "arjun024@gmail.com" <arjun024@gmail.com>,
"torvalds@linux-foundation.org" <torvalds@linux-foundation.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"jg1.han@samsung.com" <jg1.han@samsung.com>,
"akpm@linux-foundation.org" <akpm@linux-foundation.org>
Subject: Re: [PATCH] params: fix potential memory leak in add_sysfs_param()
Date: Wed, 20 Aug 2014 18:10:14 -0500 [thread overview]
Message-ID: <1408576214.9540.2.camel@infradead.org> (raw)
In-Reply-To: <1408573066.9484.11.camel@intel.com>
[-- Attachment #1: Type: text/plain, Size: 1317 bytes --]
On Wed, 2014-08-20 at 22:17 +0000, Woodhouse, David wrote:
>
> Except that in the failure case we *free* the old mk->mp and never free
> mk->mp->grp.attrs so it *is* indeed lost.
>
> A simpler version of Arjun's patch might look like this:
>
> diff --git a/kernel/params.c b/kernel/params.c
> index 34f5270..f9459bc 100644
> --- a/kernel/params.c
> +++ b/kernel/params.c
> @@ -613,7 +613,6 @@ static __modinit int add_sysfs_param(struct module_kobject *mk,
> sizeof(*mk->mp) + sizeof(mk->mp->attrs[0]) * (num+1),
> GFP_KERNEL);
> if (!new) {
> - kfree(attrs);
> err = -ENOMEM;
> goto fail;
> }
> @@ -653,7 +652,10 @@ static __modinit int add_sysfs_param(struct module_kobject *mk,
> fail_free_new:
> kfree(new);
> fail:
> - mk->mp = NULL;
> + if (mk->mp) {
> + kfree(mk->mp->grp.attrs);
> + mk->mp = NULL;
> + }
> return err;
> }
Of course this and Arjun's original *both* fail to fix the classic bug
in the 'new = krealloc(mk->mp…)' bit, failing to free the old mk->mp if
the realloc fails. I think my alternative fix that didn't kill the old
params is probably the better way forward.
--
dwmw2
[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 5745 bytes --]
next prev parent reply other threads:[~2014-08-20 23:10 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-20 20:00 Arjun Sreedharan
2014-08-20 20:49 ` Rusty Russell
2014-08-20 21:08 ` Arjun Sreedharan
2014-08-20 22:05 ` Rusty Russell
2014-08-20 22:17 ` Woodhouse, David
2014-08-20 23:10 ` David Woodhouse [this message]
2014-08-21 6:50 ` Arjun Sreedharan
2014-08-20 21:36 ` Woodhouse, David
-- strict thread matches above, loose matches on Subject: below --
2013-03-14 13:36 [PATCH] params: Fix " David Woodhouse
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1408576214.9540.2.camel@infradead.org \
--to=dwmw2@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=arjun024@gmail.com \
--cc=jg1.han@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rusty@rustcorp.com.au \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome