Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp856788pxb; Fri, 22 Apr 2022 12:45:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDeTL00TW2OxyhrqbAnyPYR1zmiD+SN0ExOiIlay0v4xfPGzMwz4G05VkfMro+VKRgL9I8 X-Received: by 2002:a17:902:ea53:b0:15b:1bb8:ac9e with SMTP id r19-20020a170902ea5300b0015b1bb8ac9emr5989322plg.45.1650656723866; Fri, 22 Apr 2022 12:45:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650656723; cv=none; d=google.com; s=arc-20160816; b=aZzv+7GTtVTQsNPGdymnjCwqlyQBZKG6iJAXBoN86e+QlkS/IuoOLCZC6Xk3vkv34N KZqwASoY9Igd9XtR2qmOokp1T3prj57t7N760g8G7izV39zZbFfaD+NI3Jk+LDaGNCwX Vlee+0PINuieVAt/m/amZHgac29VzarpBNSIQSTE/BDitBxawPpYQxXLaZp4X6SAXdix lz/171noO92xAEcE23NXBfq31SsmPyxcPwNj2Nwb6xZqOulRc82FXmrJTA3onmsm5NX7 BOeXTDoOJVq7UZEzJ48XrKZ9CFymQggDiZAy139dgySJ5ZhqUeeL9IRVlG9YmVkzgq3D G69g== 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=LaCuNqz23w9a5w7Pz3RIjEiDWBgRwylEstU9JveB5lk=; b=dUfTjO/GDd0rWJvwVe8ncUfKVJC9SAO0igneyVXCHQA+XHrzAgbYhIxQPElJARWvMK CJWzkPeO+AiqoS9ozQ1hni2HBHfPaN6NPDrFZFHObrhM2mSSxTWUBfHxkX/prv0Un8oR Oua7Is7jJne46p6+f7WZzC4xNQKMWKqE+9qO9PytKOJJ+WHwp0+53Fn4io/2Aqb/Gtf9 SSa5S0fVFHVC7NygK8x6x9ahrN5BJ0/IVGnl9e+X0D18M+q7Rdy4HhxoQUAFDLtnQE1X kbKSZjUCxnT0ZOiR1iShWtD5EPmVbvRpKn4gMuztadp1NJkPov47Kb8f8XgwAQkATWo6 6DWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="YyiGvUT/"; 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 s1-20020a056a00178100b0050a707536ecsi9710968pfg.299.2022.04.22.12.45.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 12:45:23 -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="YyiGvUT/"; 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 33D5A21DD2A; Fri, 22 Apr 2022 11:53:17 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1387219AbiDUQ6M (ORCPT + 99 others); Thu, 21 Apr 2022 12:58:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1385664AbiDUQ6J (ORCPT ); Thu, 21 Apr 2022 12:58:09 -0400 Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98A61DF06; Thu, 21 Apr 2022 09:55:19 -0700 (PDT) Received: by mail-io1-xd29.google.com with SMTP id g21so5927812iom.13; Thu, 21 Apr 2022 09:55:19 -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=LaCuNqz23w9a5w7Pz3RIjEiDWBgRwylEstU9JveB5lk=; b=YyiGvUT/avLzwSpdf6qDyTEgpemoWsOeN6neVUe5AYsTTUMzchfT6vUlpkSu2h0JkF 0wiuNKeGvoE8NWiaO+bDIw1cXDaZRNlM5MNhMpFWMEg6IVd0dgL/HTjTrEvJQi6cNi4p lOXvvI/Cdxzaa7LT3CG7LiQxYBVhuQH4W3g4uEK5lBLjl51Z0Q/dHhYPday992oPMg1R 4YUue0oCAvN8M/8/8E9NZm0YHI4s0HQkEk3BHP+/UYFCy3IyzQOvdQW2r0Ne/em2exRR rpa/8auoJL8aFJidQHjp7/BxKsU2stm6qWFQ5G4O85REvAVNoSsYMi6TS3yw30STxf4X XZQA== 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=LaCuNqz23w9a5w7Pz3RIjEiDWBgRwylEstU9JveB5lk=; b=CYWeyjSR98lkVDETFCmtioo1Ieu3yGeqmSvIDhl7+Xq9lb4QWJJrjwF3PaF0xyv2MZ w3G8lRVNy9YzWdMGhXoI8olHuQPhFhr07+sq6YOKIqnxr/JG2OVnSPhxNJdLr7jadzLD woVIt5kNUUvxXKOZgzXnAZeB+sO7Q0SmafBTLT+6TLVAcNooyWn4IP8rW78q9hUX8CHG WbBRQNZZ0G3b4CCM0CTQ2V89NUXywEopYNFNbO6FoQAjBmdzzosWfbHjvYds+1RKFUa3 wZyZ0iI0drxevhdzGcM4KQBVoIgzUt4HFwvl/MdxI+y1gkzDDvAbx6vIgVTO4m1Y05oX WZWQ== X-Gm-Message-State: AOAM533SqQ7RiZnnero7lXywkAc7KpOesDbEPivofU7cR4h6ZY90RL0O 5apksa/4iSxHacHiLA5B8/ZRV5eXr88ekMUTyDI= X-Received: by 2002:a05:6638:3393:b0:32a:93cd:7e48 with SMTP id h19-20020a056638339300b0032a93cd7e48mr277380jav.93.1650560119063; Thu, 21 Apr 2022 09:55:19 -0700 (PDT) MIME-Version: 1.0 References: <20220421130056.2510372-1-cuigaosheng1@huawei.com> In-Reply-To: <20220421130056.2510372-1-cuigaosheng1@huawei.com> From: Andrii Nakryiko Date: Thu, 21 Apr 2022 09:55:08 -0700 Message-ID: Subject: Re: [PATCH -next] libbpf: Add additional null-pointer checking in make_parent_dir To: Gaosheng Cui Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin Lau , Song Liu , Yonghong Song , john fastabend , KP Singh , Networking , bpf , open list , gongruiqi1@huawei.com, wangweiyang2@huawei.com 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 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 Thu, Apr 21, 2022 at 6:01 AM Gaosheng Cui wrote: > > The make_parent_dir is called without null-pointer checking for path, > such as bpf_link__pin. To ensure there is no null-pointer dereference > in make_parent_dir, so make_parent_dir requires additional null-pointer > checking for path. > > Signed-off-by: Gaosheng Cui > --- > tools/lib/bpf/libbpf.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index b53e51884f9e..5786e6184bf5 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -7634,6 +7634,9 @@ static int make_parent_dir(const char *path) > char *dname, *dir; > int err = 0; > > + if (path == NULL) > + return -EINVAL; > + API contract is that path shouldn't be NULL. Just like we don't check link, obj, prog for NULL in every single API, I don't think we need to do it here, unless I'm missing something? > dname = strdup(path); > if (dname == NULL) > return -ENOMEM; > -- > 2.25.1 >