Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp3731106rwi; Wed, 2 Nov 2022 02:24:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM50Zc6lJQopN4nYQz8NLZk7mctL8dJXdI2UQVRfHAG2lYtLeV9Pq9Fu/t47NO2auDPLmDIN X-Received: by 2002:a17:907:72c7:b0:791:9ba2:4978 with SMTP id du7-20020a17090772c700b007919ba24978mr21870047ejc.217.1667381048330; Wed, 02 Nov 2022 02:24:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667381048; cv=none; d=google.com; s=arc-20160816; b=G46p7b1t5mrCR+wBx+JtHmuddu15hssPuX3QySczU3Nx3kuAmOvPYKwzrzLJcgNwiZ RcX8RwYMjdQYD5C2Ml1gqnBIyQN+PvFiqC7Ib1bVWNTgbKGPWW+EaRlXKNlUg3yGJlns ttSTW2655zrTIU6VUAWSs7DI5MpuLfCyfLNMY0JIGbQcOpOh+i8AeHhSIPlPmQ4WTRAB fz1jUls0uuOhrHM0wP7mggwYKsiIZlr3QojPGfr3HHf0Uri61cIWVvl31pvn0SS0aLfe VIlyHws9yuKZvpq4l7ryyCiTy4xUgslVveex8CI6g5/6g7YAF7wlnhf8+KscmW8icQdX NOTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=lIMLlecZ95g/rrQULGzWxXanZOlZUsjqVMTaIEraaF0=; b=C5ilzGM3lzJjE/LxT5hPZckVXm5pXCjMzioWJpL7lZQOV57qiZn6qRCpnHmHTqMuQJ +NUEm/cpSHERIvrxBIk//IXjeFbm47/05HtG8DeqctrAEUIDhqYW7kIAJyw7xXKTj1jP 2dNUeamI8d/E1trkTFYfxNtpmg/oMUGMwHKdJhad8snRwE2jS1lrfpbjdOp1ov5LqOmB qpHv5ccKKRvzGA6RY1sX0Xa6iovjqF0FFZ6zJ1zwzV53vzxHuEDYPRCbFOYFiX6IDE+p NzvILS2dJ7vrYrBAsKqIIDQSJh3TOK2gHyGg22nExc7RiBJ7EuqVZAkQSbF0wSFlnv/4 t6Ug== 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:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bb6-20020a1709070a0600b007815ca78c38si17021743ejc.235.2022.11.02.02.23.43; Wed, 02 Nov 2022 02:24:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229518AbiKBIka (ORCPT + 97 others); Wed, 2 Nov 2022 04:40:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230318AbiKBIk1 (ORCPT ); Wed, 2 Nov 2022 04:40:27 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EE4524954; Wed, 2 Nov 2022 01:40:26 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4N2Kyk0D0bzKGM4; Wed, 2 Nov 2022 16:37:50 +0800 (CST) Received: from localhost.localdomain (unknown [10.67.175.61]) by APP4 (Coremail) with SMTP id gCh0CgDn9ef4LGJjxZxaAg--.29164S2; Wed, 02 Nov 2022 16:40:24 +0800 (CST) From: Pu Lehui To: bpf@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Quentin Monnet , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Pu Lehui , Pu Lehui Subject: [PATCH bpf] bpftool: Fix NULL pointer dereference when pin {PROG, MAP, LINK} without FILE Date: Wed, 2 Nov 2022 16:40:34 +0800 Message-Id: <20221102084034.3342995-1-pulehui@huaweicloud.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: gCh0CgDn9ef4LGJjxZxaAg--.29164S2 X-Coremail-Antispam: 1UD129KBjvdXoW7XF4kZrWxJw48CrW8tw4ruFg_yoWDCFbE9r yvqr9Yvr4rGF9Igw18C3yruFy8Ga4UZr4xZ3W3Jry3Aa1DCFnIk3Wvkws5AFW3WFyDZF17 JF92kry3WF4akjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbxAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j 6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628v n2kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F4 0E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_Wryl IxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxV AFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6rWUJVWrZr1UMIIF0xvEx4A2jsIE14v2 6r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0J UZa9-UUUUU= X-CM-SenderInfo: psxovxtxl6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham 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 From: Pu Lehui When using bpftool to pin {PROG, MAP, LINK} without FILE, segmentation fault will occur. The reson is that the lack of FILE will cause strlen to trigger NULL pointer dereference. The corresponding stacktrace is shown below: do_pin do_pin_any do_pin_fd mount_bpffs_for_pin strlen(name) <- NULL pointer dereference Fix it by adding validation to the common process. Fixes: 75a1e792c335 ("tools: bpftool: Allow all prog/map handles for pinning objects") Signed-off-by: Pu Lehui --- tools/bpf/bpftool/common.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c index e4d33bc8bbbf..653c130a0aaa 100644 --- a/tools/bpf/bpftool/common.c +++ b/tools/bpf/bpftool/common.c @@ -302,6 +302,9 @@ int do_pin_any(int argc, char **argv, int (*get_fd)(int *, char ***)) int err; int fd; + if (!REQ_ARGS(3)) + return -EINVAL; + fd = get_fd(&argc, &argv); if (fd < 0) return fd; -- 2.25.1