All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Igor Malovitsa" <igor.malovitsa@gmail.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf 1/2] bpf: Load ringbuf consumer_pos under the spinlock
Date: Fri, 16 Oct 2026 00:47:02 +0000	[thread overview]
Message-ID: <sashiko-outbox-173535@kernel.org> (raw)
In-Reply-To: <20261016003318.529860-2-igor.malovitsa@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] bpf: ABI compat break for 32-bit userspace on 64-bit ringbuffer
--

commit 2d8c0038759a4aa9aef622680e46c8ac2c7b7e99
Author: Igor Malovitsa <igor.malovitsa@gmail.com>

bpf: Load ringbuf consumer_pos under the spinlock

__bpf_ringbuf_reserve() loads consumer_pos before taking the spinlock.
Nothing bounds how stale that value is when the lock is finally taken.
This patch moves the load of consumer_pos inside the spinlock to ensure
it is exact.

> diff --git a/kernel/bpf/ringbuf.c b/kernel/bpf/ringbuf.c
> index 3f1013d805446..6b86c4db51088 100644
> --- a/kernel/bpf/ringbuf.c
> +++ b/kernel/bpf/ringbuf.c
> @@ -473,11 +473,12 @@ static void *__bpf_ringbuf_reserve(struct bpf_ringbuf *rb, u64 size)
>  	if (len > ringbuf_total_data_sz(rb))
>  		return NULL;
>  
> -	cons_pos = smp_load_acquire(&rb->consumer_pos);
> -
>  	if (raw_res_spin_lock_irqsave(&rb->spinlock, flags))
>  		return NULL;
>  
> +	/* Under the lock, so at most one ring behind producer_pos. */
> +	cons_pos = smp_load_acquire(&rb->consumer_pos);

[Severity: High]
Does this code handle 32-bit userspace running on a 64-bit kernel correctly?

Since consumer_pos and producer_pos are defined as unsigned long in
struct bpf_ringbuf, they are 64-bit on a 64-bit kernel but treated as
32-bit by 32-bit userspace applications.

On little-endian architectures, 32-bit userspace updates only the lower
32 bits. When the userspace counter wraps after 4GB, it writes 0.

Since the kernel's 64-bit producer_pos will exceed 4GB, new_prod_pos -
cons_pos evaluates to a value greater than 4GB.

Because this value is larger than the ringbuffer mask, does this cause the
kernel to incorrectly believe the ringbuffer is permanently full?

Can an unprivileged 32-bit process trigger this state after 4GB of traffic,
causing a permanent DoS on the map?

> +
>  	pend_pos = rb->pending_pos;
>  	prod_pos = rb->producer_pos;
>  	new_prod_pos = prod_pos + len;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261016003318.529860-1-igor.malovitsa@gmail.com?part=1

  reply	other threads:[~2026-10-16  0:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16  0:33 [PATCH bpf 0/2] bpf: Fix ring buffer checks on 32-bit position wrap Igor Malovitsa
2026-10-16  0:33 ` [PATCH bpf 1/2] bpf: Load ringbuf consumer_pos under the spinlock Igor Malovitsa
2026-10-16  0:47   ` sashiko-bot [this message]
2026-10-16  0:33 ` [PATCH bpf 2/2] bpf: Fix user ringbuf empty check on 32-bit position wrap Igor Malovitsa

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-173535@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=igor.malovitsa@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 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.