From 9d6345e5ac9d7388b5b3c385044bf27f172d2589 Mon Sep 17 00:00:00 2001 From: Geliang Tang Date: Mon, 9 Dec 2024 14:12:29 +0800 Subject: [PATCH] Squash to "bpf: Add mptcp_subflow bpf_iter" Add "sizeof" and "alignof" checks. Address Martin's comments in v1: - bpf_iter_mptcp_subflow_new returns -EINVAL when msk socket lock isn't held. Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index f9ba0a46a9f15e..566c3a32ab7303 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -232,12 +232,20 @@ bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subflow *it, struct mptcp_sock *msk) { struct bpf_iter_mptcp_subflow_kern *kit = (void *)it; + struct sock *sk = (struct sock *)msk; + + BUILD_BUG_ON(sizeof(struct bpf_iter_mptcp_subflow_kern) != + sizeof(struct bpf_iter_mptcp_subflow)); + BUILD_BUG_ON(__alignof__(struct bpf_iter_mptcp_subflow_kern) != + __alignof__(struct bpf_iter_mptcp_subflow)); kit->msk = msk; if (!msk) return -EINVAL; - msk_owned_by_me(msk); + if (!sock_owned_by_user_nocheck(sk) && + !spin_is_locked(&sk->sk_lock.slock)) + return -EINVAL; kit->pos = &msk->conn_list; return 0;