@@ -559,7 +559,7 @@ static int do_dump(int argc, char **argv)
return -1;
}
- fd = prog_parse_fd(&argc, &argv);
+ fd = prog_parse_fd(&argc, &argv, 0);
if (fd < 0)
return -1;
@@ -661,7 +661,7 @@ static int do_dump(int argc, char **argv)
return err;
}
-static int btf_parse_fd(int *argc, char ***argv)
+static int btf_parse_fd(int *argc, char ***argv, __u32 flags)
{
unsigned int id;
char *endptr;
@@ -931,7 +931,7 @@ static int do_show(int argc, char **argv)
__u32 id = 0;
if (argc == 2) {
- fd = btf_parse_fd(&argc, &argv);
+ fd = btf_parse_fd(&argc, &argv, 0);
if (fd < 0)
return -1;
}
@@ -425,7 +425,7 @@ static int do_attach(int argc, char **argv)
argc -= 2;
argv = &argv[2];
- prog_fd = prog_parse_fd(&argc, &argv);
+ prog_fd = prog_parse_fd(&argc, &argv, 0);
if (prog_fd < 0)
goto exit_cgroup;
@@ -483,7 +483,7 @@ static int do_detach(int argc, char **argv)
argc -= 2;
argv = &argv[2];
- prog_fd = prog_parse_fd(&argc, &argv);
+ prog_fd = prog_parse_fd(&argc, &argv, 0);
if (prog_fd < 0)
goto exit_cgroup;
@@ -223,12 +223,12 @@ int do_pin_fd(int fd, const char *name)
return err;
}
-int do_pin_any(int argc, char **argv, int (*get_fd)(int *, char ***))
+int do_pin_any(int argc, char **argv, int (*get_fd)(int *, char ***, __u32))
{
int err;
int fd;
- fd = get_fd(&argc, &argv);
+ fd = get_fd(&argc, &argv, 0);
if (fd < 0)
return fd;
@@ -772,7 +772,7 @@ int prog_parse_fds(int *argc, char ***argv, int **fds)
return -1;
}
-int prog_parse_fd(int *argc, char ***argv)
+int prog_parse_fd(int *argc, char ***argv, __u32 flags)
{
int *fds = NULL;
int nb_fds, fd;
@@ -909,7 +909,7 @@ int map_parse_fds(int *argc, char ***argv, int **fds)
return -1;
}
-int map_parse_fd(int *argc, char ***argv)
+int map_parse_fd(int *argc, char ***argv, __u32 flags)
{
int *fds = NULL;
int nb_fds, fd;
@@ -941,7 +941,7 @@ int map_parse_fd_and_info(int *argc, char ***argv, void *info, __u32 *info_len)
int err;
int fd;
- fd = map_parse_fd(argc, argv);
+ fd = map_parse_fd(argc, argv, 0);
if (fd < 0)
return -1;
@@ -34,7 +34,7 @@ static int do_pin(int argc, char **argv)
return -1;
}
- map_fd = map_parse_fd(&argc, &argv);
+ map_fd = map_parse_fd(&argc, &argv, 0);
if (map_fd < 0)
return -1;
@@ -15,7 +15,7 @@
static struct hashmap *link_table;
-static int link_parse_fd(int *argc, char ***argv)
+static int link_parse_fd(int *argc, char ***argv, __u32 flags)
{
int fd;
@@ -44,6 +44,7 @@ static int link_parse_fd(int *argc, char ***argv)
path = **argv;
NEXT_ARGP();
+ /* WARNING: flags not passed for links (no security hook). */
return open_obj_pinned_any(path, BPF_OBJ_LINK, 0);
}
@@ -321,7 +322,7 @@ static int do_show(int argc, char **argv)
build_obj_refs_table(&refs_table, BPF_OBJ_LINK);
if (argc == 2) {
- fd = link_parse_fd(&argc, &argv);
+ fd = link_parse_fd(&argc, &argv, 0);
if (fd < 0)
return fd;
return do_show_link(fd);
@@ -385,7 +386,7 @@ static int do_detach(int argc, char **argv)
return 1;
}
- fd = link_parse_fd(&argc, &argv);
+ fd = link_parse_fd(&argc, &argv, 0);
if (fd < 0)
return 1;
@@ -145,7 +145,8 @@ int open_obj_pinned(const char *path, bool quiet, __u32 flags);
int open_obj_pinned_any(const char *path, enum bpf_obj_type exp_type,
__u32 flags);
int mount_bpffs_for_pin(const char *name);
-int do_pin_any(int argc, char **argv, int (*get_fd_by_id)(int *, char ***));
+int do_pin_any(int argc, char **argv,
+ int (*get_fd_by_id)(int *, char ***, __u32));
int do_pin_fd(int fd, const char *name);
/* commands available in bootstrap mode */
@@ -166,9 +167,9 @@ int do_struct_ops(int argc, char **argv) __weak;
int do_iter(int argc, char **argv) __weak;
int parse_u32_arg(int *argc, char ***argv, __u32 *val, const char *what);
-int prog_parse_fd(int *argc, char ***argv);
+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);
+int map_parse_fd(int *argc, char ***argv, __u32 flags);
int map_parse_fds(int *argc, char ***argv, int **fds);
int map_parse_fd_and_info(int *argc, char ***argv, void *info, __u32 *info_len);
@@ -381,7 +381,7 @@ static int parse_elem(char **argv, struct bpf_map_info *info,
return -1;
}
- fd = map_parse_fd(&argc, &argv);
+ fd = map_parse_fd(&argc, &argv, 0);
if (fd < 0)
return -1;
@@ -402,7 +402,7 @@ static int parse_elem(char **argv, struct bpf_map_info *info,
p_info("Warning: updating program array via MAP_ID, make sure this map is kept open\n"
" by some process or pinned otherwise update will be lost");
- fd = prog_parse_fd(&argc, &argv);
+ fd = prog_parse_fd(&argc, &argv, 0);
if (fd < 0)
return -1;
@@ -1397,7 +1397,7 @@ static int do_freeze(int argc, char **argv)
if (!REQ_ARGS(2))
return -1;
- fd = map_parse_fd(&argc, &argv);
+ fd = map_parse_fd(&argc, &argv, 0);
if (fd < 0)
return -1;
@@ -571,7 +571,7 @@ static int do_attach(int argc, char **argv)
}
NEXT_ARG();
- progfd = prog_parse_fd(&argc, &argv);
+ progfd = prog_parse_fd(&argc, &argv, 0);
if (progfd < 0)
return -EINVAL;
@@ -1027,7 +1027,7 @@ static int parse_attach_detach_args(int argc, char **argv, int *progfd,
if (!REQ_ARGS(3))
return -EINVAL;
- *progfd = prog_parse_fd(&argc, &argv);
+ *progfd = prog_parse_fd(&argc, &argv, 0);
if (*progfd < 0)
return *progfd;
@@ -1046,7 +1046,7 @@ static int parse_attach_detach_args(int argc, char **argv, int *progfd,
if (!REQ_ARGS(2))
return -EINVAL;
- *mapfd = map_parse_fd(&argc, &argv);
+ *mapfd = map_parse_fd(&argc, &argv, 0);
if (*mapfd < 0)
return *mapfd;
@@ -1270,7 +1270,7 @@ static int do_run(int argc, char **argv)
if (!REQ_ARGS(4))
return -1;
- fd = prog_parse_fd(&argc, &argv);
+ fd = prog_parse_fd(&argc, &argv, 0);
if (fd < 0)
return -1;
@@ -1542,7 +1542,7 @@ static int load_with_options(int argc, char **argv, bool first_prog_only)
}
NEXT_ARG();
- fd = map_parse_fd(&argc, &argv);
+ fd = map_parse_fd(&argc, &argv, 0);
if (fd < 0)
goto err_free_reuse_maps;
@@ -2231,7 +2231,7 @@ static int do_profile(int argc, char **argv)
return -EINVAL;
/* parse target fd */
- profile_tgt_fd = prog_parse_fd(&argc, &argv);
+ profile_tgt_fd = prog_parse_fd(&argc, &argv, 0);
if (profile_tgt_fd < 0) {
p_err("failed to parse fd");
return -1;
Add the flags parameter to map_parse_fd(), prog_parse_fd(), link_parse_fd() and btf_parse_fd() at the same time, as those functions are passed to do_pin_any(). Pass zero to those functions, so that the current behavior does not change, and adjust permissions in a later patch. Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> --- tools/bpf/bpftool/btf.c | 6 +++--- tools/bpf/bpftool/cgroup.c | 4 ++-- tools/bpf/bpftool/common.c | 10 +++++----- tools/bpf/bpftool/iter.c | 2 +- tools/bpf/bpftool/link.c | 7 ++++--- tools/bpf/bpftool/main.h | 7 ++++--- tools/bpf/bpftool/map.c | 6 +++--- tools/bpf/bpftool/net.c | 2 +- tools/bpf/bpftool/prog.c | 10 +++++----- 9 files changed, 28 insertions(+), 26 deletions(-)