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 05/18] rv: Add generic monitor event tracepoints and BPF kfuncs
Date: Thu, 26 Nov 2026 13:24:27 +0000 [thread overview]
Message-ID: <sashiko-outbox-235594@kernel.org> (raw)
In-Reply-To: <20261126130004.127155-6-gmonaco@redhat.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] rv: undefined tracepoint symbols when CONFIG_RV_MON_EVENTS is
unset
- [Medium] rv: TOCTOU unbounded strlen() after strnlen() in
bpf_rv_*_monitor()
- [Low] rv: missing @id__nullable kernel-doc description in rv_bpf.c
--
commit 12ad0d7960250beaac1afe9380fabf830419122f
Author: Gabriele Monaco <gmonaco@redhat.com>
rv: Add generic monitor event tracepoints and BPF kfuncs
This commit adds generic event_monitor and error_monitor tracepoints along
with bpf_rv_event_monitor() and bpf_rv_error_monitor() BPF kfuncs so BPF
monitors can emit RV events and errors.
> diff --git a/kernel/trace/rv/Makefile b/kernel/trace/rv/Makefile
> index c895d81dfdad9..588250ce3fa93 100644
> --- a/kernel/trace/rv/Makefile
> +++ b/kernel/trace/rv/Makefile
> @@ -3,6 +3,7 @@
> ccflags-y += -I $(src) # needed for trace events
>
> obj-$(CONFIG_RV) += rv.o
> +obj-$(CONFIG_RV) += rv_bpf.o
> obj-$(CONFIG_RV_MON_WIP) += monitors/wip/wip.o
> obj-$(CONFIG_RV_MON_WWNR) += monitors/wwnr/wwnr.o
> obj-$(CONFIG_RV_MON_SCHED) += monitors/sched/sched.o
[Severity: Medium]
Does this fail to link when CONFIG_RV=y is enabled without any in-kernel C
monitor?
rv_bpf.o is built whenever CONFIG_RV is set and calls trace_event_monitor()
and trace_error_monitor(), but CREATE_TRACE_POINTS in kernel/trace/rv/rv.c
is only defined under CONFIG_RV_MON_EVENTS:
kernel/trace/rv/rv.c:
#ifdef CONFIG_RV_MON_EVENTS
#define CREATE_TRACE_POINTS
#include <rv_trace.h>
#endif
CONFIG_RV_MON_EVENTS is only selected by the in-kernel C monitor options
(all of which default to n), so a BPF-only RV build leaves
__tracepoint_event_monitor, __tracepoint_error_monitor, and their static
call symbols undefined at link time.
> diff --git a/kernel/trace/rv/rv_bpf.c b/kernel/trace/rv/rv_bpf.c
> new file mode 100644
> index 0000000000000..f39f33335c71b
> --- /dev/null
> +++ b/kernel/trace/rv/rv_bpf.c
> @@ -0,0 +1,76 @@
[ ... ]
> +/**
> + * bpf_rv_event_monitor - emit an RV monitor event tracepoint
> + *
> + * @msg must be NULL-terminated, drop the event if it isn't. This happens by
> + * construction if using snprintf-like functions and passing the right @msg__sz
> + * to both.
> + *
> + * @mon__str: name of the monitor
> + * @msg: message string
> + * @msg__sz: message string size
> + *
> + * Return -EINVAL if @msg is not NULL-terminated, 0 otherwise.
> + */
> +__bpf_kfunc int bpf_rv_event_monitor(const char *mon__str, const int *id__nullable,
> + const char *msg, u32 msg__sz)
[Severity: Low]
Both bpf_rv_event_monitor() and bpf_rv_error_monitor() use kernel-doc
comments but omit @id__nullable, which triggers kernel-doc warnings under
W=1 builds.
> +{
> + if (strnlen(msg, msg__sz) == msg__sz)
> + return -EINVAL;
> +
> + trace_event_monitor(mon__str, id__nullable, msg);
> + return 0;
> +}
> +
> +/**
> + * bpf_rv_error_monitor - emit an RV monitor error tracepoint
> + *
> + * @msg must be NULL-terminated, drop the event if it isn't. This happens by
> + * construction if using snprintf-like functions and passing the right @msg__sz
> + * to both.
> + *
> + * @mon__str: name of the monitor
> + * @msg: message string
> + * @msg__sz: message string size
> + *
> + * Return -EINVAL if @msg is not NULL-terminated, 0 otherwise.
> + */
> +__bpf_kfunc int bpf_rv_error_monitor(const char *mon__str, const int *id__nullable,
> + const char *msg, u32 msg__sz)
> +{
> + if (strnlen(msg, msg__sz) == msg__sz)
> + return -EINVAL;
> +
> + trace_error_monitor(mon__str, id__nullable, msg);
> + return 0;
> +}
[Severity: Medium]
Can a concurrent update to msg after strnlen() cause trace_event_monitor()
or trace_error_monitor() to read past msg + msg__sz?
For the (const char *msg, u32 msg__sz) kfunc argument pair, the BPF
verifier accepts any writable BPF memory region of size msg__sz, including
shared BPF map values. event_template_monitor uses __string(msg, msg),
which runs an unbounded strlen(msg) and memcpy() after strnlen() has
already returned:
CPU0 CPU1
bpf_rv_event_monitor(mon, id,
msg, msg__sz)
strnlen(msg, msg__sz) < msg__sz
/* overwrites NUL byte in shared
* BPF map value backing msg
*/
trace_event_monitor(mon, id, msg)
strlen(msg)
memcpy(..., msg, ...) <-- out-of-bounds read past msg__sz
Reading past the end of a BPF map allocation can fault on an unmapped
vmalloc guard page or copy adjacent kernel memory into the trace ring
buffer. Passing the length returned by strnlen() into the tracepoint and
using __string_len() in event_template_monitor would bound the copy without
re-scanning msg.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126130004.127155-1-gmonaco@redhat.com?part=5
next prev parent reply other threads:[~2026-11-26 13:24 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 [this message]
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
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-235594@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