lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 10 Dec 2019 17:29:18 +0000
From:   Quentin Monnet <quentin.monnet@...ronome.com>
To:     Paul Chaignon <paul.chaignon@...nge.com>, bpf@...r.kernel.org
Cc:     paul.chaignon@...il.com, netdev@...r.kernel.org,
        Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        Martin KaFai Lau <kafai@...com>,
        Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
        Andrii Nakryiko <andriin@...com>
Subject: Re: [PATCH bpf-next 1/3] bpftool: match several programs with same
 tag

Hi Paul,

2019-12-10 17:06 UTC+0100 ~ Paul Chaignon <paul.chaignon@...nge.com>
> When several BPF programs have the same tag, bpftool matches only the
> first (in ID order).  This patch changes that behavior such that dump and
> show commands return all matched programs.  Commands that require a single
> program (e.g., pin and attach) will error out if given a tag that matches
> several.  bpftool prog dump will also error out if file or visual are
> given and several programs have the given tag.
> 
> In the case of the dump command, a program header is added before each
> dump only if the tag matches several programs; this patch doesn't change
> the output if a single program matches.
> 
> Signed-off-by: Paul Chaignon <paul.chaignon@...nge.com>
> ---
>  .../bpftool/Documentation/bpftool-prog.rst    |  16 +-
>  tools/bpf/bpftool/prog.c                      | 371 ++++++++++++------
>  2 files changed, 272 insertions(+), 115 deletions(-)
> 

> diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
> index 4535c863d2cd..ca4278269e73 100644
> --- a/tools/bpf/bpftool/prog.c
> +++ b/tools/bpf/bpftool/prog.c
> @@ -25,6 +25,11 @@
>  #include "main.h"
>  #include "xlated_dumper.h"
>  
> +enum dump_mode {
> +	DUMP_JITED,
> +	DUMP_XLATED,
> +};
> +
>  static const char * const attach_type_strings[] = {
>  	[BPF_SK_SKB_STREAM_PARSER] = "stream_parser",
>  	[BPF_SK_SKB_STREAM_VERDICT] = "stream_verdict",
> @@ -77,11 +82,13 @@ static void print_boot_time(__u64 nsecs, char *buf, unsigned int size)
>  		strftime(buf, size, "%FT%T%z", &load_tm);
>  }
>  
> -static int prog_fd_by_tag(unsigned char *tag)
> +static int
> +prog_fd_by_tag(unsigned char *tag, int *fds)

Nit: No line break necessary if it fits on one line.
(Sorry for misleading you on that in an earlier discussion :/)

>  {
>  	unsigned int id = 0;
> +	int fd, nb_fds = 0;
> +	void *tmp;
>  	int err;
> -	int fd;
>  
>  	while (true) {
>  		struct bpf_prog_info info = {};

[...]

> @@ -351,21 +421,43 @@ static int show_prog(int fd)
>  
>  static int do_show(int argc, char **argv)
>  {
> +	int fd, nb_fds, i;
> +	int *fds = NULL;
>  	__u32 id = 0;
>  	int err;
> -	int fd;
>  
>  	if (show_pinned)
>  		build_pinned_obj_table(&prog_table, BPF_OBJ_PROG);
>  
>  	if (argc == 2) {
> -		fd = prog_parse_fd(&argc, &argv);
> -		if (fd < 0)
> +		fds = malloc(sizeof(int));
> +		if (!fds) {
> +			p_err("mem alloc failed");
>  			return -1;
> +		}
> +		nb_fds = prog_parse_fds(&argc, &argv, fds);
> +		if (nb_fds < 1)
> +			goto err_free;
>  
> -		err = show_prog(fd);
> -		close(fd);
> -		return err;
> +		if (json_output && nb_fds > 1)
> +			jsonw_start_array(json_wtr);	/* root array */
> +		for (i = 0; i < nb_fds; i++) {
> +			err = show_prog(fds[i]);
> +			close(fds[i]);
> +			if (err) {
> +				for (i++; i < nb_fds; i++)
> +					close(fds[i]);
> +				goto err_free;

Alternatively, we could keep trying to list the remaining programs. For
example, if the system has a long list of BPF programs running and one
of them is removed while printing the list, we would still have the rest
of the list.

If we went this way, maybe just set err to non-zero if no program at all
could be printed?

> +			}
> +		}
> +		if (json_output && nb_fds > 1)
> +			jsonw_end_array(json_wtr);	/* root array */
> +
> +		return 0;
> +
> +err_free:
> +		free(fds);
> +		return -1;
>  	}
>  
>  	if (argc)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