All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Cen Zhang (Microsoft Security FORGE Labs)"
	<cenzhang@linux.microsoft.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf v2] bpf: Fix NULL pointer dereference in __bpf_sk_storage_map_seq_show
Date: Fri, 11 Sep 2026 14:28:07 +0000	[thread overview]
Message-ID: <20260911142808.1B1581F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260911140308.81560-1-cenzhang@linux.microsoft.com>

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

Pre-existing issues:
- [High] Passing `sk_storage->owner` to the BPF program in `__bpf_sk_storage_map_seq_show` introduces a Use-After-Free for non-RCU-safe sockets because the socket memory can be synchronously freed concurrently.
--

commit 64d29cd038f4fabc766558da2cca84aac8eec45a
Author: Cen Zhang (Microsoft Security FORGE Labs) <cenzhang@linux.microsoft.com>

bpf: Fix NULL pointer dereference in __bpf_sk_storage_map_seq_show

Iterating a sk_storage map is a two-stage operation:
bpf_sk_storage_map_seq_find_next() returns a selem, then
__bpf_sk_storage_map_seq_show() uses it. The latter re-reads
selem->local_storage via rcu_dereference() without checking for NULL.

Link: https://lore.kernel.org/all/CAMB2axNFOC9G2RwOCnsWDth83REMWnmPE8gxMwbLYoGusw9miA@mail.gmail.com/
Link: https://lore.kernel.org/all/c3f2a61d-d5bc-454c-987d-717b5f8c8809@linux.dev/

> diff --git a/net/core/bpf_sk_storage.c b/net/core/bpf_sk_storage.c
> index 1d295a8769fad..7d02245aa7049 100644
> --- a/net/core/bpf_sk_storage.c
> +++ b/net/core/bpf_sk_storage.c
> @@ -806,6 +806,8 @@ static int __bpf_sk_storage_map_seq_show(struct seq_file *seq,
>  		ctx.map = info->map;
>  		if (selem) {
>  			sk_storage = rcu_dereference(selem->local_storage);
> +			if (!sk_storage)
> +				return SEQ_SKIP;
>  			ctx.sk = sk_storage->owner;

[Severity: High]
This is a pre-existing issue, but does assigning the socket pointer to ctx.sk
without taking a reference or ensuring RCU protection introduce a
use-after-free risk for non-RCU-safe sockets?

For sockets that are not RCU-safe, such as UNIX domain sockets, the socket
memory can be synchronously freed. If CPU 1 is delayed after reading
selem->local_storage in __bpf_sk_storage_map_seq_show(), CPU 2 can execute
the final sock_put() and call __sk_destruct().

Because SOCK_RCU_FREE is not set, __sk_destruct() immediately calls
bpf_sk_storage_free() followed by sk_prot_free(sk), which frees the socket
memory to the slab allocator.

When CPU 1 resumes, it will call bpf_iter_run_prog(prog, &ctx) with ctx.sk
pointing to freed memory.

>  			ctx.value = SDATA(selem)->data;
>  		}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260911140308.81560-1-cenzhang@linux.microsoft.com?part=1

  parent reply	other threads:[~2026-09-11 14:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-11 14:03 [PATCH bpf v2] bpf: Fix NULL pointer dereference in __bpf_sk_storage_map_seq_show Cen Zhang (Microsoft Security FORGE Labs)
2026-09-11 14:24 ` luoxuanqiang
2026-09-11 14:28 ` sashiko-bot [this message]
2026-09-11 15:34   ` Cen Zhang (Microsoft Security FORGE Labs)

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=20260911142808.1B1581F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=cenzhang@linux.microsoft.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.