All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
To: "Khawar Ahemad" <ahemadkhawar123@gmail.com>, <bpf@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <ast@kernel.org>,
	<daniel@iogearbox.net>, <andrii@kernel.org>, <eddyz87@gmail.com>
Subject: Re: [PATCH bpf-next] bpf: Fix stream capacity leak and spurious -ENOSPC in bpf_stream_stage_commit
Date: Tue, 25 Aug 2026 14:18:56 +0200	[thread overview]
Message-ID: <DKY0P97XUIG1.1AOV8WFUW5Z0H@gmail.com> (raw)
In-Reply-To: <20260825113948.85020-1-ahemadkhawar123@gmail.com>

On Tue Aug 25, 2026 at 1:39 PM CEST, Khawar Ahemad wrote:
> 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>
> ---

Completely unnecessary.

pw-bot: cr

>  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;


      parent reply	other threads:[~2026-08-25 12:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-25 11:39 [PATCH bpf-next] bpf: Fix stream capacity leak and spurious -ENOSPC in bpf_stream_stage_commit Khawar Ahemad
2026-08-25 11:56 ` sashiko-bot
2026-08-25 11:57 ` Khawar Ahemad
2026-08-25 12:18 ` Kumar Kartikeya Dwivedi [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=DKY0P97XUIG1.1AOV8WFUW5Z0H@gmail.com \
    --to=memxor@gmail.com \
    --cc=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 \
    /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.