Commit 733f531d authored by Matthieu Baerts (NGI0)'s avatar Matthieu Baerts (NGI0) Committed by Geliang Tang
Browse files

mptcp: check the protocol in mptcp_sk() with DEBUG_NET

mainline inclusion
from mainline-v6.9-rc1
commit 14d29ec5302caac945267b9586fad01ecddc700c
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I9VYQ9
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=14d29ec5302caac945267b9586fad01ecddc700c



--------------------------------

Fuzzers and static checkers might not detect when mptcp_sk() is used
with a non mptcp_sock structure.

This is similar to the parent commit, where it is easy to use mptcp_sk()
with a TCP sock, e.g. with a subflow sk.

So a new simple check is done when CONFIG_DEBUG_NET is enabled to tell
kernel devs when a non-MPTCP socket is being used as an MPTCP one.
'mptcp_sk()' macro is then defined differently: with an extra WARN to
complain when an unexpected socket is being used.

Reviewed-by: default avatarMat Martineau <martineau@kernel.org>
Signed-off-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://lore.kernel.org/r/20240223-upstream-net-next-20240223-misc-improvements-v1-4-b6c8a10396bd@kernel.org


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Reviewed-by: default avatarJackie Liu <liuyun01@kylinos.cn>
Signed-off-by: default avatarGeliang Tang <tanggeliang@kylinos.cn>
parent 11d6cf76
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -359,9 +359,15 @@ static inline void msk_owned_by_me(const struct mptcp_sock *msk)
	WARN_ON(_ptr->sk_protocol != IPPROTO_TCP);				\
	container_of_const(_ptr, struct tcp_sock, inet_conn.icsk_inet.sk);	\
})
#endif
#define mptcp_sk(ptr) ({						\
	typeof(ptr) _ptr = (ptr);					\
	WARN_ON(_ptr->sk_protocol != IPPROTO_MPTCP);			\
	container_of_const(_ptr, struct mptcp_sock, sk.icsk_inet.sk);	\
})

#else /* !CONFIG_DEBUG_NET */
#define mptcp_sk(ptr) container_of_const(ptr, struct mptcp_sock, sk.icsk_inet.sk)
#endif

/* the msk socket don't use the backlog, also account for the bulk
 * free memory