mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dave Young <hidave.darkstar@gmail.com>
To: Greg KH <gregkh@suse.de>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/3] kobject : kobject_set_name_vargs leak fix
Date: Thu, 14 May 2009 20:04:31 +0800	[thread overview]
Message-ID: <a8e1da0905140504x1d1d99ebq911018d5aaa80a16@mail.gmail.com> (raw)
In-Reply-To: <a8e1da0905102316v1037c89cs48cb052924c250a9@mail.gmail.com>

On Mon, May 11, 2009 at 2:16 PM, Dave Young <hidave.darkstar@gmail.com> wrote:
> kobject_set_name_vargs will leak the old_name when return -ENOMEM,
> move the kfree(old_name) before the return path.

Hi, greg

I rethought about this problem, does such issue exist really? I means
that kobject->name != NULL scenario.

there's following comments of this function:

 * This sets the name of the kobject.  If you have already added the
 * kobject to the system, you must call kobject_rename() in order to
 * change the name of the kobject

So what if something like :

if (kobject->name) {
 WARN(1, KERN_WARNING, "there's name for kobject already!");
 return -EINVAL;
}

if (!fmt)
 return 0;

>
> Signed-off-by: Dave Young <hidave.darkstar@gmail.com>
> ---
> lib/kobject.c |    2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff -uprN linux.old/lib/kobject.c linux.new/lib/kobject.c
> --- linux.old/lib/kobject.c     2009-05-11 13:59:01.000000000 +0800
> +++ linux.new/lib/kobject.c     2009-05-11 13:59:34.000000000 +0800
> @@ -221,6 +221,7 @@ int kobject_set_name_vargs(struct kobjec
>        if (kobj->name && !fmt)
>                return 0;
>
> +       kfree(old_name);
>        kobj->name = kvasprintf(GFP_KERNEL, fmt, vargs);
>        if (!kobj->name)
>                return -ENOMEM;
> @@ -229,7 +230,6 @@ int kobject_set_name_vargs(struct kobjec
>        while ((s = strchr(kobj->name, '/')))
>                s[0] = '!';
>
> -       kfree(old_name);
>        return 0;
>  }
>



-- 
Regards
dave

  parent reply	other threads:[~2009-05-14 12:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-11  6:16 Dave Young
2009-05-12 16:29 ` Greg KH
2009-05-14 12:04 ` Dave Young [this message]
2009-05-14 12:38   ` Ming Lei
2009-05-14 12:59     ` Dave Young

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=a8e1da0905140504x1d1d99ebq911018d5aaa80a16@mail.gmail.com \
    --to=hidave.darkstar@gmail.com \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®