From: Cong Wang <xiyou.wangcong@gmail.com>
To: Dong Chenchen <dongchenchen2@huawei.com>
Cc: edumazet@google.com, kuniyu@amazon.com, pabeni@redhat.com,
willemb@google.com, john.fastabend@gmail.com,
jakub@cloudflare.com, davem@davemloft.net, kuba@kernel.org,
horms@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org,
bpf@vger.kernel.org, stfomichev@gmail.com, mrpre@163.com,
zhangchangzhong@huawei.com, weiyongjun1@huawei.com
Subject: Re: [PATCH net 1/2] bpf, sockmap: Avoid sk_prot reset on sockmap unlink with ULP set
Date: Wed, 19 Mar 2025 16:42:28 -0700 [thread overview]
Message-ID: <Z9tWZPaidMB4uvQu@pop-os.localdomain> (raw)
In-Reply-To: <20250314082004.2369712-2-dongchenchen2@huawei.com>
On Fri, Mar 14, 2025 at 04:20:03PM +0800, Dong Chenchen wrote:
> WARNING: CPU: 0 PID: 6558 at net/core/sock_map.c:1703 sock_map_close+0x3c4/0x480
> Modules linked in:
> CPU: 0 UID: 0 PID: 6558 Comm: syz-executor.14 Not tainted 6.14.0-rc5+ #238
> RIP: 0010:sock_map_close+0x3c4/0x480
> Call Trace:
> <TASK>
> inet_release+0x144/0x280
> __sock_release+0xb8/0x270
> sock_close+0x1e/0x30
> __fput+0x3c6/0xb30
> __fput_sync+0x7b/0x90
> __x64_sys_close+0x90/0x120
> do_syscall_64+0x5d/0x170
> entry_SYSCALL_64_after_hwframe+0x76/0x7e
>
> The root cause is:
> bpf_prog_attach(BPF_SK_SKB_STREAM_VERDICT)
> tcp_set_ulp //set ulp after sockmap add
> icsk->icsk_ulp_ops = ulp_ops;
> sock_hash_update_common
> sock_map_unref
> sock_map_del_link
> psock->psock_update_sk_prot(sk, psock, false);
> sk->sk_prot->close = sock_map_close
> sk_psock_drop
> sk_psock_restore_proto
> tcp_bpf_update_proto
> tls_update //not redo sk_prot to tcp prot
> inet_release
> sk->sk_prot->close
> sock_map_close
> WARN(sk->sk_prot->close == sock_map_close)
This makes sense now. Please see my comment below.
>
> commit e34a07c0ae39 ("sock: redo the psock vs ULP protection check")
> has moved ulp check from tcp_bpf_update_proto() to psock init.
> If sk sets ulp after being added to sockmap, it will reset sk_prot to
> BPF_BASE when removed from sockmap. After the psock is dropped, it will
> not reset sk_prot back to the tcp prot, only tls context update is
> performed. This can trigger a warning in sock_map_close() due to
> recursion of sk->sk_prot->close.
>
> To fix this issue, skip the sk_prot operations redo when deleting link
> from sockmap if ULP is set.
>
> Fixes: e34a07c0ae39 ("sock: redo the psock vs ULP protection check")
> Fixes: c0d95d3380ee ("bpf, sockmap: Re-evaluate proto ops when psock is removed from sockmap")
> Signed-off-by: Dong Chenchen <dongchenchen2@huawei.com>
> ---
> net/core/sock_map.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/core/sock_map.c b/net/core/sock_map.c
> index 82a14f131d00..a3ed1f2cf8a2 100644
> --- a/net/core/sock_map.c
> +++ b/net/core/sock_map.c
> @@ -170,7 +170,7 @@ static void sock_map_del_link(struct sock *sk,
> if (verdict_stop)
> sk_psock_stop_verdict(sk, psock);
>
> - if (psock->psock_update_sk_prot)
> + if (!(sk_is_inet(sk) && inet_csk_has_ulp(sk)) && psock->psock_update_sk_prot)
> psock->psock_update_sk_prot(sk, psock, false);
Can we put this TCP-specific logic into tcp_bpf_update_proto() instead?
Something like this...
diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c
index ba581785adb4..0bb363447fc7 100644
--- a/net/ipv4/tcp_bpf.c
+++ b/net/ipv4/tcp_bpf.c
@@ -708,6 +708,8 @@ int tcp_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore)
return 0;
}
+ if (inet_csk_has_ulp(sk))
+ return 0;
if (sk->sk_family == AF_INET6) {
if (tcp_bpf_assert_proto_ops(psock->sk_proto))
return -EINVAL;
next prev parent reply other threads:[~2025-03-19 23:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-14 8:20 [PATCH net 0/2] bpf, sockmap: Avoid sk_prot reset on sockmap unlink with ULP set Dong Chenchen
2025-03-14 8:20 ` [PATCH net 1/2] " Dong Chenchen
2025-03-19 23:42 ` Cong Wang [this message]
2025-03-14 8:20 ` [PATCH net 2/2] selftests: bpf: Add case for sockmap_ktls set when verdict attached Dong Chenchen
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=Z9tWZPaidMB4uvQu@pop-os.localdomain \
--to=xiyou.wangcong@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dongchenchen2@huawei.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jakub@cloudflare.com \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=kuniyu@amazon.com \
--cc=mrpre@163.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stfomichev@gmail.com \
--cc=weiyongjun1@huawei.com \
--cc=willemb@google.com \
--cc=zhangchangzhong@huawei.com \
/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;
as well as URLs for NNTP newsgroup(s).