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] [day] [month] [year] [list]
Date:   Wed, 22 May 2019 09:45:04 +0200
From:   Jakub Sitnicki <jakub@...udflare.com>
To:     "Daniel T. Lee" <danieltimlee@...il.com>
Cc:     Daniel Borkmann <daniel@...earbox.net>,
        Alexei Starovoitov <ast@...nel.org>, netdev@...r.kernel.org
Subject: Re: [PATCH] samples: bpf: fix style in bpf_load

On Wed, May 22, 2019 at 02:24 AM CEST, Daniel T. Lee wrote:
> This commit fixes style problem in samples/bpf/bpf_load.c
>
> Styles that have been changed are:
>  - Magic string use of 'DEBUGFS'
>  - Useless zero initialization of a global variable
>  - Minor style fix with whitespace
>
> Signed-off-by: Daniel T. Lee <danieltimlee@...il.com>
> ---
>  samples/bpf/bpf_load.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/samples/bpf/bpf_load.c b/samples/bpf/bpf_load.c
> index eae7b635343d..e71d23d2a0ff 100644
> --- a/samples/bpf/bpf_load.c
> +++ b/samples/bpf/bpf_load.c
> @@ -40,7 +40,7 @@ int prog_cnt;
>  int prog_array_fd = -1;
>
>  struct bpf_map_data map_data[MAX_MAPS];
> -int map_data_count = 0;
> +int map_data_count;
>
>  static int populate_prog_array(const char *event, int prog_fd)
>  {
> @@ -57,6 +57,7 @@ static int populate_prog_array(const char *event, int prog_fd)
>  static int write_kprobe_events(const char *val)
>  {
>  	int fd, ret, flags;
> +	char buf[256];
>
>  	if (val == NULL)
>  		return -1;
> @@ -65,7 +66,9 @@ static int write_kprobe_events(const char *val)
>  	else
>  		flags = O_WRONLY | O_APPEND;
>
> -	fd = open("/sys/kernel/debug/tracing/kprobe_events", flags);
> +	strcpy(buf, DEBUGFS);
> +	strcat(buf, "kprobe_events");
> +	fd = open(buf, flags);

No need to build the path at run-time. Compile-time string literal
concatenation will do in this case:

  fd = open(DEBUGFS "kprobe_events", flags);

-Jakub

>
>  	ret = write(fd, val, strlen(val));
>  	close(fd);
> @@ -490,8 +493,8 @@ static int load_elf_maps_section(struct bpf_map_data *maps, int maps_shndx,
>
>  		/* Verify no newer features were requested */
>  		if (validate_zero) {
> -			addr = (unsigned char*) def + map_sz_copy;
> -			end  = (unsigned char*) def + map_sz_elf;
> +			addr = (unsigned char *) def + map_sz_copy;
> +			end  = (unsigned char *) def + map_sz_elf;
>  			for (; addr < end; addr++) {
>  				if (*addr != 0) {
>  					free(sym);

Powered by blists - more mailing lists