BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jiayuan Chen" <jiayuan.chen@linux.dev>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf 05/11] bpf, sockmap: Fix concurrent senders on one psock
Date: Sat, 21 Nov 2026 10:53:55 +0000	[thread overview]
Message-ID: <sashiko-outbox-226959@kernel.org> (raw)
In-Reply-To: <20261121103222.88209-6-jiayuan.chen@linux.dev>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] bpf, sockmap: -EBUSY from tcp_bpf_sendmsg() aborts
  sk_psock_backlog()
--

commit d941631cdccff7e72d215bc4dd09b124e439b443
Author: Jiayuan Chen <jiayuan.chen@linux.dev>

bpf, sockmap: Fix concurrent senders on one psock

This commit adds an SK_PSOCK_TX_BUSY state bit to reject concurrent
callers of tcp_bpf_sendmsg() on the same psock with -EBUSY.

> diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c
> index 7191b95c7b1c7..077b65927ac8d 100644
> --- a/net/ipv4/tcp_bpf.c
> +++ b/net/ipv4/tcp_bpf.c
> @@ -602,6 +602,16 @@ static int tcp_bpf_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
>  	if (unlikely(!psock))
>  		return tcp_sendmsg(sk, msg, size);
>  
> +	/*
> +	 * The verdict, apply_bytes, sk_redir and the cork live in the psock
> +	 * and span the places where the socket lock is dropped below. They
> +	 * can only serve one sender at a time.
> +	 */
> +	if (test_and_set_bit(SK_PSOCK_TX_BUSY, &psock->state)) {
> +		sk_psock_put(sk, psock);
> +		return -EBUSY;
> +	}

[Severity: High]
Can returning -EBUSY here abort sk_psock_backlog() when an sk_buff is
redirected to the egress of a socket that also has a msg_parser program
attached?

For egress sk_buff redirects, sk_psock_handle_skb() sends the packet via
skb_send_sock() -> sendmsg_unlocked() -> sock_sendmsg() ->
tcp_bpf_sendmsg().  Previously, skb_send_sock() and a userspace sendmsg()
on that socket serialized on lock_sock(sk).  With this change, when a
userspace sender sleeps in sk_stream_wait_memory() with SK_PSOCK_TX_BUSY
set and freeing send buffer space wakes sk_psock_write_space(), the
backlog work runs and hits -EBUSY:

CPU0 (userspace sendmsg)          CPU1 (psock->work)
tcp_bpf_sendmsg()
  test_and_set_bit(SK_PSOCK_TX_BUSY, ...)
  lock_sock(sk)
  ...
  sk_stream_wait_memory()
    release_sock(sk)
                                  sk_psock_backlog()
                                    sk_psock_handle_skb()
                                      skb_send_sock()
                                        ...
                                          tcp_bpf_sendmsg()
                                            test_and_set_bit(SK_PSOCK_TX_BUSY)
                                            return -EBUSY

sk_psock_backlog() only retries on -EAGAIN and treats any other error as
fatal:

net/core/skmsg.c:sk_psock_backlog() {
	...
			if (ret <= 0) {
				if (ret == -EAGAIN) {
					...
					goto end;
				}
				/* Hard errors break pipe and stop xmit. */
				sk_psock_report_error(psock, ret ? -ret : EPIPE);
				sk_psock_clear_state(psock, SK_PSOCK_TX_ENABLED);
				goto end;
			}
	...
}

This sets sk->sk_err = EBUSY (which also aborts the sleeping userspace
sendmsg()) and permanently clears SK_PSOCK_TX_ENABLED, stranding queued
packets in psock->ingress_skb.  Conversely, if sk_psock_backlog() sets
SK_PSOCK_TX_BUSY first, a single userspace sender on the socket fails
with -EBUSY instead of waiting on lock_sock(sk).

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

  reply	other threads:[~2026-11-21 10:53 UTC|newest]

Thread overview: 16+ 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 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 [this message]
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
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 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-226959@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