Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp205222pxh; Thu, 7 Apr 2022 18:58:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGvZ25ZGED+A97WCpqA7RXFZv9W2zjYfpLF0ucCZSVI5Pgu4kav3VscV3rvpI37BpXHn0Y X-Received: by 2002:a17:90b:384c:b0:1cb:1b44:2939 with SMTP id nl12-20020a17090b384c00b001cb1b442939mr5476066pjb.46.1649383112611; Thu, 07 Apr 2022 18:58:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649383112; cv=none; d=google.com; s=arc-20160816; b=cO5A+rYNE6xkeNVyvoOAKWRDX1Ii3WupEKqe3w6BnBPQuz9qgbYoCbUgKKqcKSCAcE CSbbYNBHxptyWK9KrG09FGaROi6zoHXO6GGKP7WoPqMRG120I3JkZyQoc+BfNn/+tMKb 872IDebKVey1iWSgdY9vmqJ38GZWouU/JMabkV+P3Z3k/d9dxHoFO8T/NNs++uh1/8od dE9270kHf8UVyIpQrTi8jUIGjP9HLIfQLhe36Y5HpI0GKnYP8A3J0NF/RxS4krNs7q78 Jo/89HFnQiKroqq7I+SNFjibJ6COf6+BrAFGUHYccaShaLfZca5aT/aFe5S0cMw67yfr hS6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=KV2zmbKSJf0wRb/LEVvQE/dVi5AzrJJ6WLnCZMZGH0E=; b=PHleZuQMxD9OM4SjE7sYNLQqL9BahaKugcK4f/4drgN9EOKoKZBGOkGBlPOyspn47W Md66XLlBlI8QHNvj40aWNDGkGz8PROKvc0mCUrH7IGVIz20PUP1dNIjvENdj7KzoQCw2 ZeUD9RjhOyWRk/EvvBM9mPS0WwSIveehgvCUYNjwCWRH5oWeW1Hq6arIKNCifk4OMqc7 ++l5ix6LBSg3fbcH3t3bi7s63QWiD5nRfbgdfi+ycFjS6HRC42WB9urxLLZBxoW/B2YB S+zfLA4ICiGWDR6Dpk1k4FZa2Ts0qmTfvySXwnjxmA8womgfIdJ3vqzvou2Lit0TzExD eMDA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id g67-20020a636b46000000b0039cc85e85e9si3270228pgc.531.2022.04.07.18.58.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 18:58:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 076BD2A7B9D; Thu, 7 Apr 2022 18:30:28 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233434AbiDHBcQ (ORCPT + 99 others); Thu, 7 Apr 2022 21:32:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232119AbiDHBcO (ORCPT ); Thu, 7 Apr 2022 21:32:14 -0400 Received: from mail.meizu.com (edge05.meizu.com [157.122.146.251]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B2452706C6; Thu, 7 Apr 2022 18:30:11 -0700 (PDT) Received: from IT-EXMB-1-125.meizu.com (172.16.1.125) by mz-mail12.meizu.com (172.16.1.108) with Microsoft SMTP Server (TLS) id 14.3.487.0; Fri, 8 Apr 2022 09:30:09 +0800 Received: from [172.16.137.70] (172.16.137.70) by IT-EXMB-1-125.meizu.com (172.16.1.125) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.14; Fri, 8 Apr 2022 09:30:08 +0800 Message-ID: <2c29b3cd-ec23-f9c8-ae9f-d713ce3dd4f0@meizu.com> Date: Fri, 8 Apr 2022 09:30:07 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH] libbpf: potential NULL dereference in usdt_manager_attach_usdt() To: Andrii Nakryiko CC: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Networking , bpf , open list References: <1649299098-2069-1-git-send-email-baihaowen@meizu.com> From: baihaowen In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [172.16.137.70] X-ClientProxiedBy: IT-EXMB-1-126.meizu.com (172.16.1.126) To IT-EXMB-1-125.meizu.com (172.16.1.125) X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 4/8/22 3:04 AM, Andrii Nakryiko 写道: > On Wed, Apr 6, 2022 at 7:38 PM Haowen Bai wrote: >> link could be null but still dereference bpf_link__destroy(&link->link) >> and it will lead to a null pointer access. >> >> Signed-off-by: Haowen Bai >> --- >> tools/lib/bpf/usdt.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/tools/lib/bpf/usdt.c b/tools/lib/bpf/usdt.c >> index 1bce2eab5e89..b02ebc4ba57c 100644 >> --- a/tools/lib/bpf/usdt.c >> +++ b/tools/lib/bpf/usdt.c >> @@ -996,7 +996,7 @@ struct bpf_link *usdt_manager_attach_usdt(struct usdt_manager *man, const struct >> link = calloc(1, sizeof(*link)); >> if (!link) { >> err = -ENOMEM; >> - goto err_out; >> + goto link_err; > this is not a complete fix because there are two more similar goto > err_out; above which you didn't fix. I think better fix is to just add > if (link) check before bpf_link__destroy(), which is what I did > locally when applying. > > >> } >> >> link->usdt_man = man; >> @@ -1072,7 +1072,7 @@ struct bpf_link *usdt_manager_attach_usdt(struct usdt_manager *man, const struct >> >> err_out: >> bpf_link__destroy(&link->link); >> - >> +link_err: >> free(targets); >> hashmap__free(specs_hash); >> if (elf) >> -- >> 2.7.4 >> Thank you for your kindness help. :) -- Haowen Bai