From: sashiko-bot@kernel.org
To: "Weiming Shi" <bestswngs@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf v2] bpf: Fix NULL pointer dereference in bpf_sk_storage_clone and diag paths
Date: Wed, 22 Apr 2026 16:43:02 +0000 [thread overview]
Message-ID: <20260422164303.475A8C19425@smtp.kernel.org> (raw)
In-Reply-To: <20260421155024.997077-2-bestswngs@gmail.com>
Sashiko AI review found 1 potential issue(s):
- [High] The NULL pointer dereference fix in the diag paths is incomplete due to a Time-Of-Check to Time-Of-Use (TOCTOU) race condition in `diag_get()`.
--
commit 89ba4092c0928afed16ec4db32d2b5ffaa88889b
Author: Weiming Shi <bestswngs@gmail.com>
bpf: Fix NULL pointer dereference in bpf_sk_storage_clone and diag paths
This commit adds NULL checks for the storage map pointer in
bpf_sk_storage_clone() and bpf_sk_storage_diag_put_all() to prevent a
NULL pointer dereference when racing with a concurrent storage map removal.
> diff --git a/net/core/bpf_sk_storage.c b/net/core/bpf_sk_storage.c
> index 14eb7812bda4a..b2cd2b0292cb6 100644
> --- a/net/core/bpf_sk_storage.c
> +++ b/net/core/bpf_sk_storage.c
[ ... ]
> @@ -596,6 +596,8 @@ static int bpf_sk_storage_diag_put_all(struct sock *sk, struct sk_buff *skb,
> saved_len = skb->len;
> hlist_for_each_entry_rcu(selem, &sk_storage->list, snode) {
> smap = rcu_dereference(SDATA(selem)->smap);
> + if (!smap)
> + continue;
> diag_size += nla_value_size(smap->map.value_size);
>
> if (nla_stgs && diag_get(SDATA(selem), skb))
Can this still trigger a NULL pointer dereference due to a race condition?
If a concurrent unlinking operation sets the storage map pointer to NULL
after the check above, but before diag_get() executes, it looks like
diag_get() could still read the NULL pointer:
net/core/bpf_sk_storage.c:diag_get() {
...
smap = rcu_dereference(sdata->smap);
if (nla_put_u32(skb, SK_DIAG_BPF_STORAGE_MAP_ID, smap->map.id))
...
}
Because rcu_dereference() re-fetches the pointer from memory, it could now
return NULL, leading to a crash on the smap->map.id access.
Would it be safer to pass the already-validated smap pointer directly to
diag_get() as an argument, or add a NULL check inside diag_get() itself?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260421155024.997077-2-bestswngs@gmail.com?part=1
prev parent reply other threads:[~2026-04-22 16:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-21 15:50 [PATCH bpf v2] bpf: Fix NULL pointer dereference in bpf_sk_storage_clone and diag paths Weiming Shi
2026-04-21 16:24 ` bot+bpf-ci
2026-04-21 16:29 ` Amery Hung
2026-04-22 16:43 ` sashiko-bot [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=20260422164303.475A8C19425@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bestswngs@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=sashiko@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