From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761350AbZENMEk (ORCPT ); Thu, 14 May 2009 08:04:40 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755845AbZENMEb (ORCPT ); Thu, 14 May 2009 08:04:31 -0400 Received: from wf-out-1314.google.com ([209.85.200.171]:36908 "EHLO wf-out-1314.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754930AbZENMEa convert rfc822-to-8bit (ORCPT ); Thu, 14 May 2009 08:04:30 -0400 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=s+fHqgbn73dqs77uwTEYxvioIUrtYzFi3eFG5PuPixefhnDsSXUJ1SDeWTczfF2GMG s7/pkwa0MllNy4IsVC6Zp2Myin/Mif3Kt/mBXmwaV3tcss8ohhEwCR7TEBL5bz3m99ay x8oSDYkVTgRmFglJTGE/nIf1jUav7AQCeUyOs= MIME-Version: 1.0 In-Reply-To: References: Date: Thu, 14 May 2009 20:04:31 +0800 Message-ID: Subject: Re: [PATCH 1/3] kobject : kobject_set_name_vargs leak fix From: Dave Young To: Greg KH , Linux Kernel Mailing List Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 11, 2009 at 2:16 PM, Dave Young 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 > --- > 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