Skip to contentSkip to conversation

mptcp: TCP_MD5SIG support

PATCH Superseded Geliang Tang 4 participants 10 messages Aug 2, 2025 – Aug 6, 2025

Subsystems (2)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Geliang Tang

author reviewer
#0 lore raw

v4 cover mptcp: TCP_MD5SIG support

From: Geliang Tang <[email protected]>

v4:
- drop CONFIG_TCP_MD5SIG check.
- drop sk_state check.
- use WARN_ON_ONCE for __mptcp_try_fallback().

v3:
- limit the use of these options for listened and closed state.
- check the return value of __mptcp_try_fallback().

v2:
- trigger fallback to TCP.
- check CONFIG_TCP_MD5SIG.
- update MD5 comment.
- drop selftests, packetdrill tests will be added later.

This series introduces support for TCP_MD5SIG socket options in MPTCP along with code improvements:

Patch 1: Refactors TCP_MAXSEG getsockopt handling to improve code consistency
Patch 2: Adds setsockopt support for TCP_MD5SIG/TCP_MD5SIG_EXT (first subflow only)

Geliang Tang (2):
mptcp: Handle TCP_MAXSEG getsockopt in common case
mptcp: setsockopt support for TCP_MD5SIG

 net/mptcp/sockopt.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
Signature · 1 line
2.48.1
author reviewer
#1 lore raw

PATCH v4 1/2 mptcp: Handle TCP_MAXSEG getsockopt in common case

From: Geliang Tang <[email protected]>

This patch simplifies MPTCP's TCP_MAXSEG getsockopt handling by moving it to the common case where other TCP options are processed. Previously it was handled separately after the main switch statement.

The change:

- Moves TCP_MAXSEG case into the main switch block
- Removes redundant separate handling
- Maintains identical functionality

This improves code consistency without altering behavior.

---
 net/mptcp/sockopt.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
net/mptcp/sockopt.c +1 -3
index 2c267aff95be..b264185b810d 100644
@@ -1404,6 +1404,7 @@ static int mptcp_getsockopt_sol_tcp(struct mptcp_sock *msk, int optname,
 	case TCP_FASTOPEN_CONNECT:
 	case TCP_FASTOPEN_KEY:
 	case TCP_FASTOPEN_NO_COOKIE:
+	case TCP_MAXSEG:
 		return mptcp_getsockopt_first_sf_only(msk, SOL_TCP, optname,
 						      optval, optlen);
 	case TCP_INQ:
@@ -1428,9 +1429,6 @@ static int mptcp_getsockopt_sol_tcp(struct mptcp_sock *msk, int optname,
 		return mptcp_put_int_option(msk, optval, optlen, msk->notsent_lowat);
 	case TCP_IS_MPTCP:
 		return mptcp_put_int_option(msk, optval, optlen, 1);
-	case TCP_MAXSEG:
-		return mptcp_getsockopt_first_sf_only(msk, SOL_TCP, optname,
-						      optval, optlen);
 	}
 	return -EOPNOTSUPP;
 }
Signature · 1 line
2.48.1
author reviewer
#2 lore raw

PATCH v4 2/2 mptcp: setsockopt support for TCP_MD5SIG

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Supporting TCP_MD5 socket option is required when MPTCP is used by default when creating a socket, to keep the same behaviour as with TCP. TCP_MD5 is not compatible with MPTCP, and it will cause a fallback to TCP at the connection request, if MPTCP was requested. This then fixes a "regression" compared to TCP.

This patch adds setsockopt support for TCP_MD5SIG and TCP_MD5SIG_EXT options. The implementation:
- Allow setting these options (getsockopt remains unsupported)
- Apply them only to the first subflow
- Trigger fallback to TCP to maintain MD5 compatibility

Note that getsockopt for these options remains unsupported, consistent with TCP.

Fixes d9e4c1291810 ("mptcp: only admit explicitly supported sockopt")
---
 net/mptcp/sockopt.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
net/mptcp/sockopt.c +12 -2
index b264185b810d..f2f0b475c8d6 100644
@@ -13,6 +13,7 @@
 #include <net/tcp.h>
 #include <net/mptcp.h>
 #include "protocol.h"
+#include "mib.h"
 
 #define MIN_INFO_OPTLEN_SIZE		16
 #define MIN_FULL_INFO_OPTLEN_SIZE	40
@@ -567,11 +568,12 @@ static bool mptcp_supported_sockopt(int level, int optname)
 		case TCP_FASTOPEN_CONNECT:
 		case TCP_FASTOPEN_KEY:
 		case TCP_FASTOPEN_NO_COOKIE:
+		/* MD5 will force a fallback to TCP: OK to set while not connected */
+		case TCP_MD5SIG:
+		case TCP_MD5SIG_EXT:
 			return true;
 		}
 
-		/* TCP_MD5SIG, TCP_MD5SIG_EXT are not supported, MD5 is not compatible with MPTCP */
-
 		/* TCP_REPAIR, TCP_REPAIR_QUEUE, TCP_QUEUE_SEQ, TCP_REPAIR_OPTIONS,
 		 * TCP_REPAIR_WINDOW are not supported, better avoid this mess
 		 */
@@ -836,6 +838,14 @@ static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname,
 	case TCP_FASTOPEN_NO_COOKIE:
 		return mptcp_setsockopt_first_sf_only(msk, SOL_TCP, optname,
 						      optval, optlen);
+	case TCP_MD5SIG:
+	case TCP_MD5SIG_EXT:
+		ret = mptcp_setsockopt_first_sf_only(msk, SOL_TCP, optname,
+						     optval, optlen);
+		if (ret == 0)
+			WARN_ON_ONCE(!__mptcp_try_fallback(msk,
+							   MPTCP_MIB_MD5SIGFALLBACK));
+		return ret;
 	}
 
 	ret = mptcp_get_int_option(msk, optval, optlen, &val);
Signature · 1 line
2.48.1
#3 lore raw
In reply to Geliang Tang

Hi Geliang,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal: Success! ✅
- KVM Validation: debug: Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/16695728843

Initiator: Matthieu Baerts (NGI0)
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/79f05b8aa681
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=987879

If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-normal

For more details:

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker

Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)

#4 lore raw
In reply to Geliang Tang
Quoted 26 lines · Geliang Tang

From: Geliang Tang <[email protected]>

v4:
- drop CONFIG_TCP_MD5SIG check.
- drop sk_state check.
- use WARN_ON_ONCE for __mptcp_try_fallback().

v3:
- limit the use of these options for listened and closed state.
- check the return value of __mptcp_try_fallback().

v2:
- trigger fallback to TCP.
- check CONFIG_TCP_MD5SIG.
- update MD5 comment.
- drop selftests, packetdrill tests will be added later.

This series introduces support for TCP_MD5SIG socket options in MPTCP along with code improvements:

Patch 1: Refactors TCP_MAXSEG getsockopt handling to improve code consistency
Patch 2: Adds setsockopt support for TCP_MD5SIG/TCP_MD5SIG_EXT (first subflow only)

Quoted 8 lines

Geliang Tang (2):
mptcp: Handle TCP_MAXSEG getsockopt in common case
mptcp: setsockopt support for TCP_MD5SIG

 net/mptcp/sockopt.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

When I run these 2 patches, I get a reset from the server :

