Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp7484454ybp; Wed, 16 Oct 2019 09:19:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqzkWlKyN+T1tgq2srd5/ClSyT7pnmtGhbNVA8n2o/aJLABsWcqh/BQCVGWvC1CGFvTM05ZU X-Received: by 2002:a17:906:1390:: with SMTP id f16mr39998584ejc.295.1571242758170; Wed, 16 Oct 2019 09:19:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571242758; cv=none; d=google.com; s=arc-20160816; b=bFDQbGTkSVtcA9dk7Eqc52cSCX6tx7EryJ6mZq4S4iakNXI9vdy0gCBZzuqNi4Gn0j tafP3L41irKC0fvXyg9592061FOVVfwP3ljDTt/oiXeN70rsa/AZeKYXizWo5tZnBh9g W4zvWR7qvFMHM92L3ex/B66MFdLNOHnu9ylB8bfUKKYyY9MnBjk2C1UBAXarzSabXKPb 5mE1Qwacphm2fQatu/lO6bSgYBorqIamm5xfpQEjv24hpxbaKi/NUaaA6d0bMnBIZDAf tOfrBqrhjoXm/vW5Vd2pvAxk6H+3enuafFfJ8ahSZIXF9biMirYhWVvVSovjyVE8xLhp s4xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=O8nJDY0wNx/xjHUf96LU8Xv3A8OjuRZlpuu7lNwPMLw=; b=sAVw4+6IYXH01ax/v7NWqItKQ6pEj3qwL8r14uJox/rrOfxQWpOFl1bYViDEAM/JtV PRPIcUzadTYmpgSbsvi2S5NydywAWrUEuARHz914KeNmmH4sPtENvlA64JudILT/4A7y QZV8ptcUwzPcUVUVlskmgeWBA+asZMibugOAw+37Hkx3IG7e4hnaPFakrU30lvsuLGnF 6O09TMvaZDb1Xh28b8DV1EMSMMmDEtLX625mZfsw4rx1EmyufD4GCDMMCxaNhRBRr0yS QQcoCTEL5+fBAZWows8lRfEDIsXau0ggCh8fJDp8Y309HcJIJPsUMi47ionvsIcz/rpM bidQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g23si14449023ejm.398.2019.10.16.09.18.55; Wed, 16 Oct 2019 09:19:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393863AbfJPORf (ORCPT + 99 others); Wed, 16 Oct 2019 10:17:35 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:4223 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2392279AbfJPORf (ORCPT ); Wed, 16 Oct 2019 10:17:35 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 11C14584243BE82D58B3; Wed, 16 Oct 2019 22:17:32 +0800 (CST) Received: from [127.0.0.1] (10.177.251.225) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.439.0; Wed, 16 Oct 2019 22:17:24 +0800 Subject: Re: [PATCH] perf kmem: Fix memory leak in compact_gfp_flags() To: Arnaldo Carvalho de Melo CC: , , , , , , , , References: <20191016130403.GA22835@kernel.org> <20191016130921.GC22835@kernel.org> <20191016140856.GG22835@kernel.org> From: Yunfeng Ye Message-ID: Date: Wed, 16 Oct 2019 22:17:22 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20191016140856.GG22835@kernel.org> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.251.225] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019/10/16 22:08, Arnaldo Carvalho de Melo wrote: > Em Wed, Oct 16, 2019 at 09:19:54PM +0800, Yunfeng Ye escreveu: >> >> >> On 2019/10/16 21:09, Arnaldo Carvalho de Melo wrote: >>> Em Wed, Oct 16, 2019 at 10:04:03AM -0300, Arnaldo Carvalho de Melo escreveu: >>>> Em Wed, Oct 16, 2019 at 04:38:45PM +0800, Yunfeng Ye escreveu: >>>>> The memory @orig_flags is allocated by strdup(), it is freed on the >>>>> normal path, but leak to free on the error path. >>>> >>>> Are you using some tool to find out these problems? Or is it just visual >>>> inspection? >>> >> By a static code anaylsis tool which not an open source tool. thanks. > > Ok, so please state that next time, just for the fullest possible > disclosure and for people to realize to what extent problems in the > kernel and in tooling hosted in the kernel is being fixed by such tools. > > I.e. you don't need to release the tool, not even give out its name, > just something like: > > "Found by internal static analysis tool." > ok, thanks. > Thanks, > > - Arnaldo > >>> Anyway, applied after adding this to the commit log message: >>> >>> Fixes: 0e11115644b3 ("perf kmem: Print gfp flags in human readable string") >>> >> ok, thanks. >> >>> - Arnaldo >>> >>>> - Arnaldo >>>> >>>>> Fix this by adding free(orig_flags) on the error path. >>>>> >>>>> Signed-off-by: Yunfeng Ye >>>>> --- >>>>> tools/perf/builtin-kmem.c | 1 + >>>>> 1 file changed, 1 insertion(+) >>>>> >>>>> diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c >>>>> index 1e61e353f579..9661671cc26e 100644 >>>>> --- a/tools/perf/builtin-kmem.c >>>>> +++ b/tools/perf/builtin-kmem.c >>>>> @@ -691,6 +691,7 @@ static char *compact_gfp_flags(char *gfp_flags) >>>>> new = realloc(new_flags, len + strlen(cpt) + 2); >>>>> if (new == NULL) { >>>>> free(new_flags); >>>>> + free(orig_flags); >>>>> return NULL; >>>>> } >>>>> >>>>> -- >>>>> 2.7.4.3 >>>> >>>> -- >>>> >>>> - Arnaldo >>> >