BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jiayuan Chen" <jiayuan.chen@linux.dev>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v3 3/7] bpf, sockmap: zero-initialize pages allocated in bpf_msg_push_data
Date: Fri, 12 Jun 2026 13:34:05 +0000	[thread overview]
Message-ID: <20260612133405.C1D341F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260612130919.299124-4-jiayuan.chen@linux.dev>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] bpf_msg_push_data() reads from an unused scatterlist element when appending data to a full ring buffer, leading to ring buffer collapse and memory leak.
--

commit e3a134650540250c479e1e8112bfc1b9991ae703
Author: Weiming Shi <bestswngs@gmail.com>

bpf, sockmap: zero-initialize pages allocated in bpf_msg_push_data

This patch ensures that pages allocated in bpf_msg_push_data() are zeroed
by adding the __GFP_ZERO flag to the alloc_pages() call. This prevents
stale heap content, including kernel pointers, from being transmitted to
userspace.

Link: https://lore.kernel.org/all/20260424155913.A19FDC19425@smtp.kernel.org

> diff --git a/net/core/filter.c b/net/core/filter.c
> index 3e555f276ba80..6e345ca65ca14 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -2832,7 +2832,7 @@ BPF_CALL_4(bpf_msg_push_data, struct sk_msg *, msg, u32, start,
>  	if (unlikely(copy + len < copy))
>  		return -EINVAL;
>  
> -	page = alloc_pages(__GFP_NOWARN | GFP_ATOMIC | __GFP_COMP,
> +	page = alloc_pages(__GFP_NOWARN | GFP_ATOMIC | __GFP_COMP | __GFP_ZERO,
>  			   get_order(copy + len));

[Severity: High]
This isn't a bug introduced by this patch, but is it possible for
bpf_msg_push_data() in net/core/filter.c to read from an unused scatterlist
element when appending data to a full ring buffer?

When appending data to the end of the message (start == total_length), the
scatterlist iteration loop exits with i == msg->sg.end.

If the ring buffer is full (space == 0), the code attempts to coalesce the new
data with an existing fragment to free up a slot:

	if (!space || (space == 1 && start != offset))
		copy = msg->sg.data[i].length;

Since i == msg->sg.end, this points to the unused, zero-initialized separator
slot.

As a result, copy evaluates to 0, the coalescing path is skipped, and the new
fragment is unconditionally appended to the full ring buffer.

Does this unconditionally advance msg->sg.end and cause it to equal
msg->sg.start (since MAX_MSG_FRAGS + 1 wraps around)?

If so, sk_msg_elem_used() would return 0, making the message appear empty,
collapsing the entire ring buffer, and leaking all previously allocated
scatterlist pages.

>  	if (unlikely(!page))
>  		return -ENOMEM;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260612130919.299124-1-jiayuan.chen@linux.dev?part=3

  reply	other threads:[~2026-06-12 13:34 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-12 13:07 [PATCH bpf-next v3 0/7] bpf, skmsg: some fixes for skmsg Jiayuan Chen
2026-06-12 13:07 ` [PATCH bpf-next v3 1/7] bpf, sockmap: reject overflowing copy + len in bpf_msg_push_data() Jiayuan Chen
2026-06-12 13:28   ` sashiko-bot
2026-06-13  0:09   ` Kuniyuki Iwashima
2026-06-12 13:07 ` [PATCH bpf-next v3 2/7] bpf, sockmap: Fix wrong rsge offset " Jiayuan Chen
2026-06-12 13:27   ` sashiko-bot
2026-06-13  0:17   ` Kuniyuki Iwashima
2026-06-12 13:07 ` [PATCH bpf-next v3 3/7] bpf, sockmap: zero-initialize pages allocated in bpf_msg_push_data Jiayuan Chen
2026-06-12 13:34   ` sashiko-bot [this message]
2026-06-13  0:28   ` Kuniyuki Iwashima
2026-06-13  1:36     ` Alexei Starovoitov
2026-06-12 13:07 ` [PATCH bpf-next v3 4/7] bpf, sockmap: keep sk_msg copy state in sync Jiayuan Chen
2026-06-12 13:57   ` bot+bpf-ci
2026-06-13  0:40   ` Kuniyuki Iwashima
2026-06-12 13:07 ` [PATCH bpf-next v3 5/7] sockmap: Fix use-after-free in udp_bpf_recvmsg() Jiayuan Chen
2026-06-12 13:24   ` sashiko-bot
2026-06-12 13:07 ` [PATCH bpf-next v3 6/7] bpf, sockmap: fix integer overflow in bpf_msg_pop_data() bounds check Jiayuan Chen
2026-06-13  0:44   ` Kuniyuki Iwashima
2026-06-12 13:07 ` [PATCH bpf-next v3 7/7] selftests/bpf: add test for bpf_msg_pop_data() overflow Jiayuan Chen
2026-06-12 17:09 ` [PATCH bpf-next v3 0/7] bpf, skmsg: some fixes for skmsg Alexei Starovoitov
2026-06-12 18:43   ` Kuniyuki Iwashima

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=20260612133405.C1D341F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=jiayuan.chen@linux.dev \
    --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