Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp7718869ioo; Fri, 3 Jun 2022 11:59:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWjVfzLVj7LAXytGvJtpCJULyGVFZA2kCXt6NhEysETaBlhjxGKil3O+p5wucHFf6PuGcu X-Received: by 2002:a05:6402:11cb:b0:42b:6315:7cde with SMTP id j11-20020a05640211cb00b0042b63157cdemr12494712edw.264.1654282795409; Fri, 03 Jun 2022 11:59:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654282795; cv=none; d=google.com; s=arc-20160816; b=zFh4qg7AcKsFZkLSya9y6NqaOvNoQnkeUhTq9msdhWawLkekQl4HExZDkqYOpjFPTK MGzPZfvCYEadB9UB9KSMXNmPD3/7TNZQO71xYQyLwNZnNmKA7gIvCrcBtEJr1jj6ebfq ZVlR/JIYrdQPOiKHYXH3q0ZmjYfuNP9AMIFFYlKNTZ5q3Nft/jJOufsKMDMYKQy6E55X A3/uPSvIahCs1TJTQi6qRmMDoyI8JuATn+toxC1j8Yx4FE00bFf92WeYS2A5j0mC/oUK H+SKYa3pgxVYL+atzZodxDbkZkn+yWYisR6XEMME4oD2q1335CyGmD+MenlPiTGKHKiv T2mQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=y9mYw2lZJVVGSW9eCHkW4OSoeoq/SHjhA0WRE/VeL0U=; b=GN8IYAoE+xQUzD/JXGMQdErKS/QDEHMKDBrqApkqZeY0z8gJYwSJujO78H3viB2eRZ nxq6eAbf8rdT783xpiK4w8xZy/GXISsvwRnqSlFJfyifXIzIW1UEs+wKSd5Po/NkZRmt qOOG3xACCnwsYk8F8SCiMP3inzQ6xGfQ0kOCLe+GjZZ0VFD1R9vB3sBX6ozG79BK/CzD kw5WvZHiU1b+G1yWBhKPhLdVAhT32lCkPp6s9cALBNyiaulIxs1nbq8r0r9B5SzhW2pb T3vLAvv+4NWGz2zupvvPzZOma1luZhi7n2tndu5ELs8WacNQAYH2dYi8jKbNAta5vOEs lSKQ== 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e5-20020a17090658c500b006ff077eab22si8488936ejs.0.2022.06.03.11.59.30; Fri, 03 Jun 2022 11:59:55 -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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236163AbiFBOj4 (ORCPT + 99 others); Thu, 2 Jun 2022 10:39:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236031AbiFBOjc (ORCPT ); Thu, 2 Jun 2022 10:39:32 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAD581DAF2E; Thu, 2 Jun 2022 07:39:30 -0700 (PDT) Received: from fraeml714-chm.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4LDT8h64Z9z686LZ; Thu, 2 Jun 2022 22:36:04 +0800 (CST) Received: from roberto-ThinkStation-P620.huawei.com (10.204.63.22) by fraeml714-chm.china.huawei.com (10.206.15.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 2 Jun 2022 16:39:28 +0200 From: Roberto Sassu To: , , , CC: , , , , Roberto Sassu Subject: [PATCH v2 6/9] bpftool: Add flags parameter to map_parse_fd_and_info() Date: Thu, 2 Jun 2022 16:37:45 +0200 Message-ID: <20220602143748.673971-7-roberto.sassu@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220602143748.673971-1-roberto.sassu@huawei.com> References: <20220602143748.673971-1-roberto.sassu@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.204.63.22] X-ClientProxiedBy: lhreml754-chm.china.huawei.com (10.201.108.204) To fraeml714-chm.china.huawei.com (10.206.15.33) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Add the flags parameter to map_parse_fd_and_info(), as this function is called directly by the functions implementing bpftool subcommands, so that it is possible to specify the right permissions for accessing a map. Still pass zero as value for flags, and adjust permissions in a later patch. Signed-off-by: Roberto Sassu --- tools/bpf/bpftool/btf.c | 2 +- tools/bpf/bpftool/common.c | 5 +++-- tools/bpf/bpftool/main.h | 3 ++- tools/bpf/bpftool/map.c | 12 ++++++------ tools/bpf/bpftool/map_perf_ring.c | 3 ++- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c index 98569252ef4a..69a7695030f9 100644 --- a/tools/bpf/bpftool/btf.c +++ b/tools/bpf/bpftool/btf.c @@ -529,7 +529,7 @@ static int do_dump(int argc, char **argv) return -1; } - fd = map_parse_fd_and_info(&argc, &argv, &info, &len); + fd = map_parse_fd_and_info(&argc, &argv, &info, &len, 0); if (fd < 0) return -1; diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c index 641810b78581..0816ea2f0be1 100644 --- a/tools/bpf/bpftool/common.c +++ b/tools/bpf/bpftool/common.c @@ -947,12 +947,13 @@ int map_parse_fd(int *argc, char ***argv, __u32 flags) return fd; } -int map_parse_fd_and_info(int *argc, char ***argv, void *info, __u32 *info_len) +int map_parse_fd_and_info(int *argc, char ***argv, void *info, __u32 *info_len, + __u32 flags) { int err; int fd; - fd = map_parse_fd(argc, argv, 0); + fd = map_parse_fd(argc, argv, flags); if (fd < 0) return -1; diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h index 70b0ad6245b9..46c2f24f66fd 100644 --- a/tools/bpf/bpftool/main.h +++ b/tools/bpf/bpftool/main.h @@ -171,7 +171,8 @@ int prog_parse_fd(int *argc, char ***argv, __u32 flags); int prog_parse_fds(int *argc, char ***argv, int **fds); int map_parse_fd(int *argc, char ***argv, __u32 flags); int map_parse_fds(int *argc, char ***argv, int **fds, __u32 flags); -int map_parse_fd_and_info(int *argc, char ***argv, void *info, __u32 *info_len); +int map_parse_fd_and_info(int *argc, char ***argv, void *info, __u32 *info_len, + __u32 flags); struct bpf_prog_linfo; #ifdef HAVE_LIBBFD_SUPPORT diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c index 9a747918882e..f253f69879a9 100644 --- a/tools/bpf/bpftool/map.c +++ b/tools/bpf/bpftool/map.c @@ -998,7 +998,7 @@ static int do_update(int argc, char **argv) if (argc < 2) usage(); - fd = map_parse_fd_and_info(&argc, &argv, &info, &len); + fd = map_parse_fd_and_info(&argc, &argv, &info, &len, 0); if (fd < 0) return -1; @@ -1077,7 +1077,7 @@ static int do_lookup(int argc, char **argv) if (argc < 2) usage(); - fd = map_parse_fd_and_info(&argc, &argv, &info, &len); + fd = map_parse_fd_and_info(&argc, &argv, &info, &len, 0); if (fd < 0) return -1; @@ -1128,7 +1128,7 @@ static int do_getnext(int argc, char **argv) if (argc < 2) usage(); - fd = map_parse_fd_and_info(&argc, &argv, &info, &len); + fd = map_parse_fd_and_info(&argc, &argv, &info, &len, 0); if (fd < 0) return -1; @@ -1199,7 +1199,7 @@ static int do_delete(int argc, char **argv) if (argc < 2) usage(); - fd = map_parse_fd_and_info(&argc, &argv, &info, &len); + fd = map_parse_fd_and_info(&argc, &argv, &info, &len, 0); if (fd < 0) return -1; @@ -1311,7 +1311,7 @@ static int do_create(int argc, char **argv) if (!REQ_ARGS(2)) usage(); inner_map_fd = map_parse_fd_and_info(&argc, &argv, - &info, &len); + &info, &len, 0); if (inner_map_fd < 0) return -1; attr.inner_map_fd = inner_map_fd; @@ -1358,7 +1358,7 @@ static int do_pop_dequeue(int argc, char **argv) if (argc < 2) usage(); - fd = map_parse_fd_and_info(&argc, &argv, &info, &len); + fd = map_parse_fd_and_info(&argc, &argv, &info, &len, 0); if (fd < 0) return -1; diff --git a/tools/bpf/bpftool/map_perf_ring.c b/tools/bpf/bpftool/map_perf_ring.c index 6b0c410152de..dcfc4724cd8d 100644 --- a/tools/bpf/bpftool/map_perf_ring.c +++ b/tools/bpf/bpftool/map_perf_ring.c @@ -135,7 +135,8 @@ int do_event_pipe(int argc, char **argv) int err, map_fd; map_info_len = sizeof(map_info); - map_fd = map_parse_fd_and_info(&argc, &argv, &map_info, &map_info_len); + map_fd = map_parse_fd_and_info(&argc, &argv, &map_info, &map_info_len, + 0); if (map_fd < 0) return -1; -- 2.25.1