Skip to content

Commit 7e56e83

Browse files
Geliang Tangintel-lab-lkp
authored andcommitted
Squash to "bpf: Add mptcp_subflow bpf_iter"
Drop the NULL check for 'msk' as Martin suggested, add more checks for 'sk'. Use the "struct sock *sk" instead of "struct mptcp-sock *msk" as the argument in the bpf_iter_mptcp_subflow_new as Martin suggested. v5: - check bpf_iter_task in mptcp_subflow_new() v4: - drop sock_owned_by_user_nocheck and spin_is_locked. According to comments from Mat [2] and Martin [1], in this set mptcp_subflow bpf_iter only used from a cg sockopt bpf prog, no need to add these check at this moment. [1] https://lore.kernel.org/all/[email protected]/ [2] https://patchwork.kernel.org/project/mptcp/patch/f6469225598beecbf0bda12a4c33fafa86c0ff15.1739787744.git.tanggeliang@kylinos.cn/ v3: - continue to use sock_owned_by_user_nocheck and spin_is_locked checks instead of using msk_owned_by_me(). v2: - check the owner before assigning the msk as Mat suggested. Signed-off-by: Geliang Tang <[email protected]>
1 parent c974dd2 commit 7e56e83

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

net/mptcp/bpf.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,24 +249,33 @@ bpf_mptcp_subflow_ctx(const struct sock *sk)
249249

250250
__bpf_kfunc static int
251251
bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subflow *it,
252-
struct mptcp_sock *msk)
252+
struct sock *sk)
253253
{
254254
struct bpf_iter_mptcp_subflow_kern *kit = (void *)it;
255-
struct sock *sk = (struct sock *)msk;
255+
struct task_struct *task;
256+
struct mptcp_sock *msk;
256257

257258
BUILD_BUG_ON(sizeof(struct bpf_iter_mptcp_subflow_kern) >
258259
sizeof(struct bpf_iter_mptcp_subflow));
259260
BUILD_BUG_ON(__alignof__(struct bpf_iter_mptcp_subflow_kern) !=
260261
__alignof__(struct bpf_iter_mptcp_subflow));
261262

262-
kit->msk = msk;
263-
if (!msk)
263+
if (unlikely(!sk || !sk_fullsock(sk)))
264264
return -EINVAL;
265265

266-
if (!sock_owned_by_user_nocheck(sk) &&
267-
!spin_is_locked(&sk->sk_lock.slock))
266+
if (sk->sk_protocol != IPPROTO_MPTCP)
268267
return -EINVAL;
269268

269+
msk = mptcp_sk(sk);
270+
task = mptcp_get_bpf_iter_task(msk);
271+
if (!task || task != current)
272+
return -EINVAL;
273+
274+
mptcp_clear_bpf_iter_task(msk);
275+
276+
msk_owned_by_me(msk);
277+
278+
kit->msk = msk;
270279
kit->pos = &msk->conn_list;
271280
return 0;
272281
}

0 commit comments

Comments
 (0)