Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp47980pxh; Thu, 7 Apr 2022 13:35:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwYYd/yuC/xfWVeZoopnWjCIzcE5RssnoVUg96gpzlbEA/R1PYbboajQ7cQiCtryjW0X3vM X-Received: by 2002:a17:903:22d1:b0:154:4cfa:2b12 with SMTP id y17-20020a17090322d100b001544cfa2b12mr15365069plg.47.1649363706172; Thu, 07 Apr 2022 13:35:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649363706; cv=none; d=google.com; s=arc-20160816; b=BKH/Zg7Jr/xPaYGWYevZZW37fN5Q4XLI6O7OYsEkZunA5Tchmq5EzBmPQCxamdxDKT hYGCI/LPAi/gqZuKTiBsmFmvrplNLs5U9qJ0p83CP3u6xzJI3nH8jWeuN4TtT4Rxmlf7 p4ZC8kJYMtjk86EqclMAaqz8ln0StEPqMVLxyw5LEES8MpUgZyIeWeXZTUbFlhDNKes0 +G9GSY936WwrpnmF6cpKUjMiaPydow2wJUyYlR9Xj3h5dt/4TgCYvNU6CBmS28IvdGbI 1xRAWqMAr6W9exd/8O6WaSGOi5reS1v/YjwxcatkvKOLESoaTGOokMSmi5aDF5GCe67E 29rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=+dlVy2KZaY8lVEV9hh94s1VdGn0V+ORlIk1tY4mgF8M=; b=unmWIobT3YnBhnF8tcS+kWGB99bRnV81LQJy6lWEv90MebZMkqOhXB/zmIyem9Oa9Y r2Ov+gsFbDYMIPh6lTYFm9aC+dpiwgviy6nREudNiSNuTYXdILM2USNF1MJPhhC1pv8a h6sDsWYOBveQrr+e2hiJE4gE/0VAl6MiS6tDwBrSjGARAyrZvGao5cYFsRoD5SNwrobu Ee9l4DGdvSecEzJFj4s3Vyt6YU53JEnH697RJKFuSxcI1PH/RE65U2UotccjA+q3z+wn +VScoKQiXubK9T9lyl+Dr+CNHFgKnu0Vsq8SrqNBx1Adb2ge2EHqFGk28kDQ8zYTCIJp +qbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=YXgIRtwS; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id 11-20020a63104b000000b003816043ef05si20167362pgq.250.2022.04.07.13.35.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 13:35:06 -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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=YXgIRtwS; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 251183B9275; Thu, 7 Apr 2022 12:50:41 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244647AbiDGTHH (ORCPT + 99 others); Thu, 7 Apr 2022 15:07:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233740AbiDGTHE (ORCPT ); Thu, 7 Apr 2022 15:07:04 -0400 Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B410E33C; Thu, 7 Apr 2022 12:05:03 -0700 (PDT) Received: by mail-il1-x12c.google.com with SMTP id e13so4928997ils.8; Thu, 07 Apr 2022 12:05:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+dlVy2KZaY8lVEV9hh94s1VdGn0V+ORlIk1tY4mgF8M=; b=YXgIRtwSAJL+rMrZdZF3nWvejXegp0BTZlsi8nmRL/Lhq0+pxiL2xcJg0C9MFAfrjZ 0t8pvl6UrBxH1s14afcX0k0PNp4hwIWe3v8HdOM8OaEng8IWhOy8g66MvN4T80ZGuw9H CQS2QjzEKR+0+8CEgVA7jdCROqb7+3Xtw/SlHapVcbtwJQhZmcJ7uhoOEzrbr6zTsazX DrS6LlFNswULirUP9mkugPMyW9AdyISKaZDp9/MTl4c00GXr+2OyTZB6rNTEykRTloSV gTAp3kyY071EzYLnML+5KjVKdTkOMO9l+9wH2JaGMZ5uOKpYOv+tjnkgPHdovwI+LPDX LNxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+dlVy2KZaY8lVEV9hh94s1VdGn0V+ORlIk1tY4mgF8M=; b=cPoCRfMrWCHByOBQH9g1W0OcolDvzqoxylEQ2h/Yyin9ZrH6oDE0gcOS6BuoNgvDuw 0b+qY7sqE2fYRJk84s3s3HH0fviopUDDBQhCWuCJhp+9VfMC9oDzt7zpyPztN93ENRfA tMCavIK2Gh0k1bYWgjxqS7BtbMexSdGb+IHclYcgT9ebuLaDBJQTDeaKIdOqG1R1pn+b gvNBZ5dLfFyzzkE0jUYZVvRZlHTIbOeRVWARAxSsQ9b7C/10qhWx7uUn+CJO9Z5XYvc8 5aCCM3om2K70mEolPCOs6F390J4DZQCUPxalgw2lFzC9yhXCFzqs7gNtfj9F9up7jP4B WLBg== X-Gm-Message-State: AOAM531NcVRU2Ksc7BMEjYlkPV+MJlTZseQ1oKxL3fy68JsE3MNT31YC qPSOsBryqTZCtgGHwPrIbw5ww2wm0yAgz4026OE= X-Received: by 2002:a05:6e02:1562:b0:2ca:50f1:72f3 with SMTP id k2-20020a056e02156200b002ca50f172f3mr6911215ilu.71.1649358303000; Thu, 07 Apr 2022 12:05:03 -0700 (PDT) MIME-Version: 1.0 References: <1649299098-2069-1-git-send-email-baihaowen@meizu.com> In-Reply-To: <1649299098-2069-1-git-send-email-baihaowen@meizu.com> From: Andrii Nakryiko Date: Thu, 7 Apr 2022 12:04:52 -0700 Message-ID: Subject: Re: [PATCH] libbpf: potential NULL dereference in usdt_manager_attach_usdt() To: Haowen Bai Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Networking , bpf , open list Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 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 >