Thread View: linux.kernel.netdev
56 messages
56 total messages
Page 2 of 2
Started by Alexei Starovoitov
Mon, 02 Nov 2026 07:20
Page 2 of 2 • 56 total messages
Re: [PATCH bpf v2 03/15] bpf, sockmap: Don't let an SK_PASS verdict cover the next message
Author: "Alexei Starovoitov"
Date: Wed, 04 Nov 2026 02:04
Date: Wed, 04 Nov 2026 02:04
12 lines
11823 bytes
11823 bytes
On Tue, Nov 03, 2026 at 05:32 PM Jiayuan Chen <jiayuan.chen@linux.dev> wrote: >> The log of patch 13 says that a cork is not safe for two senders. >> Jiayuan proposed to serialize the senders in the reply to that patch. > > > I will pick up thoes pre-existing issues and organize others reported by sashiko. Thanks, but make sure to create reproducers for all sashiko findings. Most of them are wrong. I'm waiting for netdev maintainers to ack net/core/ bits.
Re: [PATCH bpf v2 08/15] net: Leave sk_stream_wait_memory() once the socket is dead
Author: Eric Dumazet
Date: Wed, 04 Nov 2026 05:23
Date: Wed, 04 Nov 2026 05:23
93 lines
12876 bytes
12876 bytes
Le lun. 2 nov. 2026 à 08:22, Alexei Starovoitov
<alexei.starovoitov@gmail.com> a écrit :
>
> From: Alexei Starovoitov <ast@kernel.org>
>
> When an sk_msg prog redirects data to the egress of another socket, the
> sender calls tcp_sendmsg_locked() on that socket. The sender holds a
> reference to the sock, but not to its file. Thus __tcp_close() can call
> sock_orphan() while the sender sleeps in sk_stream_wait_memory().
> sock_orphan() sets SOCK_DEAD and sets sk_wq to NULL.
>
> After the sleep the loop continues and does not test SOCK_DEAD. The
> subsequent sk_set_bit() can dereference the NULL sk_wq. The tests of sk_err
> and sk_shutdown do not always stop the sender. sock_error() clears sk_err,
> and __tcp_close() can call tcp_disconnect(), which clears sk_shutdown. The
> sender then adds data to the write queue of the dead socket, and
> inet_sock_destruct() warns.
>
> Leave the loop with -EPIPE when the socket is dead after the sleep. The
> function already tests SOCK_DEAD before remove_wait_queue() for the same
> reason. A caller that has the socket open never sees SOCK_DEAD.
>
> Fixes: 4f738adba30a ("bpf: create tcp_bpf_ulp allowing BPF to monitor socket TX/RX data")
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
> ---
> net/core/stream.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/net/core/stream.c b/net/core/stream.c
> index cb255e2a3a5d..334124d683a7 100644
> --- a/net/core/stream.c
> +++ b/net/core/stream.c
> @@ -150,7 +150,11 @@ int sk_stream_wait_memory(struct sock *sk, long *timeo_p)
> (sk_stream_memory_free(sk) && !vm_wait),
> &wait);
> sk->sk_write_pending--;
> - if (ret < 0)
> + /*
> + * A sender which sockmap has redirected to sk does not keep it
> + * open. A dead socket has no sk_wq.
> + */
> + if (ret < 0 || sock_flag(sk, SOCK_DEAD))
> goto do_error;
This is fine, but it only helps a sender that wakes up.
As you said in your reply to the bot on patch 07, nothing wakes it.
__tcp_close() sets sk_shutdown and calls sock_orphan() without a wakeup
on sk_sleep(sk), and once sk_wq is NULL, sk_stream_write_space() cannot
reach the sleeper either.
"A signal or SO_SNDTIMEO of the target ends it" does not look enough to
me. tcp_sendmsg_locked() takes the timeout from sock_sndtimeo() of the
target, a socket the sender does not own and cannot configure. With the
default MAX_SCHEDULE_TIMEOUT, a blocking sendmsg() on the sender's own
socket never returns, and the sender's sock_hold() pins the dead target
until then.
Since this patch makes SOCK_DEAD a reason to leave, one wakeup before
sock_orphan(), while the socket is still owned by the closer, should be
enough. The sender can only get the socket lock back after
sock_orphan(), so it sees SOCK_DEAD. Nothing walks the wait queue after
sock_orphan(), so skipping remove_wait_queue() stays safe.
Something like this (untested). sk_wq can be NULL here for MPTCP
subflows, hence skwq_has_sleeper():
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ void __tcp_close(struct sock *sk, long timeout)
adjudge_to_death:
state = sk->sk_state;
sock_hold(sk);
+ /* A sockmap egress redirect can sleep in sk_stream_wait_memory()
+ * without a reference on our file. Let it see SOCK_DEAD.
+ */
+ rcu_read_lock();
+ wq = rcu_dereference(sk->sk_wq);
+ if (skwq_has_sleeper(wq))
+ wake_up_interruptible_all(&wq->wait);
+ rcu_read_unlock();
sock_orphan(sk);
This can be a follow-up and does not need to block the series.
Re: [PATCH bpf v2 00/15] bpf, sockmap: Fixes for verdicts, redirects, corks and recvmsg()
Author: Eric Dumazet
Date: Wed, 04 Nov 2026 05:24
Date: Wed, 04 Nov 2026 05:24
31 lines
10028 bytes
10028 bytes
Le lun. 2 nov. 2026 à 21:11, John Fastabend <john.fastabend@gmail.com> a écrit : > > On Mon, Nov 02, 2026 at 07:20:57AM +0000, Alexei Starovoitov wrote: > >From: Alexei Starovoitov <ast@kernel.org> > > > >These patches fix bugs in sockmap: > > > > patches area > > ------- ---------------------------------------------------------------- > > 01 recvmsg() after a fault > > 02-04 the verdict of an sk_msg prog and the return value of sendmsg() > > 05 the backlog of a stopped psock > > 06 TCP listeners > > 07-08 the target of an egress redirect > > 09 the TCP state in recvmsg() > > 10-14 corks and the redirect target > > 15 bpf_msg_push_data() and bpf_msg_pop_data() > > > >8 of the patches are from Chris Mason and Josef Bacik. > > Thanks everyone lgtm. For the series. > > Reviewed-by: John Fastabend <john.fastabend@gmail.com> For the series: Reviewed-by: Eric Dumazet <edumazet@kernel.org>
Re: [PATCH bpf v2 08/15] net: Leave sk_stream_wait_memory() once the socket is dead
Author: "Alexei Starovoitov"
Date: Wed, 04 Nov 2026 18:32
Date: Wed, 04 Nov 2026 18:32
42 lines
13025 bytes
13025 bytes
On Tue, Nov 03, 2026 at 09:23 PM Eric Dumazet <edumazet@kernel.org> wrote: > "A signal or SO_SNDTIMEO of the target ends it" does not look enough to > me. tcp_sendmsg_locked() takes the timeout from sock_sndtimeo() of the > target, a socket the sender does not own and cannot configure. With the > default MAX_SCHEDULE_TIMEOUT, a blocking sendmsg() on the sender's own > socket never returns, and the sender's sock_hold() pins the dead target > until then. Right. It's not enough. > Since this patch makes SOCK_DEAD a reason to leave, one wakeup before > sock_orphan(), while the socket is still owned by the closer, should be > enough. The sender can only get the socket lock back after > sock_orphan(), so it sees SOCK_DEAD. Nothing walks the wait queue after > sock_orphan(), so skipping remove_wait_queue() stays safe. > > Something like this (untested). sk_wq can be NULL here for MPTCP > subflows, hence skwq_has_sleeper(): > > diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c > --- a/net/ipv4/tcp.c > +++ b/net/ipv4/tcp.c > @@ void __tcp_close(struct sock *sk, long timeout) > adjudge_to_death: > state = sk->sk_state; > sock_hold(sk); > + /* A sockmap egress redirect can sleep in sk_stream_wait_memory() > + * without a reference on our file. Let it see SOCK_DEAD. > + */ > + rcu_read_lock(); > + wq = rcu_dereference(sk->sk_wq); > + if (skwq_has_sleeper(wq)) > + wake_up_interruptible_all(&wq->wait); > + rcu_read_unlock(); > sock_orphan(sk); > > This can be a follow-up and does not need to block the series. Makes sense to me. Thx It depends on the SOCK_DEAD test, so it goes on top of this series. Will send it as a follow-up.
Re: [PATCH bpf v2 00/15] bpf, sockmap: Fixes for verdicts, redirects, corks and recvmsg()
Author: patchwork-bot+netdevbpf
Date: Wed, 04 Nov 2026 18:50
Date: Wed, 04 Nov 2026 18:50
60 lines
10927 bytes
10927 bytes
Hello:
This series was applied to bpf/bpf.git (master)
by Alexei Starovoitov <ast@kernel.org>:
On Mon, 2 Nov 2026 07:20:57 +0000 you wrote:
> From: Alexei Starovoitov <ast@kernel.org>
>
> These patches fix bugs in sockmap:
>
> patches area
> ------- ----------------------------------------------------------------
> 01 recvmsg() after a fault
> 02-04 the verdict of an sk_msg prog and the return value of sendmsg()
> 05 the backlog of a stopped psock
> 06 TCP listeners
> 07-08 the target of an egress redirect
> 09 the TCP state in recvmsg()
> 10-14 corks and the redirect target
> 15 bpf_msg_push_data() and bpf_msg_pop_data()
>
> [...]
Here is the summary with links:
- [bpf,v2,01/15] bpf, sockmap: Write sg.start when recvmsg() faults
https://git.kernel.org/bpf/bpf/c/b889ea1f6dbe
- [bpf,v2,02/15] bpf, sockmap: Don't let an SK_DROP verdict stick
https://git.kernel.org/bpf/bpf/c/436c4cfa071e
- [bpf,v2,03/15] bpf, sockmap: Don't let an SK_PASS verdict cover the next message
https://git.kernel.org/bpf/bpf/c/f4c044966d6c
- [bpf,v2,04/15] bpf, sockmap: Subtract all dropped bytes from the return value
https://git.kernel.org/bpf/bpf/c/fa84be67b5bc
- [bpf,v2,05/15] bpf, sockmap: Clear the resume state of a stopped psock
https://git.kernel.org/bpf/bpf/c/51e0f3d60be5
- [bpf,v2,06/15] bpf, sockmap: Give no progs to a TCP listener
https://git.kernel.org/bpf/bpf/c/7c036a39ba29
- [bpf,v2,07/15] bpf, sockmap: Check the target of an egress redirect before each send
https://git.kernel.org/bpf/bpf/c/4aeaad1c536e
- [bpf,v2,08/15] net: Leave sk_stream_wait_memory() once the socket is dead
https://git.kernel.org/bpf/bpf/c/430775a30b1f
- [bpf,v2,09/15] bpf, sockmap: Check the TCP state in recvmsg()
https://git.kernel.org/bpf/bpf/c/9f5763e6287a
- [bpf,v2,10/15] bpf, sockmap: Reset the copy position when corking
https://git.kernel.org/bpf/bpf/c/12c45473dfe7
- [bpf,v2,11/15] bpf, sockmap: Don't copy 0 bytes into a full cork
https://git.kernel.org/bpf/bpf/c/a912358996f8
- [bpf,v2,12/15] bpf, sockmap: Clear the redirect target before the sk_msg prog runs
https://git.kernel.org/bpf/bpf/c/e4c2fe0b9a62
- [bpf,v2,13/15] bpf, sockmap: Check that the redirected message is the cork
https://git.kernel.org/bpf/bpf/c/815cfc482e63
- [bpf,v2,14/15] bpf, sockmap: Keep the rest of the cork after a redirect
https://git.kernel.org/bpf/bpf/c/13c41b87e4a7
- [bpf,v2,15/15] bpf, sockmap: Clear the end mark of elements added by push and pop
https://git.kernel.org/bpf/bpf/c/0048086bd361
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Page 2 of 2 • 56 total messages
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads