From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89193C43381 for ; Fri, 8 Mar 2019 20:23:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4C4DE20851 for ; Fri, 8 Mar 2019 20:23:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727128AbfCHUXR (ORCPT ); Fri, 8 Mar 2019 15:23:17 -0500 Received: from www62.your-server.de ([213.133.104.62]:48876 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726996AbfCHUXQ (ORCPT ); Fri, 8 Mar 2019 15:23:16 -0500 Received: from [78.46.172.3] (helo=sslproxy06.your-server.de) by www62.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1h2M1O-0003QI-OA; Fri, 08 Mar 2019 21:23:11 +0100 Received: from [178.197.249.29] (helo=linux.home) by sslproxy06.your-server.de with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1h2M1O-000HOn-Gs; Fri, 08 Mar 2019 21:23:10 +0100 Subject: Re: [PATCH v3 bpf]: libbpf: fixing leak when kernel does not support btf To: Martin Lau , "Nikita V. Shirokov" Cc: Alexei Starovoitov , Yonghong Song , "netdev@vger.kernel.org" References: <20190308051814.19218-1-tehnerd@tehnerd.com> <20190308164524.esibgk5yd7a5vq2o@kafai-mbp.dhcp.thefacebook.com> From: Daniel Borkmann Message-ID: Date: Fri, 8 Mar 2019 21:23:09 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20190308164524.esibgk5yd7a5vq2o@kafai-mbp.dhcp.thefacebook.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.100.2/25382/Fri Mar 8 09:55:42 2019) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On 03/08/2019 05:45 PM, Martin Lau wrote: > On Fri, Mar 08, 2019 at 05:18:14AM +0000, Nikita V. Shirokov wrote: >> we could end up in situation when we have object file w/ all btf >> info but kernel does not support btf yet. in this situation currently >> libbpf just set obj->btf to NULL w/o freeing it first. >> this patch if fixing it by making sure to run btf__free first >> >> v2->v3: >> - adding "Fixes" tag >> >> v1->v2: >> - adding netdev to cc >> >> Fixes: 8a138aed4a80 ("bpf: btf: Add BTF support to libbpf") > I think the Fixes tag should belong to a later patch, just in > case there will be an issue when pulling into stable: > > Fixes: d29d87f7e612 ("btf: separate btf creation and loading") Agree, I just fixed up the tags, thanks! >> Signed-off-by: Nikita V. Shirokov >> --- >> tools/lib/bpf/libbpf.c | 2 ++ >> 1 file changed, 2 insertions(+) >> >> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c >> index f5eb60379c8d..d5b830d60601 100644 >> --- a/tools/lib/bpf/libbpf.c >> +++ b/tools/lib/bpf/libbpf.c >> @@ -838,6 +838,8 @@ static int bpf_object__elf_collect(struct bpf_object *obj, int flags) >> if (IS_ERR(obj->btf) || btf__load(obj->btf)) { >> pr_warning("Error loading ELF section %s: %ld. Ignored and continue.\n", >> BTF_ELF_SEC, PTR_ERR(obj->btf)); > Printing this PTR_ERR(obj->btf) seems not very correct also if btf__load() > was the one failing. Makes sense as well. Given this is logically independent from addressing this leak, please send a follow-up fix for the pr_warning(). >> + if (!IS_ERR(obj->btf)) >> + btf__free(obj->btf); >> obj->btf = NULL; >> } >> } else if (strcmp(name, BTF_EXT_ELF_SEC) == 0) { >> -- >> 2.17.1 >>