23:24:48.285068 enP22p3s0f0np0 Out IP 10.221.81.117.35206 > 10.221.81.118.1234: Flags [S], seq 314447609, win 64240, options [nop,nop,md5 shared secret not supplied with -M, can't check - bab9b1ba60e4d55efb3d475ee4222311,mss 1460,nop,nop,sackOK,nop,wscale 0], length 0
23:24:48.285172 enP22p3s0f0np0 In IP 10.221.81.118.1234 > 10.221.81.117.35206: Flags [R.], seq 0, ack 314447610, win 0, options [nop,nop,md5 shared secret not supplied with -M, can't check - c3bb41109aead9863e97f9cc4e12e7d2], length 0

My test program simply creates a socket (IPPROTO_MPTCP), sets TCP_MD5SIG and connects.

When I use IPPROTO_TCP, everything works.

I haven't even tried removing wscale,... to make space in the TCP-options to try combining both TCP_MD5 and MPTCP.

Christoph

author reviewer
#5 lore raw

Hi Christoph,

Quoted 41 lines · Christoph Paasch
Quoted 28 lines · Geliang Tang

From: Geliang Tang <[email protected]>

v4:
 - drop CONFIG_TCP_MD5SIG check.
 - drop sk_state check.
 - use WARN_ON_ONCE for __mptcp_try_fallback().

v3:
 - limit the use of these options for listened and closed state.
 - check the return value of __mptcp_try_fallback().

v2:
 - trigger fallback to TCP.
 - check CONFIG_TCP_MD5SIG.
 - update MD5 comment.
 - drop selftests, packetdrill tests will be added later.

This series introduces support for TCP_MD5SIG socket options in MPTCP along
with code improvements:

Patch 1: Refactors TCP_MAXSEG getsockopt handling to improve code consistency
Patch 2: Adds setsockopt support for TCP_MD5SIG/TCP_MD5SIG_EXT (first
subflow only)

Quoted 8 lines

Geliang Tang (2):
  mptcp: Handle TCP_MAXSEG getsockopt in common case
  mptcp: setsockopt support for TCP_MD5SIG

 net/mptcp/sockopt.c | 18 +++++++++++++-----

 1 file changed, 13 insertions(+), 5 deletions(-)

When I run these 2 patches, I get a reset from the server :

Quoted 10 lines

23:24:48.285068 enP22p3s0f0np0 Out IP 10.221.81.117.35206 > 10.221.81.118.1234: Flags [S], seq 314447609, win 64240, options [nop,nop,md5 shared secret not supplied with -M, can't check - bab9b1ba60e4d55efb3d475ee4222311,mss 1460,nop,nop,sackOK,nop,wscale 0], length 0
23:24:48.285172 enP22p3s0f0np0 In  IP 10.221.81.118.1234 > 10.221.81.117.35206: Flags [R.], seq 0, ack 314447610, win 0, options [nop,nop,md5 shared secret not supplied with -M, can't check - c3bb41109aead9863e97f9cc4e12e7d2], length 0

Yes, indeed, I got this reset too. This patch can fix it:

net/mptcp/subflow.c +0 -0
index 69e773059844..b22daf8c4526 100644
@@ -165,7 +165,8 @@ static int subflow_check_req(struct request_sock

*req,
/* no MPTCP if MD5SIG is enabled on this socket or we may run
out of
* TCP option space.
*/
- if (rcu_access_pointer(tcp_sk(sk_listener)->md5sig_info)) {
+ if (rcu_access_pointer(tcp_sk(sk_listener)->md5sig_info) ||
+ !__mptcp_check_fallback(mptcp_sk(listener->conn))) {
subflow_add_reset_reason(skb, MPTCP_RST_EMPTCP); return -EINVAL;
}

WDYT?

Thanks,
-Geliang

Quoted 10 lines

My test program simply creates a socket (IPPROTO_MPTCP), sets TCP_MD5SIG and connects.

When I use IPPROTO_TCP, everything works.

I haven't even tried removing wscale,... to make space in the TCP-options to try combining both TCP_MD5 and MPTCP.

Christoph

author reviewer
#6 lore raw
In reply to Christoph Paasch

Hi Christoph,

Quoted 41 lines · Christoph Paasch
Quoted 28 lines · Geliang Tang

From: Geliang Tang <[email protected]>

v4:
 - drop CONFIG_TCP_MD5SIG check.
 - drop sk_state check.
 - use WARN_ON_ONCE for __mptcp_try_fallback().

v3:
 - limit the use of these options for listened and closed state.
 - check the return value of __mptcp_try_fallback().

v2:
 - trigger fallback to TCP.
 - check CONFIG_TCP_MD5SIG.
 - update MD5 comment.
 - drop selftests, packetdrill tests will be added later.

This series introduces support for TCP_MD5SIG socket options in MPTCP along
with code improvements:

Patch 1: Refactors TCP_MAXSEG getsockopt handling to improve code consistency
Patch 2: Adds setsockopt support for TCP_MD5SIG/TCP_MD5SIG_EXT (first
subflow only)

Quoted 8 lines

Geliang Tang (2):
  mptcp: Handle TCP_MAXSEG getsockopt in common case
  mptcp: setsockopt support for TCP_MD5SIG

 net/mptcp/sockopt.c | 18 +++++++++++++-----

 1 file changed, 13 insertions(+), 5 deletions(-)

When I run these 2 patches, I get a reset from the server :

Quoted 10 lines

23:24:48.285068 enP22p3s0f0np0 Out IP 10.221.81.117.35206 > 10.221.81.118.1234: Flags [S], seq 314447609, win 64240, options [nop,nop,md5 shared secret not supplied with -M, can't check - bab9b1ba60e4d55efb3d475ee4222311,mss 1460,nop,nop,sackOK,nop,wscale 0], length 0
23:24:48.285172 enP22p3s0f0np0 In  IP 10.221.81.118.1234 > 10.221.81.117.35206: Flags [R.], seq 0, ack 314447610, win 0, options [nop,nop,md5 shared secret not supplied with -M, can't check - c3bb41109aead9863e97f9cc4e12e7d2], length 0

Yes, indeed, I got this reset too. This patch can fix it:

net/mptcp/subflow.c +0 -0
index 69e773059844..b22daf8c4526 100644
@@ -165,7 +165,8 @@ static int subflow_check_req(struct request_sock

*req,
/* no MPTCP if MD5SIG is enabled on this socket or we may run
out of
* TCP option space.
*/
- if (rcu_access_pointer(tcp_sk(sk_listener)->md5sig_info)) {
+ if (rcu_access_pointer(tcp_sk(sk_listener)->md5sig_info) &&
+ !__mptcp_check_fallback(mptcp_sk(listener->conn))) {
subflow_add_reset_reason(skb, MPTCP_RST_EMPTCP); return -EINVAL;
}

WDYT?

Thanks,
-Geliang

Quoted 10 lines

My test program simply creates a socket (IPPROTO_MPTCP), sets TCP_MD5SIG and connects.

When I use IPPROTO_TCP, everything works.

I haven't even tried removing wscale,... to make space in the TCP-options to try combining both TCP_MD5 and MPTCP.

Christoph

maintainer
#7 lore raw

Hi Geliang,

Quoted 65 lines · Geliang Tang

Hi Christoph,

Quoted 41 lines · Christoph Paasch
Quoted 28 lines · Geliang Tang

From: Geliang Tang <[email protected]>

v4:
 - drop CONFIG_TCP_MD5SIG check.
 - drop sk_state check.
 - use WARN_ON_ONCE for __mptcp_try_fallback().

v3:
 - limit the use of these options for listened and closed state.
 - check the return value of __mptcp_try_fallback().

v2:
 - trigger fallback to TCP.
 - check CONFIG_TCP_MD5SIG.
 - update MD5 comment.
 - drop selftests, packetdrill tests will be added later.

This series introduces support for TCP_MD5SIG socket options in MPTCP along
with code improvements:

Patch 1: Refactors TCP_MAXSEG getsockopt handling to improve code consistency
Patch 2: Adds setsockopt support for TCP_MD5SIG/TCP_MD5SIG_EXT (first
subflow only)

Quoted 8 lines

Geliang Tang (2):
  mptcp: Handle TCP_MAXSEG getsockopt in common case
  mptcp: setsockopt support for TCP_MD5SIG

 net/mptcp/sockopt.c | 18 +++++++++++++-----

 1 file changed, 13 insertions(+), 5 deletions(-)

When I run these 2 patches, I get a reset from the server :

Quoted 10 lines

23:24:48.285068 enP22p3s0f0np0 Out IP 10.221.81.117.35206 > 10.221.81.118.1234: Flags [S], seq 314447609, win 64240, options [nop,nop,md5 shared secret not supplied with -M, can't check - bab9b1ba60e4d55efb3d475ee4222311,mss 1460,nop,nop,sackOK,nop,wscale 0], length 0
23:24:48.285172 enP22p3s0f0np0 In  IP 10.221.81.118.1234 > 10.221.81.117.35206: Flags [R.], seq 0, ack 314447610, win 0, options [nop,nop,md5 shared secret not supplied with -M, can't check - c3bb41109aead9863e97f9cc4e12e7d2], length 0

Yes, indeed, I got this reset too. This patch can fix it:

net/mptcp/subflow.c +0 -0
index 69e773059844..b22daf8c4526 100644
@@ -165,7 +165,8 @@ static int subflow_check_req(struct request_sock
 *req,
 	/* no MPTCP if MD5SIG is enabled on this socket or we may run

out of

net/mptcp/subflow.c

Quoted 5 lines
net/mptcp/subflow.c +2 -1
 	 * TCP option space.
 	 */
-	if (rcu_access_pointer(tcp_sk(sk_listener)->md5sig_info)) {
+	if (rcu_access_pointer(tcp_sk(sk_listener)->md5sig_info) &&
+	    !__mptcp_check_fallback(mptcp_sk(listener->conn))) {

If __mptcp_check_fallback() is true, does it mean we will accept SYN+MPC+MD5?

Should we not have something like that?

if (__mptcp_check_fallback())

      return 0;

Please provide packetdrill tests: for the client and server side. For the server side, with and without MPTCP in the injected SYN.

(+ adapt the one causing issues)

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author reviewer
#8 lore raw

Hi Matt,

Quoted 86 lines · Matthieu Baerts

Hi Geliang,

Quoted 78 lines · Geliang Tang

Hi Christoph,

Quoted 44 lines · Christoph Paasch
Quoted 33 lines · Geliang Tang

From: Geliang Tang <[email protected]>

v4:
 - drop CONFIG_TCP_MD5SIG check.
 - drop sk_state check.
 - use WARN_ON_ONCE for __mptcp_try_fallback().

v3:
 - limit the use of these options for listened and closed state.
 - check the return value of __mptcp_try_fallback().

v2:
 - trigger fallback to TCP.
 - check CONFIG_TCP_MD5SIG.
 - update MD5 comment.
 - drop selftests, packetdrill tests will be added later.

This series introduces support for TCP_MD5SIG socket options in MPTCP along
with code improvements:

Patch 1: Refactors TCP_MAXSEG getsockopt handling to improve code
consistency
Patch 2: Adds setsockopt support for TCP_MD5SIG/TCP_MD5SIG_EXT (first
subflow only)

Closes:
https://github.com/multipath-tcp/mptcp_net-next/issues/575

Quoted 6 lines

Geliang Tang (2):
  mptcp: Handle TCP_MAXSEG getsockopt in common case
  mptcp: setsockopt support for TCP_MD5SIG

 net/mptcp/sockopt.c | 18 +++++++++++++-----

 1 file changed, 13 insertions(+), 5 deletions(-)

When I run these 2 patches, I get a reset from the server :

Quoted 12 lines

23:24:48.285068 enP22p3s0f0np0 Out IP 10.221.81.117.35206 > 10.221.81.118.1234: Flags [S], seq 314447609, win 64240, options [nop,nop,md5 shared secret not supplied with -M, can't check - bab9b1ba60e4d55efb3d475ee4222311,mss 1460,nop,nop,sackOK,nop,wscale
0], length 0
23:24:48.285172 enP22p3s0f0np0 In  IP 10.221.81.118.1234 > 10.221.81.117.35206: Flags [R.], seq 0, ack 314447610, win 0, options
[nop,nop,md5 shared secret not supplied with -M, can't check - c3bb41109aead9863e97f9cc4e12e7d2], length 0

Yes, indeed, I got this reset too. This patch can fix it:

net/mptcp/subflow.c +0 -0
index 69e773059844..b22daf8c4526 100644
@@ -165,7 +165,8 @@ static int subflow_check_req(struct

request_sock
*req,
  /* no MPTCP if MD5SIG is enabled on this socket or we may run
out of
  * TCP option space.
  */

net/mptcp/subflow.c +0 -1
-	if (rcu_access_pointer(tcp_sk(sk_listener)->md5sig_info))

{

net/mptcp/subflow.c +1 -0
+	if (rcu_access_pointer(tcp_sk(sk_listener)->md5sig_info)

&&

net/mptcp/subflow.c

Quoted 1 line
net/mptcp/subflow.c +1 -0
+	    !__mptcp_check_fallback(mptcp_sk(listener->conn))) {

If __mptcp_check_fallback() is true, does it mean we will accept SYN+MPC+MD5?

Quoted 4 lines

Should we not have something like that?

  if (__mptcp_check_fallback())
      return 0;

Yes, this is much better, I'll update it in v5.

Quoted 3 lines

Please provide packetdrill tests: for the client and server side. For the server side, with and without MPTCP in the injected SYN.

Adding MD5SIG tests to packetdrill is not easy, as packetdrill currently does not accept struct tcp_md5sig as a parameter for setsockopt calls. This makes it difficult to express the following operation in packetdrill:

setsockopt(sockfd, IPPROTO_TCP, TCP_MD5SIG, &md5sig, sizeof(md5sig))

Integer parameters for setsockopt, on the other hand, are straightforward to represent. For example:

+0.0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0

Do I need to extend packetdrill to support struct tcp_md5sig? I'm uncertain and would like your advice.

Thanks,
-Geliang

Quoted 5 lines

(+ adapt the one causing issues)

Cheers,
Matt

maintainer
#9 lore raw

Hi Geliang,

Quoted 1 line · Geliang Tang

On Sun, 2025-08-03 at 09:47 +0200, Matthieu Baerts wrote:

(...)

Quoted 10 lines
Quoted 2 lines

Please provide packetdrill tests: for the client and server side. For the server side, with and without MPTCP in the injected SYN.

Adding MD5SIG tests to packetdrill is not easy, as packetdrill currently does not accept struct tcp_md5sig as a parameter for setsockopt calls. This makes it difficult to express the following operation in packetdrill:

setsockopt(sockfd, IPPROTO_TCP, TCP_MD5SIG, &md5sig, sizeof(md5sig))

Quoted 7 lines

Integer parameters for setsockopt, on the other hand, are straightforward to represent. For example:

+0.0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0

Do I need to extend packetdrill to support struct tcp_md5sig? I'm uncertain and would like your advice.

I see that Packetdrill can parse packet with the TCP_MD5 option, see:

gtests/net/tcp/md5/md5-only-on-client-ack.pkt

But indeed, there is nothing planned to fill tcp_md5sig structure. I guess you need more than 32 bits.

Could you eventually try to add a new type of optval, similar to others that have been added in run_system_call.c:syscall_setsockopt()?

If not, maybe we could do the tests in the selftests, but it looks like that will be a lot of code and infrastructure to test something that might be quick and short (and easier to maintain) with packetdrill, no?

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.