From: sashiko-bot@kernel.org
To: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v3 4/5] bpftool: Add option to wait for program stream output
Date: Fri, 25 Sep 2026 05:15:21 +0000 [thread overview]
Message-ID: <20260925051521.7D8D41F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260925045536.1480933-5-memxor@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] bpf: bpftool deadlock in exit_stream signal handler
--
commit 482ed48b5d6910c6aec52e854a7926f6f16ce58a
Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>
bpftool: Add option to wait for program stream output
bpftool prog tracelog { stdout | stderr } PROG dumps the output buffered
in a program stream and exits, which is all BPF_PROG_STREAM_READ_BY_FD
allows. Waiting for further output means rerunning the command.
> diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
> index 24e40dfab4690..5e27b22444f25 100644
> --- a/tools/bpf/bpftool/prog.c
> +++ b/tools/bpf/bpftool/prog.c
> @@ -1119,21 +1119,66 @@ enum prog_tracelog_mode {
> TRACE_STDERR,
> };
>
> +static void exit_stream(int signo)
> +{
> + exit(0);
> +}
> +
[Severity: Medium]
Since exit_stream() is used as a signal handler for SIGINT, SIGHUP, and
SIGTERM, is it safe to call exit(0) here?
exit() is not async-signal-safe and attempts to flush open stdio streams.
If the signal interrupts the main loop in prog_tracelog_stream() while it
is executing fwrite() or fflush(), it could try to acquire the same
non-reentrant lock, resulting in a deadlock.
Could _exit(0) be used instead to avoid this deadlock?
[ ... ]
> + /*
> + * Exit from the handler like the trace pipe variant does. A flag checked
> + * between reads would miss a signal that lands before read() blocks and
> + * only end the loop at the next print.
> + */
> + for (i = 0; i < ARRAY_SIZE(signals); i++)
> + sigaction(signals[i], &act, NULL);
> + while ((ret = read(fd, buf, sizeof(buf))) > 0) {
> + fwrite(buf, sizeof(buf[0]), ret, file);
> + fflush(file);
> + }
> + if (ret < 0)
> + p_err("failed to read stream: %s", strerror(errno));
> + close(fd);
> +out:
> fflush(file);
> return ret ? -1 : 0;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260925045536.1480933-1-memxor@gmail.com?part=4
next prev parent reply other threads:[~2026-09-25 5:15 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-25 4:55 [PATCH bpf-next v3 0/5] File descriptor interface for BPF streams Kumar Kartikeya Dwivedi
2026-09-25 4:55 ` [PATCH bpf-next v3 1/5] bpf: Skip zero-length stream writes Kumar Kartikeya Dwivedi
2026-09-25 4:55 ` [PATCH bpf-next v3 2/5] bpf: Add file descriptor interface for program streams Kumar Kartikeya Dwivedi
2026-09-25 4:55 ` [PATCH bpf-next v3 3/5] libbpf: Add bpf_prog_stream_open() Kumar Kartikeya Dwivedi
2026-09-25 4:55 ` [PATCH bpf-next v3 4/5] bpftool: Add option to wait for program stream output Kumar Kartikeya Dwivedi
2026-09-25 5:15 ` sashiko-bot [this message]
2026-09-25 6:13 ` Kumar Kartikeya Dwivedi
2026-09-25 14:22 ` Quentin Monnet
2026-09-25 4:55 ` [PATCH bpf-next v3 5/5] selftests/bpf: Test program stream file descriptors Kumar Kartikeya Dwivedi
2026-09-25 6:14 ` [PATCH bpf-next v3 0/5] File descriptor interface for BPF streams Kumar Kartikeya Dwivedi
2026-09-25 21:10 ` patchwork-bot+netdevbpf
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=20260925051521.7D8D41F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=memxor@gmail.com \
--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