From: Gang Yan <gang.yan@linux.dev>
To: mptcp@lists.linux.dev
Cc: pabeni@redhat.com, Gang Yan <yangang@kylinos.cn>
Subject: [PATCH mptcp-next 2/5] mptcp: reject sockopt requiring ssks' lock in BPF context
Date: Mon, 13 Jul 2026 17:57:32 +0800 [thread overview]
Message-ID: <20260713095735.1222033-3-gang.yan@linux.dev> (raw)
In-Reply-To: <20260713095735.1222033-1-gang.yan@linux.dev>
From: Gang Yan <yangang@kylinos.cn>
Several MPTCP setsockopt handlers need to acquire the subflow lock
via lock_sock(ssk) to propagate settings to each subflow. This lock
can sleep and is therefore not usable in BPF context where sleeping
is forbidden.
The short-term solution is to make any sockopt operation that requires
subflow-level lock fail with -EOPNOTSUPP when called from BPF context.
Signed-off-by: Gang Yan <yangang@kylinos.cn>
---
net/mptcp/sockopt.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c
index 342aec7f9086..0c391247eb4c 100644
--- a/net/mptcp/sockopt.c
+++ b/net/mptcp/sockopt.c
@@ -185,6 +185,9 @@ static int mptcp_setsockopt_sol_socket_int(struct mptcp_sock *msk, int optname,
if (ret)
return ret;
+ if (has_current_bpf_ctx())
+ return -EOPNOTSUPP;
+
switch (optname) {
case SO_KEEPALIVE:
case SO_DEBUG:
@@ -218,6 +221,9 @@ static int mptcp_setsockopt_sol_socket_timestamping(struct mptcp_sock *msk,
struct so_timestamping timestamping;
int ret;
+ if (has_current_bpf_ctx())
+ return -EOPNOTSUPP;
+
if (optlen == sizeof(timestamping)) {
if (copy_from_sockptr(×tamping, optval,
sizeof(timestamping)))
@@ -265,6 +271,9 @@ static int mptcp_setsockopt_sol_socket_linger(struct mptcp_sock *msk, sockptr_t
sockptr_t kopt;
int ret;
+ if (has_current_bpf_ctx())
+ return -EOPNOTSUPP;
+
if (optlen < sizeof(ling))
return -EINVAL;
@@ -598,6 +607,9 @@ static int mptcp_setsockopt_sol_tcp_congestion(struct mptcp_sock *msk, sockptr_t
bool cap_net_admin;
int ret;
+ if (has_current_bpf_ctx())
+ return -EOPNOTSUPP;
+
if (optlen < 1)
return -EINVAL;
@@ -639,6 +651,9 @@ static int __mptcp_setsockopt_set_val(struct mptcp_sock *msk, int max,
struct mptcp_subflow_context *subflow;
int err = 0;
+ if (has_current_bpf_ctx())
+ return -EOPNOTSUPP;
+
mptcp_for_each_subflow(msk, subflow) {
struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
int ret;
@@ -662,6 +677,9 @@ static int __mptcp_setsockopt_sol_tcp_cork(struct mptcp_sock *msk, int val)
struct mptcp_subflow_context *subflow;
struct sock *sk = (struct sock *)msk;
+ if (has_current_bpf_ctx())
+ return -EOPNOTSUPP;
+
sockopt_seq_inc(msk);
msk->cork = !!val;
mptcp_for_each_subflow(msk, subflow) {
@@ -682,6 +700,9 @@ static int __mptcp_setsockopt_sol_tcp_nodelay(struct mptcp_sock *msk, int val)
struct mptcp_subflow_context *subflow;
struct sock *sk = (struct sock *)msk;
+ if (has_current_bpf_ctx())
+ return -EOPNOTSUPP;
+
sockopt_seq_inc(msk);
msk->nodelay = !!val;
mptcp_for_each_subflow(msk, subflow) {
@@ -749,6 +770,9 @@ static int mptcp_setsockopt_v4_set_tos(struct mptcp_sock *msk, int optname,
struct sock *sk = (struct sock *)msk;
int err, val;
+ if (has_current_bpf_ctx())
+ return -EOPNOTSUPP;
+
err = ip_setsockopt(sk, SOL_IP, optname, optval, optlen);
if (err != 0)
@@ -1654,6 +1678,9 @@ int mptcp_set_rcvlowat(struct sock *sk, int val)
if (space <= sk->sk_rcvbuf)
return 0;
+ if (has_current_bpf_ctx())
+ return -EOPNOTSUPP;
+
/* propagate the rcvbuf changes to all the subflows */
WRITE_ONCE(sk->sk_rcvbuf, space);
mptcp_for_each_subflow(mptcp_sk(sk), subflow) {
--
2.43.0
next prev parent reply other threads:[~2026-07-13 9:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-13 9:57 [PATCH mptcp-next 0/5] mptcp: add bpf_setsockopt support in Gang Yan
2026-07-13 9:57 ` [PATCH mptcp-next 1/5] mptcp: use sockopt_lock/release_sock in sockopt Gang Yan
2026-07-13 9:57 ` Gang Yan [this message]
2026-07-13 9:57 ` [PATCH mptcp-next 3/5] mptcp: enable bpf_setsockopt on the master socket Gang Yan
2026-07-13 9:57 ` [PATCH mptcp-next 4/5] mptcp: add TCP_CONNECT_CB sock_ops hook Gang Yan
2026-07-13 9:57 ` [PATCH mptcp-next 5/5] selftests: bpf: verify mptcp bpf_setsockopt from TCP_CONNECT_CB Gang Yan
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=20260713095735.1222033-3-gang.yan@linux.dev \
--to=gang.yan@linux.dev \
--cc=mptcp@lists.linux.dev \
--cc=pabeni@redhat.com \
--cc=yangang@kylinos.cn \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.