From: Simon Horman <horms@kernel.org>
To: rhkrqnwk98@gmail.com
Cc: 'Simon Horman' <horms@kernel.org>,
edumazet@google.com, ncardwell@google.com, davem@davemloft.net,
kuba@kernel.org, pabeni@redhat.com, kuniyu@google.com,
brakmo@fb.com, ast@kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH net] tcp: clear sock_ops cb flags before force-closing a child socket
Date: Wed, 10 Jun 2026 14:46:34 +0100 [thread overview]
Message-ID: <20260610134633.428711-2-horms@kernel.org> (raw)
In-Reply-To: <20260605094954.1374489-1-rhkrqnwk98@gmail.com>
From: 'Simon Horman' <horms@kernel.org>
This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
Full review at: https://sashiko.dev
---
tcp: clear sock_ops cb flags before force-closing a child socket
This patch clears the inherited bpf_sock_ops_cb_flags on a child socket
before inet_csk_prepare_forced_close() drops the socket lock, so the
subsequent tcp_done() does not invoke tcp_call_bpf() without the lock and
trip sock_owned_by_me(). The fix is applied at the put_and_exit labels in
tcp_v4_syn_recv_sock() and tcp_v6_syn_recv_sock().
> diff --git a/include/net/tcp.h b/include/net/tcp.h
> index 98848db62894..97eac5fa341c 100644
> --- a/include/net/tcp.h
> +++ b/include/net/tcp.h
> @@ -2942,6 +2942,11 @@ static inline int tcp_call_bpf_3arg(struct sock *sk, int op, u32 arg1, u32 arg2,
> return tcp_call_bpf(sk, op, 3, args);
> }
>
> +static inline void tcp_clear_sock_ops_cb_flags(struct sock *sk)
> +{
> + tcp_sk(sk)->bpf_sock_ops_cb_flags = 0;
> +}
> +
> #else
[ ... ]
> diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
> index fdc81150ff6c..7748668dba82 100644
> --- a/net/ipv4/tcp_ipv4.c
> +++ b/net/ipv4/tcp_ipv4.c
> @@ -1783,6 +1783,7 @@ struct sock *tcp_v4_syn_recv_sock(const struct sock *sk, struct sk_buff *skb,
> return NULL;
> put_and_exit:
> newinet->inet_opt = NULL;
> + tcp_clear_sock_ops_cb_flags(newsk);
> inet_csk_prepare_forced_close(newsk);
> tcp_done(newsk);
> goto exit;
[High]
Should the same clearing also be added to chtls_recv_sock() in
drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c?
That function clones a child via tcp_create_openreq_child() ->
inet_csk_clone_lock() (which inherits the listener's
bpf_sock_ops_cb_flags), and on its error paths (dst lookup, neighbour
lookup, port mismatch, chtls_sock_create(), or l2t_entry allocation
failure) it falls through to free_sk:
drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c:chtls_recv_sock() {
[ ... ]
free_sk:
inet_csk_prepare_forced_close(newsk);
tcp_done(newsk);
free_oreq:
chtls_reqsk_free(oreq);
return NULL;
}
That sequence looks like it would hit the same sock_owned_by_me() warning
in tcp_set_state() -> tcp_call_bpf() if BPF_SOCK_OPS_STATE_CB_FLAG was set
on the listener, which is the case the commit message describes.
Would it be more robust to clear the cb flags inside
inet_csk_prepare_forced_close() itself so the invariant holds for every
present and future caller, or alternatively to add
tcp_clear_sock_ops_cb_flags(newsk) at the chtls free_sk label as well?
prev parent reply other threads:[~2026-06-10 13:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-05 9:49 [PATCH net] tcp: clear sock_ops cb flags before force-closing a child socket Sechang Lim
2026-06-05 11:16 ` Jiayuan Chen
2026-06-10 13:46 ` Simon Horman [this message]
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=20260610134633.428711-2-horms@kernel.org \
--to=horms@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brakmo@fb.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rhkrqnwk98@gmail.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