BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Gabriele Monaco" <gmonaco@redhat.com>,
	linux-trace-kernel@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH v3 09/18] tools/rv: Implement BPF monitor discovery and listing
Date: Thu, 26 Nov 2026 13:17:59 +0000	[thread overview]
Message-ID: <sashiko-outbox-235588@kernel.org> (raw)
In-Reply-To: <20261126130004.127155-10-gmonaco@redhat.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] tools/rv: path truncation checked after open in
  bpf_object_iterate_path()
- [Low] tools/rv: uncoordinated monitor listing in rv_list() and
  ikm_list_monitors()
--

commit 4abb124d92aede7d5ee4cdd253273b42ad6b0fdc
Author: Gabriele Monaco <gmonaco@redhat.com>

tools/rv: Implement BPF monitor discovery and listing

This commit adds libbpf detection to the rv build configuration and
implements discovery and listing of compiled BPF monitor object files
for rv list.

> diff --git a/tools/verification/rv/src/bpf_monitor.c b/tools/verification/rv/src/bpf_monitor.c
> new file mode 100644
> index 0000000000000..a5767617c7200
> --- /dev/null
> +++ b/tools/verification/rv/src/bpf_monitor.c

[ ... ]

> +static void bpf_object_iterate_path(const char *base_path, const char *subdir,
> +				    void (*action)(const char *name, struct bpf_object *obj))
> +{
> +	char path[MAX_PATH];
> +	struct dirent *entry;
> +	DIR *dir;
> +	char *ext;
> +
> +	snprintf(path, sizeof(path), "%s/%s", base_path, subdir);
> +	dir = opendir(path);
> +	if (!dir) {
> +		debug_msg("bpf: error opening directory: %s\n", path);
> +		return;
> +	}
> +
> +	while ((entry = readdir(dir)) != NULL) {
> +		size_t size;
> +		struct bpf_object *obj;
> +		char name[MAX_DA_NAME_LEN], obj_path[MAX_PATH];
> +
> +		if (entry->d_name[0] == '.')
> +			continue;
> +
> +		ext = strrchr(entry->d_name, '.');
> +		if (!ext || strcmp(ext, ".o") != 0)
> +			continue;
> +
> +		size = (size_t)(ext - entry->d_name);
> +		if (size >= MAX_DA_NAME_LEN) {
> +			err_msg("bpf: name too long, skipping %s/%s\n", path,
> +				entry->d_name);
> +			continue;
> +		}
> +		memcpy(name, entry->d_name, size);
> +		name[size] = '\0';
> +
> +		size = snprintf(obj_path, sizeof(obj_path), "%s/%s", path,
> +				entry->d_name);
> +		obj = bpf_object__open_file(obj_path, NULL);
> +		if (!obj || size >= MAX_PATH) {
> +			err_msg("bpf: error opening object file %s: %s\n",
> +				obj_path, strerror(errno));
> +			continue;
> +		}

[Severity: Low]
Should size >= MAX_PATH be checked before calling bpf_object__open_file()?

When the formatted path reaches MAX_PATH, bpf_object__open_file() is
invoked on a truncated obj_path.  If opening the truncated path succeeds,
the size >= MAX_PATH branch logs a stale errno and continues without
calling bpf_object__close(obj), leaking obj.  Also, the earlier
snprintf(path, sizeof(path), "%s/%s", base_path, subdir) does not check
for truncation when formatting base_path (which is itself sized MAX_PATH).

[ ... ]

> diff --git a/tools/verification/rv/src/rv.c b/tools/verification/rv/src/rv.c
> index 09e0d85986196..7c4a2e49ff9d1 100644
> --- a/tools/verification/rv/src/rv.c
> +++ b/tools/verification/rv/src/rv.c
> @@ -13,6 +13,7 @@
>  #include <trace.h>
>  #include <utils.h>
>  #include <in_kernel.h>
> +#include <bpf_monitor.h>
>  
>  static int stop_session;
>  
> @@ -76,6 +77,7 @@ static void rv_list(int argc, char **argv)
>  	}
>  
>  	ikm_list_monitors(container);
> +	bpf_list_monitors(container);
>  
>  	exit(EXIT_SUCCESS);
>  }

