All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH mptcp-next v3 0/3] mptcp: check the protocol with DEBUG_NET
@ 2024-02-07 11:56 Matthieu Baerts (NGI0)
  2024-02-07 11:56 ` [PATCH mptcp-next v3 1/3] mptcp: token kunit: set protocol Matthieu Baerts (NGI0)
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Matthieu Baerts (NGI0) @ 2024-02-07 11:56 UTC (permalink / raw)
  To: mptcp; +Cc: Paolo Abeni, Matthieu Baerts (NGI0)

Recently, Paolo fixed a bug where a TCP-specific helper was used with an
MPTCP socket [1]. The bug was not detected by fuzzer or static analysis.

Following this, it has been suggested to add a check, only in debug
mode. This is what this series is doing.

The series has been split to be upstreamed: a preparation patch for
MPTCP, the modification for TCP, then for MPTCP. It is not clear if it
would be OK to add that upstream. If not, we can squash these three
patches in "DO-NOT-MERGE: mptcp: improve code coverage for CI" commit we
have in our export tree.

Note that the MPTCP Token kUnit test needs to be adapted for this new
check. This is what is done in patch 1/3.

Link: https://lore.kernel.org/mptcp/35875ef9cb7194563b580e14c71cc8cb065f846c.1706043786.git.pabeni@redhat.com/ [1]
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
Changes in v3:
- Patch 2 and 3 have been modified, please the changelog on each patch
- Link to v2: https://lore.kernel.org/r/20240201-mptcp-check-protocol-v2-0-1e253ef51990@kernel.org

Changes in v2:
- Patch 2 and 3 have been modified, please the changelog on each patch
- Link to v1: https://lore.kernel.org/r/20240131-mptcp-check-protocol-v1-0-a06067f0bd08@kernel.org

---
Matthieu Baerts (NGI0) (3):
      mptcp: token kunit: set protocol
      mptcp: check the protocol in tcp_sk() with DEBUG_NET
      mptcp: check the protocol in mptcp_sk() with DEBUG_NET

 net/mptcp/protocol.h   | 14 ++++++++++++++
 net/mptcp/token_test.c |  7 ++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)
---
base-commit: c2469b38e369c3f2b9577beeb9470cc757abc1b9
change-id: 20240131-mptcp-check-protocol-e32e53d04a75

Best regards,
-- 
Matthieu Baerts (NGI0) <matttbe@kernel.org>


^ permalink raw reply	[flat|nested] 14+ messages in thread
* [PATCH mptcp-next v4 3/3] mptcp: check the protocol in mptcp_sk() with DEBUG_NET
@ 2024-02-15 11:40 Matthieu Baerts (NGI0)
  2024-02-15 12:34 ` mptcp: check the protocol in mptcp_sk() with DEBUG_NET: Tests Results MPTCP CI
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: Matthieu Baerts (NGI0) @ 2024-02-15 11:40 UTC (permalink / raw)
  To: mptcp; +Cc: Mat Martineau, Matthieu Baerts (NGI0)

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)
  - v3:
    - add parenthesis around 'ptr' (checkpatch)
    - there is still this check from checkpatch but I guess that's fine:
      Macro argument reuse 'ptr' - possible side-effects?
  - v4:
    - avoid reusing 'ptr' to fix checkpatch warning (Mat)
    - remove extra parenthesis in WARN_ON, no longer needed
---
 net/mptcp/protocol.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 32cf98bd2961..459859b107ba 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -356,9 +356,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

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread
* [PATCH mptcp-next v2 3/3] mptcp: check the protocol in mptcp_sk() with DEBUG_NET
@ 2024-02-01 16:09 Matthieu Baerts (NGI0)
  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
  0 siblings, 2 replies; 14+ messages in thread
From: Matthieu Baerts (NGI0) @ 2024-02-01 16:09 UTC (permalink / raw)
  To: mptcp; +Cc: Paolo Abeni, Matthieu Baerts (NGI0)

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


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2024-02-16  0:23 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-07 11:56 [PATCH mptcp-next v3 0/3] mptcp: check the protocol with DEBUG_NET Matthieu Baerts (NGI0)
2024-02-07 11:56 ` [PATCH mptcp-next v3 1/3] mptcp: token kunit: set protocol Matthieu Baerts (NGI0)
2024-02-07 11:56 ` [PATCH mptcp-next v3 2/3] mptcp: check the protocol in tcp_sk() with DEBUG_NET Matthieu Baerts (NGI0)
2024-02-14 19:03   ` Mat Martineau
2024-02-15 11:42     ` Matthieu Baerts
2024-02-07 11:56 ` [PATCH mptcp-next v3 3/3] mptcp: check the protocol in mptcp_sk() " Matthieu Baerts (NGI0)
2024-02-07 12:52   ` mptcp: check the protocol in mptcp_sk() with DEBUG_NET: Tests Results MPTCP CI
2024-02-07 13:10   ` MPTCP CI
  -- strict thread matches above, loose matches on Subject: below --
2024-02-15 11:40 [PATCH mptcp-next v4 3/3] mptcp: check the protocol in mptcp_sk() with DEBUG_NET Matthieu Baerts (NGI0)
2024-02-15 12:34 ` mptcp: check the protocol in mptcp_sk() with DEBUG_NET: Tests Results MPTCP CI
2024-02-15 12:50 ` MPTCP CI
2024-02-16  0:03 ` MPTCP CI
2024-02-16  0:23 ` MPTCP CI
2024-02-01 16:09 [PATCH mptcp-next v2 3/3] mptcp: check the protocol in mptcp_sk() with DEBUG_NET Matthieu Baerts (NGI0)
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

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.