All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Andrey Grodzovsky" <andrey.grodzovsky@crowdstrike.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v6 7/7] selftests/bpf: Convert veristat to BPF_PROG_LOAD_STRATEGY_MANUAL
Date: Sat, 10 Oct 2026 15:08:50 +0000	[thread overview]
Message-ID: <sashiko-outbox-166685@kernel.org> (raw)
In-Reply-To: <20261010143156.379864-8-andrey.grodzovsky@crowdstrike.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] bpf: veristat uninitialized memory read of log buffer on early load failure
- [Low] bpf: veristat skips cleanup and info retrieval when BPF program fd is 0
--

commit 9ac34aec88e7eee9b39c53e8055bc5989345ce5b
Author: Andrey Grodzovsky <andrey.grodzovsky@crowdstrike.com>
Subject: selftests/bpf: Convert veristat to BPF_PROG_LOAD_STRATEGY_MANUAL

This commit updates the veristat utility to verify programs using
BPF_PROG_LOAD_STRATEGY_MANUAL alongside bpf_program__load() and
bpf_program__unload(). It replaces the previous use of bpf_program__clone(),
ensuring RODATA maps are properly bound during verification and subsequently
dropped upon unload.

> diff --git a/tools/testing/selftests/bpf/veristat.c b/tools/testing/selftests/bpf/veristat.c
> index 9cfc9b4b41c12..0cd19b59037f6 100644
> --- a/tools/testing/selftests/bpf/veristat.c
> +++ b/tools/testing/selftests/bpf/veristat.c
[ ... ]
> @@ -1726,18 +1725,15 @@ static int process_prog(const char *filename, struct bpf_object *obj, struct bpf
>  	if (env.force_reg_invariants)
>  		bpf_program__add_flags(prog, BPF_F_TEST_REG_INVARIANTS);
>  
> -	opts.log_buf = buf;
> -	opts.log_size = buf_sz;
> -	opts.log_level = log_level;
> +	bpf_program__set_log_buf(prog, buf, buf_sz);
> +	bpf_program__set_log_level(prog, log_level);
>  
>  	cgroup_err = reset_stat_cgroup();
>  	mem_peak_a = cgroup_memory_peak();
> -	fd = bpf_program__clone(prog, &opts);
> -	if (fd < 0) {
> -		err = fd;
> -		if (env.verbose)
> -			fprintf(stderr, "Failed to load program %s %d\n", prog_name, err);
> -	}
> +	err = bpf_program__load(prog);

[Severity: Medium]
If bpf_program__load() returns an early error (e.g. from libbpf without
calling the kernel), could the dynamically allocated buf remain
uninitialized?

When env.verbose or env.top_src_lines > 0 is set, buf is allocated
via malloc() but the fallback initialization only null-terminates the
static array:

	if (env.verbose || env.top_src_lines > 0) {
		buf = malloc(buf_sz);
	...
	verif_log_buf[0] = '\0';

If bpf_program__load() returns early without modifying the buffer,
parse_verif_log(buf, ...) will read this uninitialized memory. Could
buf[0] = '\0' be set directly on buf before loading?

> +	fd = err == 0 ? bpf_program__fd(prog) : -1;

[Severity: Low]
If standard input is closed, can bpf_program__load() assign file descriptor
0 to the loaded program?

If fd 0 is assigned, later checks will explicitly skip handling it:

	if (fd > 0 && bpf_prog_get_info_by_fd(fd, &info, &info_len) == 0)

This causes the program's JIT statistics to be skipped. Should this check
test for fd >= 0 instead of fd > 0?

> +	if (err && env.verbose)
> +		fprintf(stderr, "Failed to load program %s %d\n", prog_name, err);
>  	mem_peak_b = cgroup_memory_peak();
>  	if (!cgroup_err && mem_peak_a >= 0 && mem_peak_b >= 0)
>  		mem_peak = mem_peak_b - mem_peak_a;
[ ... ]
> @@ -1774,7 +1770,7 @@ static int process_prog(const char *filename, struct bpf_object *obj, struct bpf
>  	if (verif_log_buf != buf)
>  		free(buf);
>  	if (fd > 0)
> -		close(fd);
> +		bpf_program__unload(prog);

[Severity: Low]
Similar to the issue above, if fd is 0, will this prevent the program from
being immediately unloaded and leave it in the kernel until the entire
BPF object is closed?

Should this check also use if (fd >= 0) to ensure cleanup occurs?

>  	return 0;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261010143156.379864-1-andrey.grodzovsky@crowdstrike.com?part=7

      reply	other threads:[~2026-10-10 15:08 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-10 14:31 [PATCH bpf-next v6 0/7] libbpf: BPF program manual loading Andrey Grodzovsky
2026-10-10 14:31 ` [PATCH bpf-next v6 1/7] libbpf: Reject gen_loader set after PREPARE step Andrey Grodzovsky
2026-10-10 15:21   ` bot+bpf-ci
2026-10-10 14:31 ` [PATCH bpf-next v6 2/7] libbpf: BPF program load strategy enum Andrey Grodzovsky
2026-10-10 14:31 ` [PATCH bpf-next v6 3/7] libbpf: BPF programs manual loading and attaching Andrey Grodzovsky
2026-10-10 14:31 ` [PATCH bpf-next v6 4/7] libbpf: Support declarative manual load via SEC("!...") prefix Andrey Grodzovsky
2026-10-10 15:06   ` sashiko-bot
2026-10-10 14:31 ` [PATCH bpf-next v6 5/7] selftests/bpf: Cover BPF program load strategy transitions Andrey Grodzovsky
2026-10-10 14:31 ` [PATCH bpf-next v6 6/7] selftests/bpf: Cover BPF program manual loading Andrey Grodzovsky
2026-10-10 15:03   ` sashiko-bot
2026-10-10 14:31 ` [PATCH bpf-next v6 7/7] selftests/bpf: Convert veristat to BPF_PROG_LOAD_STRATEGY_MANUAL Andrey Grodzovsky
2026-10-10 15:08   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-166685@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=andrey.grodzovsky@crowdstrike.com \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.