Re: [PATCH bpf 08/11] bpf, sockmap: Fix socket lock taken on a child before accept()

From: bot+bpf-ci

Date: Sat Nov 21 2026 - 06:26:59 EST


> bpf, sockmap: Fix socket lock taken on a child before accept()

TL;DR: Behaviour change question: sk_msg ingress redirects to not-yet-accepted
children now fail with -EINVAL instead of queueing, and with
bpf_msg_cork_bytes() send() may report success while dropping data. Intended?

> diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c
> --- a/net/ipv4/tcp_bpf.c
> +++ b/net/ipv4/tcp_bpf.c

[ ... ]

> @@ -188,9 +188,17 @@ static int tcp_bpf_push_locked(struct sock *sk, struct sk_msg *msg,
> int tcp_bpf_sendmsg_redir(struct sock *sk, bool ingress,
> struct sk_msg *msg, u32 bytes, int flags)
> {
> - struct sk_psock *psock = sk_psock_get(sk);
> + struct sk_psock *psock;
> int ret;
>
> + /*
> + * The listener frees a child that nobody has accepted yet without
> + * waiting for the owner of its socket lock.
> + */
> + if (!READ_ONCE(sk->sk_socket))
> + return sock_flag(sk, SOCK_DEAD) ? -EPIPE : -EINVAL;

Before this patch, an ingress redirect (BPF_F_INGRESS) to a peer that the
server has not accepted yet queued the data on the psock, and the server
read it after accept(). Is this change in behavior intended?

A common setup adds the client at BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB and
the server child at BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB, and the client's
sk_msg program redirects to the peer with BPF_F_INGRESS. If the client
sends before the server calls accept(), the child still has
sk->sk_socket == NULL, so this now returns -EINVAL.

The old path was:

tcp_bpf_sendmsg_redir(child, ingress=true)
bpf_tcp_ingress()
lock_sock(child)
sk_psock_queue_msg()
sk_psock_data_ready()

and tcp_bpf_recvmsg() read psock->ingress_msg after accept(). The comment
in tcp_bpf_recvmsg_parser() ("We may have received data on the
sk_receive_queue pre-accept ...") suggests pre-accept data on a sockmap
child is a supported state.

For a plain send(), this means the call fails depending on whether it runs
before the server's accept().

With bpf_msg_cork_bytes(), the failure looks worse. In
tcp_bpf_send_verdict():

if (unlikely(ret < 0)) {
int free = sk_msg_free(sk, msg);

if (!cork)
*copied -= free;
}
...
if (cork) {
sk_msg_free(sk, msg);
kfree(msg);
msg = NULL;
ret = 0;
}

For a corked message the data is freed, ret is set to 0 and *copied is left
unchanged, so can send() report success while the bytes are dropped from
the TCP stream?

Also, sk_psock_skb_ingress() still queues to unaccepted children, so
sk_skb and sk_msg redirects now behave differently.

The commit message says "Refuse the ingress redirect too". It does not
mention that a redirect which used to deliver now fails, or that corked
data can be dropped. Could the ingress case avoid the WARN_ON without
refusing delivery, or should this behavior change be stated and justified?

>
> + psock = sk_psock_get(sk);
> if (unlikely(!psock))
> return -EPIPE;


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/44896626218