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]
Message-ID: <aea8ec32-4b9b-194e-2369-95bc6ad1119d@netronome.com>
Date:   Mon, 15 Apr 2019 10:18:31 +0100
From:   Quentin Monnet <quentin.monnet@...ronome.com>
To:     Benjamin Poirier <bpoirier@...e.com>,
        Daniel Borkmann <daniel@...earbox.net>
Cc:     Jakub Kicinski <jakub.kicinski@...ronome.com>,
        David Ahern <dsahern@...il.com>, netdev@...r.kernel.org,
        bpf@...r.kernel.org
Subject: Re: [PATCH v3 bpf-next 1/2] bpftool: Use print_entry_error() in case
 of ENOENT when dumping

2019-04-15 16:15 UTC+0900 ~ Benjamin Poirier <bpoirier@...e.com>
> Commit bf598a8f0f77 ("bpftool: Improve handling of ENOENT on map dumps")
> used print_entry_plain() in case of ENOENT. However, that commit introduces
> dead code. Per-cpu maps are zero-filled. When reading them, it's all or
> nothing. There will never be a case where some cpus have an entry and
> others don't.
> 
> The truth is that ENOENT is an error case. Use print_entry_error() to
> output the desired message. That function's "value" parameter is also
> renamed to indicate that we never use it for an actual map value.
> 
> The output format is unchanged.
> 
> Signed-off-by: Benjamin Poirier <bpoirier@...e.com>
> ---
>   tools/bpf/bpftool/map.c | 33 ++++++++++++++-------------------
>   1 file changed, 14 insertions(+), 19 deletions(-)
> 
> diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
> index e96903078991..df958af56b6c 100644
> --- a/tools/bpf/bpftool/map.c
> +++ b/tools/bpf/bpftool/map.c
> @@ -261,20 +261,20 @@ static void print_entry_json(struct bpf_map_info *info, unsigned char *key,
>   }
>   
>   static void print_entry_error(struct bpf_map_info *info, unsigned char *key,
> -			      const char *value)
> +			      const char *error_msg)
>   {
> -	int value_size = strlen(value);
> +	int msg_size = strlen(error_msg);
>   	bool single_line, break_names;
>   
> -	break_names = info->key_size > 16 || value_size > 16;
> -	single_line = info->key_size + value_size <= 24 && !break_names;
> +	break_names = info->key_size > 16 || msg_size > 16;
> +	single_line = info->key_size + msg_size <= 24 && !break_names;
>   
>   	printf("key:%c", break_names ? '\n' : ' ');
>   	fprint_hex(stdout, key, info->key_size, " ");
>   
>   	printf(single_line ? "  " : "\n");
>   
> -	printf("value:%c%s", break_names ? '\n' : ' ', value);
> +	printf("value:%c%s", break_names ? '\n' : ' ', error_msg);
>   
>   	printf("\n");
>   }
> @@ -298,11 +298,7 @@ static void print_entry_plain(struct bpf_map_info *info, unsigned char *key,
>   
>   		if (info->value_size) {
>   			printf("value:%c", break_names ? '\n' : ' ');
> -			if (value)
> -				fprint_hex(stdout, value, info->value_size,
> -					   " ");
> -			else
> -				printf("<no entry>");
> +			fprint_hex(stdout, value, info->value_size, " ");
>   		}
>   
>   		printf("\n");
> @@ -321,11 +317,8 @@ static void print_entry_plain(struct bpf_map_info *info, unsigned char *key,
>   			for (i = 0; i < n; i++) {
>   				printf("value (CPU %02d):%c",
>   				       i, info->value_size > 16 ? '\n' : ' ');
> -				if (value)
> -					fprint_hex(stdout, value + i * step,
> -						   info->value_size, " ");
> -				else
> -					printf("<no entry>");
> +				fprint_hex(stdout, value + i * step,
> +					   info->value_size, " ");
>   				printf("\n");
>   			}
>   		}
> @@ -722,11 +715,13 @@ static int dump_map_elem(int fd, void *key, void *value,
>   		jsonw_string_field(json_wtr, "error", strerror(lookup_errno));
>   		jsonw_end_object(json_wtr);
>   	} else {
> +		const char *msg = NULL;
> +
>   		if (errno == ENOENT)
> -			print_entry_plain(map_info, key, NULL);
> -		else
> -			print_entry_error(map_info, key,
> -					  strerror(lookup_errno));
> +			msg = "<no entry>";
> +
> +		print_entry_error(map_info, key,
> +				  msg ? : strerror(lookup_errno));

(Nit: This would now fit on a single line, but no need to respin just 
for that.)

Thanks!
Reviewed-by: Quentin Monnet <quentin.monnet@...ronome.com>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