From: sashiko-bot@kernel.org
To: "Jiayuan Chen" <jiayuan.chen@linux.dev>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf 08/11] bpf, sockmap: Fix socket lock taken on a child before accept()
Date: Sat, 21 Nov 2026 10:56:08 +0000 [thread overview]
Message-ID: <sashiko-outbox-226962@kernel.org> (raw)
In-Reply-To: <20261121103222.88209-9-jiayuan.chen@linux.dev>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] bpf, sockmap: lock_sock() still taken on unaccepted child in
strp_done()
--
commit e631a931dbfb1352e17feb424d762db532b4db74
Author: Jiayuan Chen <jiayuan.chen@linux.dev>
bpf, sockmap: Fix socket lock taken on a child before accept()
This commit avoids taking lock_sock() on unaccepted child sockets (where
sk->sk_socket is NULL) by rejecting sk_msg redirects in
tcp_bpf_sendmsg_redir() before locking and by unlinking such sockets
without locking in sock_map_free() and sock_hash_free().
> diff --git a/net/core/sock_map.c b/net/core/sock_map.c
> index d8187a9823d18..8cf8ba6269561 100644
> --- a/net/core/sock_map.c
> +++ b/net/core/sock_map.c
> @@ -386,6 +386,19 @@ static int sock_map_link(struct bpf_map *map, struct sock *sk)
> return ret;
> }
>
> +/*
> + * The listener frees a child that nobody has accepted yet without waiting
> + * for the owner of its socket lock. Unlink such a child without the lock,
> + * as a delete does.
> + */
> +static bool sock_map_free_lock_sk(struct sock *sk)
> +{
> + if (!READ_ONCE(sk->sk_socket))
> + return false;
> + lock_sock(sk);
> + return true;
> +}
> +
> static void sock_map_free(struct bpf_map *map)
> {
> struct bpf_stab *stab = container_of(map, struct bpf_stab, map);
> @@ -402,12 +415,15 @@ static void sock_map_free(struct bpf_map *map)
>
> sk = xchg(psk, NULL);
> if (sk) {
> + bool locked;
> +
> sock_hold(sk);
> - lock_sock(sk);
> + locked = sock_map_free_lock_sk(sk);
> rcu_read_lock();
> sock_map_unref(sk, psk);
> rcu_read_unlock();
> - release_sock(sk);
> + if (locked)
> + release_sock(sk);
> sock_put(sk);
> }
> }
[Severity: Medium]
Can asynchronous psock teardown still take lock_sock(sk) on an unaccepted
child when the map has a stream parser attached?
When a passive TCP child is added at BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB to
a map with stream_parser and stream_verdict programs, sock_map_link()
starts the stream parser on the child and sets SK_PSOCK_RX_STRP_ENABLED.
Even though sock_map_free() and sock_hash_free() skip lock_sock(sk) here,
sock_map_unref() queues sk_psock_destroy() via sock_map_del_link() and
sk_psock_put(), which runs sk_psock_done_strp() -> strp_done():
net/strparser/strparser.c:strp_done() {
WARN_ON(!strp->stopped);
lock_sock(strp->sk);
/* sync with pending strp_recv */
release_sock(strp->sk);
...
}
If the listener closes while sk_psock_destroy() runs on the workqueue
before accept(), strp_done() locks the unaccepted child and
inet_csk_listen_stop() can still hit WARN_ON(sock_owned_by_user(child)).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261121103222.88209-1-jiayuan.chen@linux.dev?part=8
next prev parent reply other threads:[~2026-11-21 10:56 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 10:30 [PATCH bpf 00/11] fix misc sockmap issues Jiayuan Chen
2026-11-21 10:30 ` [PATCH bpf 01/11] bpf, sockmap: Fix copied_seq updates with strparser Jiayuan Chen
2026-11-21 10:59 ` sashiko-bot
2026-11-21 10:30 ` [PATCH bpf 02/11] selftests/bpf: Add test for unread SK_PASS data " Jiayuan Chen
2026-11-21 10:59 ` sashiko-bot
2026-11-21 10:30 ` [PATCH bpf 03/11] bpf, sockmap: Fix strparser reinit after the parser link is removed Jiayuan Chen
2026-11-21 11:04 ` sashiko-bot
2026-11-21 10:30 ` [PATCH bpf 04/11] bpf, sockmap: Fix empty sk_msg queued by ingress redirect Jiayuan Chen
2026-11-21 10:30 ` [PATCH bpf 05/11] bpf, sockmap: Fix concurrent senders on one psock Jiayuan Chen
2026-11-21 10:53 ` sashiko-bot
2026-11-21 10:30 ` [PATCH bpf 06/11] bpf, sockmap: Fix reconnect with a psock by rejecting disconnect Jiayuan Chen
2026-11-21 10:30 ` [PATCH bpf 07/11] bpf, sockmap: Fix psock refcnt taken in sk_psock_backlog() Jiayuan Chen
2026-11-21 10:30 ` [PATCH bpf 08/11] bpf, sockmap: Fix socket lock taken on a child before accept() Jiayuan Chen
2026-11-21 10:56 ` sashiko-bot [this message]
2026-11-21 10:30 ` [PATCH bpf 09/11] bpf, sockmap: Fix apply_bytes when a redirect sends only a part Jiayuan Chen
2026-11-21 11:11 ` bot+bpf-ci
2026-11-21 10:30 ` [PATCH bpf 10/11] selftests/bpf: Fix errno expected by the wait send mem test of test_sockmap Jiayuan Chen
2026-11-21 10:30 ` [PATCH bpf 11/11] selftests/bpf: Add test for apply_bytes when a redirect sends a part Jiayuan Chen
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-226962@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