All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Matthieu Baerts (NGI0)" <matttbe@kernel.org>
To: mptcp@lists.linux.dev
Cc: Paolo Abeni <pabeni@redhat.com>,
	 "Matthieu Baerts (NGI0)" <matttbe@kernel.org>
Subject: [PATCH mptcp-next v2 3/3] mptcp: check the protocol in mptcp_sk() with DEBUG_NET
Date: Thu, 01 Feb 2024 17:09:31 +0100	[thread overview]
Message-ID: <20240201-mptcp-check-protocol-v2-3-1e253ef51990@kernel.org> (raw)
In-Reply-To: <20240201-mptcp-check-protocol-v2-0-1e253ef51990@kernel.org>

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.

Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
Notes:
  v2:
    - Use a macro instead of an inlined function (Paolo)
---
 net/mptcp/protocol.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index f2473d9acae6..defccef59b3e 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -355,9 +355,14 @@ 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) ({						\
+	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

-- 
2.43.0


  parent reply	other threads:[~2024-02-01 16:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-01 16:09 [PATCH mptcp-next v2 0/3] mptcp: check the protocol with DEBUG_NET Matthieu Baerts (NGI0)
2024-02-01 16:09 ` [PATCH mptcp-next v2 1/3] mptcp: token kunit: set protocol Matthieu Baerts (NGI0)
2024-02-01 16:09 ` [PATCH mptcp-next v2 2/3] mptcp: check the protocol in tcp_sk() with DEBUG_NET Matthieu Baerts (NGI0)
2024-02-01 16:09 ` Matthieu Baerts (NGI0) [this message]
2024-02-01 17:23   ` mptcp: check the protocol in mptcp_sk() with DEBUG_NET: Tests Results MPTCP CI
2024-02-01 17:27   ` MPTCP CI

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=20240201-mptcp-check-protocol-v2-3-1e253ef51990@kernel.org \
    --to=matttbe@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=pabeni@redhat.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 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.