* [PATCH net-next v2 0/8] mptcp: various small and unrelated improvements
@ 2025-04-13 9:34 Matthieu Baerts (NGI0)
2025-04-13 9:34 ` [PATCH net-next v2 1/8] mptcp: sched: remove mptcp_sched_data Matthieu Baerts (NGI0)
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: Matthieu Baerts (NGI0) @ 2025-04-13 9:34 UTC (permalink / raw)
To: mptcp, Mat Martineau, Geliang Tang, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Shuah Khan
Cc: netdev, linux-kernel, linux-kselftest, Matthieu Baerts (NGI0),
Thorsten Blum, zhenwei pi, Geliang Tang
Here are various unrelated patches:
- Patch 1: sched: remove unused structure.
- Patch 2: sched: split the validation part, a preparation for later.
- Patch 3: pm: clarify code, not to think there is a possible UaF.
Note: a previous version has already been sent individually to Netdev.
- Patch 4: subflow: simplify subflow_hmac_valid by passing subflow_req.
- Patch 5: mib: add counter for MPJoin rejected by the PM.
- Patch 6: selftests: validate this new MPJoinRejected counter.
- Patch 7: selftests: define nlh variable only where needed.
- Patch 8: selftests: show how to use IPPROTO_MPTCP with getaddrinfo.
Note: a previous version has already been sent individually to Netdev.
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
Changes in v2:
- Force b4 to use 'git show' with '--no-mailmap' not to modify patches
2 and 7/8. The code has not been modified.
- Link to v1: https://lore.kernel.org/r/20250411-net-next-mptcp-sched-mib-sft-misc-v1-0-85ac8c6654c3@kernel.org
---
Geliang Tang (2):
mptcp: sched: split validation part
selftests: mptcp: diag: drop nlh parameter of recv_nlmsg
Matthieu Baerts (NGI0) (4):
mptcp: sched: remove mptcp_sched_data
mptcp: pass right struct to subflow_hmac_valid
mptcp: add MPJoinRejected MIB counter
selftests: mptcp: validate MPJoinRejected counter
Thorsten Blum (1):
mptcp: pm: Return local variable instead of freed pointer
zhenwei pi (1):
selftests: mptcp: use IPPROTO_MPTCP for getaddrinfo
include/net/mptcp.h | 13 ++-------
net/mptcp/mib.c | 1 +
net/mptcp/mib.h | 1 +
net/mptcp/pm.c | 5 +++-
net/mptcp/protocol.c | 4 ++-
net/mptcp/protocol.h | 1 +
net/mptcp/sched.c | 35 ++++++++++++++---------
net/mptcp/subflow.c | 12 ++++----
tools/testing/selftests/net/mptcp/mptcp_connect.c | 21 +++++++++++---
tools/testing/selftests/net/mptcp/mptcp_diag.c | 7 ++---
tools/testing/selftests/net/mptcp/mptcp_join.sh | 26 +++++++++++++----
11 files changed, 80 insertions(+), 46 deletions(-)
---
base-commit: 6a325aed130bb68790e765f923e76ec5669d2da7
change-id: 20250411-net-next-mptcp-sched-mib-sft-misc-25f5a6218fd8
Best regards,
--
Matthieu Baerts (NGI0) <matttbe@kernel.org>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH net-next v2 1/8] mptcp: sched: remove mptcp_sched_data
2025-04-13 9:34 [PATCH net-next v2 0/8] mptcp: various small and unrelated improvements Matthieu Baerts (NGI0)
@ 2025-04-13 9:34 ` Matthieu Baerts (NGI0)
2025-04-13 9:34 ` [PATCH net-next v2 2/8] mptcp: sched: split validation part Matthieu Baerts (NGI0)
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Matthieu Baerts (NGI0) @ 2025-04-13 9:34 UTC (permalink / raw)
To: mptcp, Mat Martineau, Geliang Tang, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Shuah Khan
Cc: netdev, linux-kernel, linux-kselftest, Matthieu Baerts (NGI0)
This is a follow-up of commit b68b106b0f15 ("mptcp: sched: reduce size
for unused data"), now removing the mptcp_sched_data structure.
Now is a good time to do that, because the previously mentioned WIP work
has been updated, no longer depending on this structure.
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
include/net/mptcp.h | 13 ++-----------
net/mptcp/sched.c | 18 +++++++-----------
2 files changed, 9 insertions(+), 22 deletions(-)
diff --git a/include/net/mptcp.h b/include/net/mptcp.h
index bfbad695951cf664af4d05390104883268b6bcd2..f7263fe2a2e40b507257c3720cc2d78d37357d6d 100644
--- a/include/net/mptcp.h
+++ b/include/net/mptcp.h
@@ -101,18 +101,9 @@ struct mptcp_out_options {
#define MPTCP_SCHED_MAX 128
#define MPTCP_SCHED_BUF_MAX (MPTCP_SCHED_NAME_MAX * MPTCP_SCHED_MAX)
-#define MPTCP_SUBFLOWS_MAX 8
-
-struct mptcp_sched_data {
- u8 subflows;
- struct mptcp_subflow_context *contexts[MPTCP_SUBFLOWS_MAX];
-};
-
struct mptcp_sched_ops {
- int (*get_send)(struct mptcp_sock *msk,
- struct mptcp_sched_data *data);
- int (*get_retrans)(struct mptcp_sock *msk,
- struct mptcp_sched_data *data);
+ int (*get_send)(struct mptcp_sock *msk);
+ int (*get_retrans)(struct mptcp_sock *msk);
char name[MPTCP_SCHED_NAME_MAX];
struct module *owner;
diff --git a/net/mptcp/sched.c b/net/mptcp/sched.c
index c16c6fbd4ba2f89a2fffcfd6b1916098d7a18cbe..f09f7eb1d63f86b9899c72b5c2fd36c8445898a8 100644
--- a/net/mptcp/sched.c
+++ b/net/mptcp/sched.c
@@ -16,8 +16,7 @@
static DEFINE_SPINLOCK(mptcp_sched_list_lock);
static LIST_HEAD(mptcp_sched_list);
-static int mptcp_sched_default_get_send(struct mptcp_sock *msk,
- struct mptcp_sched_data *data)
+static int mptcp_sched_default_get_send(struct mptcp_sock *msk)
{
struct sock *ssk;
@@ -29,8 +28,7 @@ static int mptcp_sched_default_get_send(struct mptcp_sock *msk,
return 0;
}
-static int mptcp_sched_default_get_retrans(struct mptcp_sock *msk,
- struct mptcp_sched_data *data)
+static int mptcp_sched_default_get_retrans(struct mptcp_sock *msk)
{
struct sock *ssk;
@@ -157,7 +155,6 @@ void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow,
int mptcp_sched_get_send(struct mptcp_sock *msk)
{
struct mptcp_subflow_context *subflow;
- struct mptcp_sched_data *data = NULL;
msk_owned_by_me(msk);
@@ -178,14 +175,13 @@ int mptcp_sched_get_send(struct mptcp_sock *msk)
}
if (msk->sched == &mptcp_sched_default || !msk->sched)
- return mptcp_sched_default_get_send(msk, data);
- return msk->sched->get_send(msk, data);
+ return mptcp_sched_default_get_send(msk);
+ return msk->sched->get_send(msk);
}
int mptcp_sched_get_retrans(struct mptcp_sock *msk)
{
struct mptcp_subflow_context *subflow;
- struct mptcp_sched_data *data = NULL;
msk_owned_by_me(msk);
@@ -199,8 +195,8 @@ int mptcp_sched_get_retrans(struct mptcp_sock *msk)
}
if (msk->sched == &mptcp_sched_default || !msk->sched)
- return mptcp_sched_default_get_retrans(msk, data);
+ return mptcp_sched_default_get_retrans(msk);
if (msk->sched->get_retrans)
- return msk->sched->get_retrans(msk, data);
- return msk->sched->get_send(msk, data);
+ return msk->sched->get_retrans(msk);
+ return msk->sched->get_send(msk);
}
--
2.48.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH net-next v2 2/8] mptcp: sched: split validation part
2025-04-13 9:34 [PATCH net-next v2 0/8] mptcp: various small and unrelated improvements Matthieu Baerts (NGI0)
2025-04-13 9:34 ` [PATCH net-next v2 1/8] mptcp: sched: remove mptcp_sched_data Matthieu Baerts (NGI0)
@ 2025-04-13 9:34 ` Matthieu Baerts (NGI0)
2025-04-13 9:34 ` [PATCH net-next v2 3/8] mptcp: pm: Return local variable instead of freed pointer Matthieu Baerts (NGI0)
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Matthieu Baerts (NGI0) @ 2025-04-13 9:34 UTC (permalink / raw)
To: mptcp, Mat Martineau, Geliang Tang, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Shuah Khan
Cc: netdev, linux-kernel, linux-kselftest, Matthieu Baerts (NGI0),
Geliang Tang
From: Geliang Tang <tanggeliang@kylinos.cn>
A new interface .validate has been added in struct bpf_struct_ops
recently. This patch prepares a future struct_ops support by
implementing it as a new helper mptcp_validate_scheduler() for struct
mptcp_sched_ops.
In this helper, check whether the required ops "get_subflow" of struct
mptcp_sched_ops has been implemented.
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Reviewed-by: Mat Martineau <martineau@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
Notes:
- v2: fix Author field (--no-mailmap).
---
net/mptcp/protocol.h | 1 +
net/mptcp/sched.c | 17 +++++++++++++++--
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index d409586b5977f93bff14fffd83b1d3020d57353b..7aa38d74fef6b5f00d97a114d74b711014d0a52d 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -744,6 +744,7 @@ void mptcp_info2sockaddr(const struct mptcp_addr_info *info,
struct sockaddr_storage *addr,
unsigned short family);
struct mptcp_sched_ops *mptcp_sched_find(const char *name);
+int mptcp_validate_scheduler(struct mptcp_sched_ops *sched);
int mptcp_register_scheduler(struct mptcp_sched_ops *sched);
void mptcp_unregister_scheduler(struct mptcp_sched_ops *sched);
void mptcp_sched_init(void);
diff --git a/net/mptcp/sched.c b/net/mptcp/sched.c
index f09f7eb1d63f86b9899c72b5c2fd36c8445898a8..1e59072d478c9b52c7f7b60431b589f6ca3abe65 100644
--- a/net/mptcp/sched.c
+++ b/net/mptcp/sched.c
@@ -82,10 +82,23 @@ void mptcp_get_available_schedulers(char *buf, size_t maxlen)
rcu_read_unlock();
}
+int mptcp_validate_scheduler(struct mptcp_sched_ops *sched)
+{
+ if (!sched->get_send) {
+ pr_err("%s does not implement required ops\n", sched->name);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
int mptcp_register_scheduler(struct mptcp_sched_ops *sched)
{
- if (!sched->get_send)
- return -EINVAL;
+ int ret;
+
+ ret = mptcp_validate_scheduler(sched);
+ if (ret)
+ return ret;
spin_lock(&mptcp_sched_list_lock);
if (mptcp_sched_find(sched->name)) {
--
2.48.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH net-next v2 3/8] mptcp: pm: Return local variable instead of freed pointer
2025-04-13 9:34 [PATCH net-next v2 0/8] mptcp: various small and unrelated improvements Matthieu Baerts (NGI0)
2025-04-13 9:34 ` [PATCH net-next v2 1/8] mptcp: sched: remove mptcp_sched_data Matthieu Baerts (NGI0)
2025-04-13 9:34 ` [PATCH net-next v2 2/8] mptcp: sched: split validation part Matthieu Baerts (NGI0)
@ 2025-04-13 9:34 ` Matthieu Baerts (NGI0)
2025-04-13 9:34 ` [PATCH net-next v2 4/8] mptcp: pass right struct to subflow_hmac_valid Matthieu Baerts (NGI0)
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Matthieu Baerts (NGI0) @ 2025-04-13 9:34 UTC (permalink / raw)
To: mptcp, Mat Martineau, Geliang Tang, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Shuah Khan
Cc: netdev, linux-kernel, linux-kselftest, Matthieu Baerts (NGI0),
Thorsten Blum
From: Thorsten Blum <thorsten.blum@linux.dev>
Commit e4c28e3d5c090 ("mptcp: pm: move generic PM helpers to pm.c")
removed an unnecessary if-check, which resulted in returning a freed
pointer.
This still works due to the implicit boolean conversion when returning
the freed pointer from mptcp_remove_anno_list_by_saddr(), but it can be
confusing and potentially error-prone. To improve clarity, add a local
variable to explicitly return a boolean value instead.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
Notes:
- a previous version has already been sent to Netdev. ChangeLog:
- Remove the if-check again as suggested by Matthieu Baerts
- Target net-next, not net (not a fix) and rephrase the commit message
- Link to this version:
https://lore.kernel.org/20250325110639.49399-2-thorsten.blum@linux.dev
---
net/mptcp/pm.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
index 31747f974941fae3f80bfc8313e82c41f92562eb..1306d4dc287b842ebf7efd52d121b096d5cb43e0 100644
--- a/net/mptcp/pm.c
+++ b/net/mptcp/pm.c
@@ -151,10 +151,13 @@ bool mptcp_remove_anno_list_by_saddr(struct mptcp_sock *msk,
const struct mptcp_addr_info *addr)
{
struct mptcp_pm_add_entry *entry;
+ bool ret;
entry = mptcp_pm_del_add_timer(msk, addr, false);
+ ret = entry;
kfree(entry);
- return entry;
+
+ return ret;
}
bool mptcp_pm_sport_in_anno_list(struct mptcp_sock *msk, const struct sock *sk)
--
2.48.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH net-next v2 4/8] mptcp: pass right struct to subflow_hmac_valid
2025-04-13 9:34 [PATCH net-next v2 0/8] mptcp: various small and unrelated improvements Matthieu Baerts (NGI0)
` (2 preceding siblings ...)
2025-04-13 9:34 ` [PATCH net-next v2 3/8] mptcp: pm: Return local variable instead of freed pointer Matthieu Baerts (NGI0)
@ 2025-04-13 9:34 ` Matthieu Baerts (NGI0)
2025-04-13 9:34 ` [PATCH net-next v2 5/8] mptcp: add MPJoinRejected MIB counter Matthieu Baerts (NGI0)
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Matthieu Baerts (NGI0) @ 2025-04-13 9:34 UTC (permalink / raw)
To: mptcp, Mat Martineau, Geliang Tang, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Shuah Khan
Cc: netdev, linux-kernel, linux-kselftest, Matthieu Baerts (NGI0)
subflow_hmac_valid() needs to access the MPTCP socket and the subflow
request, but not the request sock that is passed in argument.
Instead, the subflow request can be directly passed to avoid getting it
via an additional cast.
Reviewed-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
net/mptcp/subflow.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index 24c2de1891bdf31dfe04ef2077113563aad0e666..e7951786a97c91190c7341d2c586a1f4acc05ed5 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -745,15 +745,11 @@ struct request_sock *mptcp_subflow_reqsk_alloc(const struct request_sock_ops *op
EXPORT_SYMBOL(mptcp_subflow_reqsk_alloc);
/* validate hmac received in third ACK */
-static bool subflow_hmac_valid(const struct request_sock *req,
+static bool subflow_hmac_valid(const struct mptcp_subflow_request_sock *subflow_req,
const struct mptcp_options_received *mp_opt)
{
- const struct mptcp_subflow_request_sock *subflow_req;
+ struct mptcp_sock *msk = subflow_req->msk;
u8 hmac[SHA256_DIGEST_SIZE];
- struct mptcp_sock *msk;
-
- subflow_req = mptcp_subflow_rsk(req);
- msk = subflow_req->msk;
subflow_generate_hmac(READ_ONCE(msk->remote_key),
READ_ONCE(msk->local_key),
@@ -899,7 +895,7 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
goto dispose_child;
}
- if (!subflow_hmac_valid(req, &mp_opt)) {
+ if (!subflow_hmac_valid(subflow_req, &mp_opt)) {
SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_JOINACKMAC);
subflow_add_reset_reason(skb, MPTCP_RST_EPROHIBIT);
goto dispose_child;
--
2.48.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH net-next v2 5/8] mptcp: add MPJoinRejected MIB counter
2025-04-13 9:34 [PATCH net-next v2 0/8] mptcp: various small and unrelated improvements Matthieu Baerts (NGI0)
` (3 preceding siblings ...)
2025-04-13 9:34 ` [PATCH net-next v2 4/8] mptcp: pass right struct to subflow_hmac_valid Matthieu Baerts (NGI0)
@ 2025-04-13 9:34 ` Matthieu Baerts (NGI0)
2025-04-13 9:34 ` [PATCH net-next v2 6/8] selftests: mptcp: validate MPJoinRejected counter Matthieu Baerts (NGI0)
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Matthieu Baerts (NGI0) @ 2025-04-13 9:34 UTC (permalink / raw)
To: mptcp, Mat Martineau, Geliang Tang, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Shuah Khan
Cc: netdev, linux-kernel, linux-kselftest, Matthieu Baerts (NGI0)
This counter is useful to understand why some paths are rejected, and
not created as expected.
It is incremented when receiving a connection request, if the PM didn't
allow the creation of new subflows.
Reviewed-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
net/mptcp/mib.c | 1 +
net/mptcp/mib.h | 1 +
net/mptcp/protocol.c | 4 +++-
net/mptcp/subflow.c | 2 ++
4 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/net/mptcp/mib.c b/net/mptcp/mib.c
index 19eb9292bd6093a760b41f98c1774fd2490c48e3..0c24545f0e8df95b3475bfccc7a2f2ce440f7ad2 100644
--- a/net/mptcp/mib.c
+++ b/net/mptcp/mib.c
@@ -28,6 +28,7 @@ static const struct snmp_mib mptcp_snmp_list[] = {
SNMP_MIB_ITEM("MPJoinSynAckHMacFailure", MPTCP_MIB_JOINSYNACKMAC),
SNMP_MIB_ITEM("MPJoinAckRx", MPTCP_MIB_JOINACKRX),
SNMP_MIB_ITEM("MPJoinAckHMacFailure", MPTCP_MIB_JOINACKMAC),
+ SNMP_MIB_ITEM("MPJoinRejected", MPTCP_MIB_JOINREJECTED),
SNMP_MIB_ITEM("MPJoinSynTx", MPTCP_MIB_JOINSYNTX),
SNMP_MIB_ITEM("MPJoinSynTxCreatSkErr", MPTCP_MIB_JOINSYNTXCREATSKERR),
SNMP_MIB_ITEM("MPJoinSynTxBindErr", MPTCP_MIB_JOINSYNTXBINDERR),
diff --git a/net/mptcp/mib.h b/net/mptcp/mib.h
index 128282982843a07614a46f9b2c2f7c708306c769..250c6b77977e8f846b5741304f7841a922f51967 100644
--- a/net/mptcp/mib.h
+++ b/net/mptcp/mib.h
@@ -23,6 +23,7 @@ enum linux_mptcp_mib_field {
MPTCP_MIB_JOINSYNACKMAC, /* HMAC was wrong on SYN/ACK + MP_JOIN */
MPTCP_MIB_JOINACKRX, /* Received an ACK + MP_JOIN */
MPTCP_MIB_JOINACKMAC, /* HMAC was wrong on ACK + MP_JOIN */
+ MPTCP_MIB_JOINREJECTED, /* The PM rejected the JOIN request */
MPTCP_MIB_JOINSYNTX, /* Sending a SYN + MP_JOIN */
MPTCP_MIB_JOINSYNTXCREATSKERR, /* Not able to create a socket when sending a SYN + MP_JOIN */
MPTCP_MIB_JOINSYNTXBINDERR, /* Not able to bind() the address when sending a SYN + MP_JOIN */
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 44f7ab463d7550ad728651bad2b1aeb4cd4dea05..26ffa06c21e8d3429e2684f58523226d82a094ea 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -3527,8 +3527,10 @@ bool mptcp_finish_join(struct sock *ssk)
return true;
}
- if (!mptcp_pm_allow_new_subflow(msk))
+ if (!mptcp_pm_allow_new_subflow(msk)) {
+ MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_JOINREJECTED);
goto err_prohibited;
+ }
/* If we can't acquire msk socket lock here, let the release callback
* handle it
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index e7951786a97c91190c7341d2c586a1f4acc05ed5..15613d691bfef6800268ae75b62508736865f44a 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -247,6 +247,7 @@ static int subflow_check_req(struct request_sock *req,
if (unlikely(req->syncookie)) {
if (!mptcp_can_accept_new_subflow(subflow_req->msk)) {
+ SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_JOINREJECTED);
subflow_add_reset_reason(skb, MPTCP_RST_EPROHIBIT);
return -EPERM;
}
@@ -902,6 +903,7 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
}
if (!mptcp_can_accept_new_subflow(owner)) {
+ SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_JOINREJECTED);
subflow_add_reset_reason(skb, MPTCP_RST_EPROHIBIT);
goto dispose_child;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH net-next v2 6/8] selftests: mptcp: validate MPJoinRejected counter
2025-04-13 9:34 [PATCH net-next v2 0/8] mptcp: various small and unrelated improvements Matthieu Baerts (NGI0)
` (4 preceding siblings ...)
2025-04-13 9:34 ` [PATCH net-next v2 5/8] mptcp: add MPJoinRejected MIB counter Matthieu Baerts (NGI0)
@ 2025-04-13 9:34 ` Matthieu Baerts (NGI0)
2025-04-13 9:34 ` [PATCH net-next v2 7/8] selftests: mptcp: diag: drop nlh parameter of recv_nlmsg Matthieu Baerts (NGI0)
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Matthieu Baerts (NGI0) @ 2025-04-13 9:34 UTC (permalink / raw)
To: mptcp, Mat Martineau, Geliang Tang, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Shuah Khan
Cc: netdev, linux-kernel, linux-kselftest, Matthieu Baerts (NGI0)
The parent commit adds this new counter, incremented when receiving a
connection request, if the PM didn't allow the creation of new subflows.
Most of the time, it is then kept at 0, except when the PM limits cause
the receiver side to reject new MPJoin connections. This is the case in
the following tests:
- single subflow, limited by server
- multiple subflows, limited by server
- subflows limited by server w cookies
- userspace pm type rejects join
- userspace pm type prevents mp_prio
Simply set join_syn_rej=1 when checking the MPJoin counters for these
tests.
Reviewed-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
tools/testing/selftests/net/mptcp/mptcp_join.sh | 26 ++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testing/selftests/net/mptcp/mptcp_join.sh
index befa66f5a366bb738f8e6d6d84677f5c07488720..b8af65373b3ada96472347171924ad3a6cf14777 100755
--- a/tools/testing/selftests/net/mptcp/mptcp_join.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh
@@ -62,6 +62,7 @@ unset sflags
unset fastclose
unset fullmesh
unset speed
+unset join_syn_rej
unset join_csum_ns1
unset join_csum_ns2
unset join_fail_nr
@@ -1403,6 +1404,7 @@ chk_join_nr()
local syn_nr=$1
local syn_ack_nr=$2
local ack_nr=$3
+ local syn_rej=${join_syn_rej:-0}
local csum_ns1=${join_csum_ns1:-0}
local csum_ns2=${join_csum_ns2:-0}
local fail_nr=${join_fail_nr:-0}
@@ -1468,6 +1470,15 @@ chk_join_nr()
fail_test "got $count JOIN[s] ack HMAC failure expected 0"
fi
+ count=$(mptcp_lib_get_counter ${ns1} "MPTcpExtMPJoinRejected")
+ if [ -z "$count" ]; then
+ rc=${KSFT_SKIP}
+ elif [ "$count" != "$syn_rej" ]; then
+ rc=${KSFT_FAIL}
+ print_check "syn rejected"
+ fail_test "got $count JOIN[s] syn rejected expected $syn_rej"
+ fi
+
print_results "join Rx" ${rc}
join_syn_tx="${join_syn_tx:-${syn_nr}}" \
@@ -1963,7 +1974,8 @@ subflows_tests()
pm_nl_set_limits $ns2 0 1
pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
run_tests $ns1 $ns2 10.0.1.1
- chk_join_nr 1 1 0
+ join_syn_rej=1 \
+ chk_join_nr 1 1 0
fi
# subflow
@@ -1992,7 +2004,8 @@ subflows_tests()
pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow
run_tests $ns1 $ns2 10.0.1.1
- chk_join_nr 2 2 1
+ join_syn_rej=1 \
+ chk_join_nr 2 2 1
fi
# single subflow, dev
@@ -3061,7 +3074,8 @@ syncookies_tests()
pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
pm_nl_add_endpoint $ns2 10.0.2.2 flags subflow
run_tests $ns1 $ns2 10.0.1.1
- chk_join_nr 2 1 1
+ join_syn_rej=1 \
+ chk_join_nr 2 1 1
fi
# test signal address with cookies
@@ -3545,7 +3559,8 @@ userspace_tests()
pm_nl_set_limits $ns2 1 1
pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
run_tests $ns1 $ns2 10.0.1.1
- chk_join_nr 1 1 0
+ join_syn_rej=1 \
+ chk_join_nr 1 1 0
fi
# userspace pm type does not send join
@@ -3568,7 +3583,8 @@ userspace_tests()
pm_nl_add_endpoint $ns2 10.0.3.2 flags subflow
sflags=backup speed=slow \
run_tests $ns1 $ns2 10.0.1.1
- chk_join_nr 1 1 0
+ join_syn_rej=1 \
+ chk_join_nr 1 1 0
chk_prio_nr 0 0 0 0
fi
--
2.48.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH net-next v2 7/8] selftests: mptcp: diag: drop nlh parameter of recv_nlmsg
2025-04-13 9:34 [PATCH net-next v2 0/8] mptcp: various small and unrelated improvements Matthieu Baerts (NGI0)
` (5 preceding siblings ...)
2025-04-13 9:34 ` [PATCH net-next v2 6/8] selftests: mptcp: validate MPJoinRejected counter Matthieu Baerts (NGI0)
@ 2025-04-13 9:34 ` Matthieu Baerts (NGI0)
2025-04-13 9:34 ` [PATCH net-next v2 8/8] selftests: mptcp: use IPPROTO_MPTCP for getaddrinfo Matthieu Baerts (NGI0)
2025-04-15 15:30 ` [PATCH net-next v2 0/8] mptcp: various small and unrelated improvements patchwork-bot+netdevbpf
8 siblings, 0 replies; 10+ messages in thread
From: Matthieu Baerts (NGI0) @ 2025-04-13 9:34 UTC (permalink / raw)
To: mptcp, Mat Martineau, Geliang Tang, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Shuah Khan
Cc: netdev, linux-kernel, linux-kselftest, Matthieu Baerts (NGI0),
Geliang Tang
From: Geliang Tang <tanggeliang@kylinos.cn>
It's strange that 'nlh' variable is set to NULL in get_mptcpinfo() and then
this NULL pointer is passed to recv_nlmsg(). In fact, this variable should
be defined in recv_nlmsg(), not get_mptcpinfo().
So this patch drops this useless 'nlh' parameter of recv_nlmsg() and define
'nlh' variable in recv_nlmsg().
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
Notes:
- v2: fix Author field (--no-mailmap).
---
tools/testing/selftests/net/mptcp/mptcp_diag.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/net/mptcp/mptcp_diag.c b/tools/testing/selftests/net/mptcp/mptcp_diag.c
index 284286c524cfeff5f49b0af1a4da5a376c9e3140..37d5015ad08c44485f1964593ecb1a7b25d95934 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_diag.c
+++ b/tools/testing/selftests/net/mptcp/mptcp_diag.c
@@ -185,9 +185,10 @@ static void parse_nlmsg(struct nlmsghdr *nlh)
}
}
-static void recv_nlmsg(int fd, struct nlmsghdr *nlh)
+static void recv_nlmsg(int fd)
{
char rcv_buff[8192];
+ struct nlmsghdr *nlh = (struct nlmsghdr *)rcv_buff;
struct sockaddr_nl rcv_nladdr = {
.nl_family = AF_NETLINK
};
@@ -204,7 +205,6 @@ static void recv_nlmsg(int fd, struct nlmsghdr *nlh)
int len;
len = recvmsg(fd, &rcv_msg, 0);
- nlh = (struct nlmsghdr *)rcv_buff;
while (NLMSG_OK(nlh, len)) {
if (nlh->nlmsg_type == NLMSG_DONE) {
@@ -225,7 +225,6 @@ static void recv_nlmsg(int fd, struct nlmsghdr *nlh)
static void get_mptcpinfo(__u32 token)
{
- struct nlmsghdr *nlh = NULL;
int fd;
fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_SOCK_DIAG);
@@ -233,7 +232,7 @@ static void get_mptcpinfo(__u32 token)
die_perror("Netlink socket");
send_query(fd, token);
- recv_nlmsg(fd, nlh);
+ recv_nlmsg(fd);
close(fd);
}
--
2.48.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH net-next v2 8/8] selftests: mptcp: use IPPROTO_MPTCP for getaddrinfo
2025-04-13 9:34 [PATCH net-next v2 0/8] mptcp: various small and unrelated improvements Matthieu Baerts (NGI0)
` (6 preceding siblings ...)
2025-04-13 9:34 ` [PATCH net-next v2 7/8] selftests: mptcp: diag: drop nlh parameter of recv_nlmsg Matthieu Baerts (NGI0)
@ 2025-04-13 9:34 ` Matthieu Baerts (NGI0)
2025-04-15 15:30 ` [PATCH net-next v2 0/8] mptcp: various small and unrelated improvements patchwork-bot+netdevbpf
8 siblings, 0 replies; 10+ messages in thread
From: Matthieu Baerts (NGI0) @ 2025-04-13 9:34 UTC (permalink / raw)
To: mptcp, Mat Martineau, Geliang Tang, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Shuah Khan
Cc: netdev, linux-kernel, linux-kselftest, Matthieu Baerts (NGI0),
zhenwei pi
From: zhenwei pi <pizhenwei@bytedance.com>
mptcp_connect.c is a startup tutorial of MPTCP programming, however
there is a lack of ai_protocol(IPPROTO_MPTCP) usage. Add comment for
getaddrinfo MPTCP support.
This patch first uses IPPROTO_MPTCP to get addrinfo, and if glibc
version is too old, it falls back to using IPPROTO_TCP.
Co-developed-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
Notes:
- a previous version has already been sent to Netdev. ChangeLog:
- show how to use IPPROTO_MPTCP with getaddrinfo, not only a comment.
- Link to this version:
https://lore.kernel.org/20250407085122.1203489-1-pizhenwei@bytedance.com
---
tools/testing/selftests/net/mptcp/mptcp_connect.c | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/testing/selftests/net/mptcp/mptcp_connect.c
index c83a8b47bbdfa5fcf1462e2b2949b41fd32c9b14..ac1349c4b9e5404c95935eb38b08a15d774eb1d9 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_connect.c
+++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c
@@ -180,13 +180,26 @@ static void xgetnameinfo(const struct sockaddr *addr, socklen_t addrlen,
}
static void xgetaddrinfo(const char *node, const char *service,
- const struct addrinfo *hints,
+ struct addrinfo *hints,
struct addrinfo **res)
{
+again:
int err = getaddrinfo(node, service, hints, res);
if (err) {
- const char *errstr = getxinfo_strerr(err);
+ const char *errstr;
+
+ /* glibc starts to support MPTCP since v2.42.
+ * For older versions, use IPPROTO_TCP to resolve,
+ * and use TCP/MPTCP to create socket.
+ * Link: https://sourceware.org/git/?p=glibc.git;a=commit;h=a8e9022e0f82
+ */
+ if (err == EAI_SOCKTYPE) {
+ hints->ai_protocol = IPPROTO_TCP;
+ goto again;
+ }
+
+ errstr = getxinfo_strerr(err);
fprintf(stderr, "Fatal: getaddrinfo(%s:%s): %s\n",
node ? node : "", service ? service : "", errstr);
@@ -292,7 +305,7 @@ static int sock_listen_mptcp(const char * const listenaddr,
{
int sock = -1;
struct addrinfo hints = {
- .ai_protocol = IPPROTO_TCP,
+ .ai_protocol = IPPROTO_MPTCP,
.ai_socktype = SOCK_STREAM,
.ai_flags = AI_PASSIVE | AI_NUMERICHOST
};
@@ -356,7 +369,7 @@ static int sock_connect_mptcp(const char * const remoteaddr,
int infd, struct wstate *winfo)
{
struct addrinfo hints = {
- .ai_protocol = IPPROTO_TCP,
+ .ai_protocol = IPPROTO_MPTCP,
.ai_socktype = SOCK_STREAM,
};
struct addrinfo *a, *addr;
--
2.48.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH net-next v2 0/8] mptcp: various small and unrelated improvements
2025-04-13 9:34 [PATCH net-next v2 0/8] mptcp: various small and unrelated improvements Matthieu Baerts (NGI0)
` (7 preceding siblings ...)
2025-04-13 9:34 ` [PATCH net-next v2 8/8] selftests: mptcp: use IPPROTO_MPTCP for getaddrinfo Matthieu Baerts (NGI0)
@ 2025-04-15 15:30 ` patchwork-bot+netdevbpf
8 siblings, 0 replies; 10+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-04-15 15:30 UTC (permalink / raw)
To: Matthieu Baerts
Cc: mptcp, martineau, geliang, davem, edumazet, kuba, pabeni, horms,
shuah, netdev, linux-kernel, linux-kselftest, thorsten.blum,
pizhenwei
Hello:
This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Sun, 13 Apr 2025 11:34:31 +0200 you wrote:
> Here are various unrelated patches:
>
> - Patch 1: sched: remove unused structure.
>
> - Patch 2: sched: split the validation part, a preparation for later.
>
> - Patch 3: pm: clarify code, not to think there is a possible UaF.
> Note: a previous version has already been sent individually to Netdev.
>
> [...]
Here is the summary with links:
- [net-next,v2,1/8] mptcp: sched: remove mptcp_sched_data
https://git.kernel.org/netdev/net-next/c/6e83166dd800
- [net-next,v2,2/8] mptcp: sched: split validation part
https://git.kernel.org/netdev/net-next/c/760ff076695c
- [net-next,v2,3/8] mptcp: pm: Return local variable instead of freed pointer
https://git.kernel.org/netdev/net-next/c/def9d0958bef
- [net-next,v2,4/8] mptcp: pass right struct to subflow_hmac_valid
https://git.kernel.org/netdev/net-next/c/60cbf3158513
- [net-next,v2,5/8] mptcp: add MPJoinRejected MIB counter
https://git.kernel.org/netdev/net-next/c/4ce7fb8de556
- [net-next,v2,6/8] selftests: mptcp: validate MPJoinRejected counter
https://git.kernel.org/netdev/net-next/c/98dea4fd6315
- [net-next,v2,7/8] selftests: mptcp: diag: drop nlh parameter of recv_nlmsg
https://git.kernel.org/netdev/net-next/c/f9c7504d3055
- [net-next,v2,8/8] selftests: mptcp: use IPPROTO_MPTCP for getaddrinfo
https://git.kernel.org/netdev/net-next/c/a862771d1aa4
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2025-04-15 15:29 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-13 9:34 [PATCH net-next v2 0/8] mptcp: various small and unrelated improvements Matthieu Baerts (NGI0)
2025-04-13 9:34 ` [PATCH net-next v2 1/8] mptcp: sched: remove mptcp_sched_data Matthieu Baerts (NGI0)
2025-04-13 9:34 ` [PATCH net-next v2 2/8] mptcp: sched: split validation part Matthieu Baerts (NGI0)
2025-04-13 9:34 ` [PATCH net-next v2 3/8] mptcp: pm: Return local variable instead of freed pointer Matthieu Baerts (NGI0)
2025-04-13 9:34 ` [PATCH net-next v2 4/8] mptcp: pass right struct to subflow_hmac_valid Matthieu Baerts (NGI0)
2025-04-13 9:34 ` [PATCH net-next v2 5/8] mptcp: add MPJoinRejected MIB counter Matthieu Baerts (NGI0)
2025-04-13 9:34 ` [PATCH net-next v2 6/8] selftests: mptcp: validate MPJoinRejected counter Matthieu Baerts (NGI0)
2025-04-13 9:34 ` [PATCH net-next v2 7/8] selftests: mptcp: diag: drop nlh parameter of recv_nlmsg Matthieu Baerts (NGI0)
2025-04-13 9:34 ` [PATCH net-next v2 8/8] selftests: mptcp: use IPPROTO_MPTCP for getaddrinfo Matthieu Baerts (NGI0)
2025-04-15 15:30 ` [PATCH net-next v2 0/8] mptcp: various small and unrelated improvements patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).