From: Khawar Ahemad <ahemadkhawar123@gmail.com>
To: bpf@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, ast@kernel.org,
daniel@iogearbox.net, andrii@kernel.org, eddyz87@gmail.com,
memxor@gmail.com, ahemadkhawar123@gmail.com
Subject: [PATCH bpf-next] bpf: Fix stream capacity leak and spurious -ENOSPC in bpf_stream_stage_commit
Date: Tue, 25 Aug 2026 17:09:48 +0530 [thread overview]
Message-ID: <20260825113948.85020-1-ahemadkhawar123@gmail.com> (raw)
bpf_stream_stage_commit() accounts the staged string length against
the stream capacity via bpf_stream_consume_capacity() before
detaching the queued elements with llist_del_all().
If no elements are returned by llist_del_all() (for instance, when
the staging list was empty or failed to allocate elements), the
function returns early without releasing the consumed capacity.
Because no elements are queued into stream->log, no reader will ever
pop or release this capacity, leading to a permanent capacity leak.
Furthermore, if ss->len is 0, bpf_stream_consume_capacity() is invoked
needlessly and fails with -ENOSPC if the stream is currently at
capacity, spuriously rejecting a zero-byte commit.
Fix both issues by:
1. Returning early if ss->len is 0.
2. Rolling back the consumed capacity with bpf_stream_release_capacity()
if llist_del_all() returns NULL.
Fixes: 5ab154f1463a ("bpf: Introduce BPF standard streams")
Signed-off-by: Khawar Ahemad <ahemadkhawar123@gmail.com>
---
kernel/bpf/stream.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/kernel/bpf/stream.c b/kernel/bpf/stream.c
index 7a5c3ac867..3ad58c8284 100644
--- a/kernel/bpf/stream.c
+++ b/kernel/bpf/stream.c
@@ -350,15 +350,21 @@ int bpf_stream_stage_commit(struct bpf_stream_stage *ss, struct bpf_prog *prog,
if (!stream)
return -EINVAL;
+ if (!ss->len)
+ return 0;
+
ret = bpf_stream_consume_capacity(stream, ss->len);
if (ret)
return ret;
list = llist_del_all(&ss->log);
- head = tail = list;
-
- if (!list)
+ if (!list) {
+ bpf_stream_release_capacity(stream, ss->len);
return 0;
+ }
+
+ head = list;
+ tail = list;
while (llist_next(list)) {
tail = llist_next(list);
list = tail;
--
2.54.0 (Apple Git-157)
next reply other threads:[~2026-08-25 11:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-25 11:39 Khawar Ahemad [this message]
2026-08-25 11:57 ` [PATCH bpf-next] bpf: Fix stream capacity leak and spurious -ENOSPC in bpf_stream_stage_commit Khawar Ahemad
2026-08-25 12:18 ` Kumar Kartikeya Dwivedi
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=20260825113948.85020-1-ahemadkhawar123@gmail.com \
--to=ahemadkhawar123@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=memxor@gmail.com \
/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