[Severity: Low]
Does calling ikm_list_monitors() and bpf_list_monitors() independently
produce broken output when no in-kernel monitors are registered or listed?

tools/verification/rv/src/in_kernel.c:ikm_list_monitors() {
	available_monitors = tracefs_instance_file_read(NULL, "rv/available_monitors", NULL);

	if (!available_monitors) {
		err_msg("ikm: available monitors is not available, is CONFIG_RV enabled?\n");
		return -1;
	}

	curr = available_monitors;
	do {
		next = strstr(curr, "\n");
		*next = '\0';

		retval = ikm_fill_monitor_definition(curr, &ikm, container);
		if (retval < 0)
			err_msg("ikm: error reading %d in kernel monitor, skipping\n", curr);
    ...
	if (!list_monitor) {
		if (container)
			printf("-- No monitor found in container %s --\n", container);
		else
			printf("-- No monitor found --\n");
	}
}

When CONFIG_RV is enabled without any in-kernel CONFIG_RV_MON_* monitors,
rv/available_monitors is 0 bytes and tracefs_instance_file_read() returns
NULL, so ikm_list_monitors() prints the error asking if CONFIG_RV is
enabled before bpf_list_monitors() lists the BPF monitors (and if an empty
string were returned, strstr(curr, "\n") would return NULL and *next = '\0'
would dereference NULL).  Even when in-kernel monitors exist, if none are
printed, ikm_list_monitors() prints "-- No monitor found --" right before
bpf_list_monitors() prints the available BPF monitors.  In addition, the
error message in ikm_list_monitors() formats curr (char *) with %d instead
of %s.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126130004.127155-1-gmonaco@redhat.com?part=9

  reply	other threads:[~2026-11-26 13:18 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 12:59 [PATCH v3 00/18] rv: Add support for BPF monitors Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 01/18] sched: Add task enqueue/dequeue trace points Gabriele Monaco
2026-11-26 13:13   ` sashiko-bot
2026-11-26 12:59 ` [PATCH v3 02/18] tools/rv: Skip empty pid error in selftest if command failed Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 03/18] rv: Add wrapper macros for monitor tracepoint definitions Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 04/18] rv: Propagate const to model strings and tracepoints Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 05/18] rv: Add generic monitor event tracepoints and BPF kfuncs Gabriele Monaco
2026-11-26 13:24   ` sashiko-bot
2026-11-26 12:59 ` [PATCH v3 06/18] tools/build: Add a feature test for bpftool-btf Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 07/18] tools/rv: Move argument parsing from in_kernel to utils Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 08/18] tools/rv: Move monitor trace handling to trace.c Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 09/18] tools/rv: Implement BPF monitor discovery and listing Gabriele Monaco
2026-11-26 13:17   ` sashiko-bot [this message]
2026-11-26 12:59 ` [PATCH v3 10/18] tools/rv: Implement BPF monitor loading and tracing Gabriele Monaco
2026-11-26 13:14   ` sashiko-bot
2026-11-26 12:59 ` [PATCH v3 11/18] tools/rv: Rework tracing to support generic events Gabriele Monaco
2026-11-26 13:13   ` sashiko-bot
2026-11-26 12:59 ` [PATCH v3 12/18] tools/rv: Copy stripped bpf_atomic.h from libarena Gabriele Monaco
2026-11-26 12:59 ` [PATCH v3 13/18] tools/rv: Add BPF monitors Gabriele Monaco
2026-11-26 13:24   ` sashiko-bot
2026-11-26 13:00 ` [PATCH v3 14/18] tools/rv: Define CONFIG_X86_64 statically for " Gabriele Monaco
2026-11-26 13:00 ` [PATCH v3 15/18] tools/rv: Add -E/--errors-only option Gabriele Monaco
2026-11-26 13:00 ` [PATCH v3 16/18] verification/rvgen: Add support for BPF monitors Gabriele Monaco
2026-11-26 13:14   ` sashiko-bot
2026-11-26 13:00 ` [PATCH v3 17/18] tools/rv: Add selftest for rv bpf monitors Gabriele Monaco
2026-11-26 13:00 ` [PATCH v3 18/18] verification/rvgen: Add selftest for rvgen -b Gabriele Monaco

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-235588@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=gmonaco@redhat.com \
    --cc=linux-trace-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox