Skip to contentSkip to conversation

Add support for v1 of ADD_ADDR option

PATCH Superseded Peter Krystad 2 participants 8 messages Mar 11, 2020 – Mar 16, 2020

Subsystems (3)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Peter Krystad

author
#0 lore raw

v4 cover Add support for v1 of ADD_ADDR option

Support parsing and writing the new option format, with hmac generation and validation.

Support for echoing ADD_ADDR still to come.

v2: check msg len in mptcp_crypto_hmac_sha().
remove obsolete casts
v3: Rebase and split for squashing, patches ready to be applied.
v4: Get the first two patches of the set right

Peter Krystad (5):
mptcp: Re-factor mptcp_crypto_hmac_sha()
mptcp: v1 ADD_ADDR changes: options and parsing
mptcp: v1 ADD_ADDR changes: add_addr_hmac_valid
mptcp: v1 ADD_ADDR changes: add subflow_generate_hmac()
mptcp: v1 ADD_ADDR changes: use subflow_generate_hmac()

 include/linux/tcp.h  |  19 ++++---
 include/net/mptcp.h  |   2 +
 net/mptcp/crypto.c   |  17 ++++--
 net/mptcp/options.c  | 132 +++++++++++++++++++++++++++++++++----------
 net/mptcp/protocol.h |  19 +++++--
 5 files changed, 140 insertions(+), 49 deletions(-)
Signature · 1 line
2.17.2
author
#1 lore raw

PATCH v4 1/5 mptcp: Re-factor mptcp_crypto_hmac_sha()

Allow it to take variable-length messages so that v1 ADD_ADDR option processing may also use it.

squashto: Add ADD_ADDR handling

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>
---
 net/mptcp/crypto.c   | 17 +++++++++++------
 net/mptcp/protocol.h |  3 +--
 2 files changed, 12 insertions(+), 8 deletions(-)
net/mptcp/crypto.c +11 -6
index 40d1bb18fd60..c151628bd416 100644
@@ -44,8 +44,7 @@ void mptcp_crypto_key_sha(u64 key, u32 *token, u64 *idsn)
 		*idsn = be64_to_cpu(*((__be64 *)&mptcp_hashed_key[6]));
 }
 
-void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u32 nonce1, u32 nonce2,
-			   void *hmac)
+void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u8 *msg, int len, void *hmac)
 {
 	u8 input[SHA256_BLOCK_SIZE + SHA256_DIGEST_SIZE];
 	__be32 mptcp_hashed_key[SHA256_DIGEST_WORDS];
@@ -55,6 +54,9 @@ void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u32 nonce1, u32 nonce2,
 	u8 key2be[8];
 	int i;
 
+	if (WARN_ON_ONCE(len > SHA256_DIGEST_SIZE))
+		len = SHA256_DIGEST_SIZE;
+
 	put_unaligned_be64(key1, key1be);
 	put_unaligned_be64(key2, key2be);
 
@@ -65,11 +67,10 @@ void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u32 nonce1, u32 nonce2,
 	for (i = 0; i < 8; i++)
 		input[i + 8] ^= key2be[i];
 
-	put_unaligned_be32(nonce1, &input[SHA256_BLOCK_SIZE]);
-	put_unaligned_be32(nonce2, &input[SHA256_BLOCK_SIZE + 4]);
+	memcpy(&input[SHA256_BLOCK_SIZE], msg, len);
 
 	sha256_init(&state);
-	sha256_update(&state, input, SHA256_BLOCK_SIZE + 8);
+	sha256_update(&state, input, SHA256_BLOCK_SIZE + len);
 
 	/* emit sha256(K1 || msg) on the second input block, so we can
 	 * reuse 'input' for the last hashing
@@ -125,6 +126,7 @@ static int __init test_mptcp_crypto(void)
 	char hmac[20], hmac_hex[41];
 	u32 nonce1, nonce2;
 	u64 key1, key2;
+	u8 msg[8];
 	int i, j;
 
 	for (i = 0; i < ARRAY_SIZE(tests); ++i) {
@@ -134,7 +136,10 @@ static int __init test_mptcp_crypto(void)
 		nonce1 = be32_to_cpu(*((__be32 *)&tests[i].msg[0]));
 		nonce2 = be32_to_cpu(*((__be32 *)&tests[i].msg[4]));
 
-		mptcp_crypto_hmac_sha(key1, key2, nonce1, nonce2, hmac);
+		put_unaligned_be32(nonce1, &msg[0]);
+		put_unaligned_be32(nonce2, &msg[4]);
+
+		mptcp_crypto_hmac_sha(key1, key2, msg, 8, hmac);
 		for (j = 0; j < 20; ++j)
 			sprintf(&hmac_hex[j << 1], "%02x", hmac[j] & 0xff);
 		hmac_hex[40] = 0;
net/mptcp/protocol.h +1 -2
index a524ac55a575..39b36fe1c337 100644
@@ -236,8 +236,7 @@ static inline void mptcp_crypto_key_gen_sha(u64 *key, u32 *token, u64 *idsn)
 	mptcp_crypto_key_sha(*key, token, idsn);
 }
 
-void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u32 nonce1, u32 nonce2,
-			   void *hash_out);
+void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u8 *msg, int len, void *hmac);
 
 static inline struct mptcp_ext *mptcp_get_ext(struct sk_buff *skb)
 {
Signature · 1 line
2.17.2
author
#2 lore raw

PATCH v4 2/5 mptcp: v1 ADD_ADDR changes: options and parsing

In reply to Peter Krystad

Remove family field and add hmac and echo fields to struct mptcp_options_received. Parse incoming hmac on ADD_ADDR option, and send hmac with outgoing option.

squashto: Add ADD_ADDR handling

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>
---
 include/linux/tcp.h  |  19 ++++---
 include/net/mptcp.h  |   2 +
 net/mptcp/options.c  | 132 +++++++++++++++++++++++++++++++++----------
 net/mptcp/protocol.h |  16 ++++--
 4 files changed, 128 insertions(+), 41 deletions(-)
include/linux/tcp.h +11 -8
index 1e733f9fb4ab..2fa145aae5ae 100644
@@ -86,9 +86,13 @@ struct mptcp_options_received {
 	u64	data_seq;
 	u32	subflow_seq;
 	u16	data_len;
-	u8	mp_capable : 1,
+	u16	mp_capable : 1,
 		mp_join : 1,
-		dss : 1;
+		dss : 1,
+		add_addr : 1,
+		rm_addr : 1,
+		family : 4,
+		echo : 1;
 	u8	use_map:1,
 		dsn64:1,
 		data_fin:1,
@@ -96,16 +100,15 @@ struct mptcp_options_received {
 		ack64:1,
 		mpc_map:1,
 		__unused:2;
-	u8	add_addr : 1,
-		rm_addr : 1,
-		family : 4;
 	u8	addr_id;
 	union {
-		struct	in_addr	addr;
-#if IS_ENABLED(CONFIG_IPV6)
-		struct	in6_addr addr6;
+		struct in_addr	addr;
+#if IS_ENABLED(CONFIG_MPTCP_IPV6)
+		struct in6_addr	addr6;
 #endif
 	};
+	u64	ahmac;
+	u8	rm_id;
 };
 #endif
 
include/net/mptcp.h +2 -0
index 2d7e478f0380..0d5ea71dd3d0 100644
@@ -40,6 +40,8 @@ struct mptcp_out_options {
 #endif
 	};
 	u8 addr_id;
+	u64 ahmac;
+	u8 rm_id;
 	struct mptcp_ext ext_copy;
 #endif
 };
net/mptcp/options.c +103 -29

195 lines not on this page · raw message

net/mptcp/protocol.h +12 -4
index 39b36fe1c337..63136193c5b7 100644
@@ -42,9 +42,16 @@
 #define TCPOLEN_MPTCP_DSS_MAP32		10
 #define TCPOLEN_MPTCP_DSS_MAP64		14
 #define TCPOLEN_MPTCP_DSS_CHECKSUM	2
-#define TCPOLEN_MPTCP_ADD_ADDR		8
-#define TCPOLEN_MPTCP_ADD_ADDR6		20
-#define TCPOLEN_MPTCP_RM_ADDR		4
+#define TCPOLEN_MPTCP_ADD_ADDR		16
+#define TCPOLEN_MPTCP_ADD_ADDR_PORT	18
+#define TCPOLEN_MPTCP_ADD_ADDR_BASE	8
+#define TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT	10
+#define TCPOLEN_MPTCP_ADD_ADDR6		28
+#define TCPOLEN_MPTCP_ADD_ADDR6_PORT	30
+#define TCPOLEN_MPTCP_ADD_ADDR6_BASE	20
+#define TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT	22
+#define TCPOLEN_MPTCP_PORT_LEN		2
+#define TCPOLEN_MPTCP_RM_ADDR_BASE	4
 
 /* MPTCP MP_CAPABLE flags */
 #define MPTCP_VERSION_MASK	(0x0F)
@@ -62,7 +69,8 @@
 #define MPTCP_DSS_FLAG_MASK	(0x1F)
 
 /* MPTCP ADD_ADDR flags */
-#define MPTCP_ADDR_FAMILY_MASK	(0x0F)
+#define MPTCP_ADDR_ECHO		BIT(0)
+#define MPTCP_ADDR_HMAC_LEN	20
 #define MPTCP_ADDR_IPVERSION_4	4
 #define MPTCP_ADDR_IPVERSION_6	6
 
Signature · 1 line
2.17.2
author
#5 lore raw

PATCH v4 3/5 mptcp: v1 ADD_ADDR changes: add_addr_hmac_valid

In reply to Peter Krystad

Validate incoming ADD_ADDR options

squash-to: Add path manager interface

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>
---
 net/mptcp/options.c | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)
net/mptcp/options.c +27 -2
index 411ae3ad8c9e..d157e32fb001 100644
@@ -592,6 +592,30 @@ static bool check_fourth_ack(struct mptcp_subflow_context *subflow,
 	return true;
 }
 
+static bool add_addr_hmac_valid(struct mptcp_subflow_context *subflow,
+				struct mptcp_options_received *mp_opt)
+{
+	u64 hmac;
+
+	if (mp_opt->echo)
+		return true;
+
+	if (mp_opt->family == MPTCP_ADDR_IPVERSION_4)
+		hmac = add_addr_generate_hmac(subflow->remote_key,
+					      subflow->local_key,
+					      mp_opt->addr_id, &mp_opt->addr);
+	else
+		hmac = add_addr6_generate_hmac(subflow->remote_key,
+					       subflow->local_key,
+					       mp_opt->addr_id, &mp_opt->addr6);
+
+	pr_debug("subflow=%p, ahmac=%llu, mp_opt->ahmac=%llu\n",
+		 subflow, (unsigned long long)hmac,
+		 (unsigned long long)mp_opt->ahmac);
+
+	return hmac == mp_opt->ahmac;
+}
+
 void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
 			    struct tcp_options_received *opt_rx)
 {
@@ -604,7 +628,7 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
 	if (!check_fourth_ack(subflow, skb, mp_opt))
 		return;
 
-	if (msk && mp_opt->add_addr) {
+	if (msk && mp_opt->add_addr && add_addr_hmac_valid(subflow, mp_opt)) {
 		struct mptcp_addr_info addr;
 
 		addr.port = 0;
@@ -619,7 +643,8 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
 			addr.addr6 = mp_opt->addr6;
 		}
 #endif
-		mptcp_pm_add_addr_received(msk, &addr);
+		if (!mp_opt->echo)
+			mptcp_pm_add_addr_received(msk, &addr);
 		mp_opt->add_addr = 0;
 	}
 
Signature · 1 line
2.17.2
author
#6 lore raw

PATCH v4 4/5 mptcp: v1 ADD_ADDR changes: add subflow_generate_hmac()

In reply to Peter Krystad

Add subflow_generate_hmac() to generate hmac from nonces.

squash-to: Add handling of incoming MP_JOIN requests

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>
---
 net/mptcp/subflow.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
net/mptcp/subflow.c +15 -4
index de35c47e829f..dc7e0cc64659 100644
@@ -48,6 +48,17 @@ static void subflow_req_destructor(struct request_sock *req)
 	tcp_request_sock_ops.destructor(req);
 }
 
+static void subflow_generate_hmac(u64 key1, u64 key2, u32 nonce1, u32 nonce2,
+				  void *hmac)
+{
+	u8 msg[8];
+
+	put_unaligned_be32(nonce1, &msg[0]);
+	put_unaligned_be32(nonce2, &msg[4]);
+
+	mptcp_crypto_hmac_sha(key1, key2, msg, 8, hmac);
+}
+
 /* validate received token and create truncated hmac and nonce for SYN-ACK */
 static bool subflow_token_join_request(struct request_sock *req,
 				       const struct sk_buff *skb)
@@ -73,9 +84,9 @@ static bool subflow_token_join_request(struct request_sock *req,
 
 	get_random_bytes(&subflow_req->local_nonce, sizeof(u32));
 
-	mptcp_crypto_hmac_sha(msk->local_key, msk->remote_key,
+	subflow_generate_hmac(msk->local_key, msk->remote_key,
 			      subflow_req->local_nonce,
-			      subflow_req->remote_nonce, (u32 *)hmac);
+			      subflow_req->remote_nonce, hmac);
 
 	subflow_req->thmac = get_unaligned_be64(hmac);
 
@@ -238,9 +249,9 @@ static bool subflow_hmac_valid(const struct request_sock *req,
 	if (!msk)
 		return false;
 
-	mptcp_crypto_hmac_sha(msk->remote_key, msk->local_key,
+	subflow_generate_hmac(msk->remote_key, msk->local_key,
 			      subflow_req->remote_nonce,
-			      subflow_req->local_nonce, (u32 *)hmac);
+			      subflow_req->local_nonce, hmac);
 
 	ret = true;
 	if (crypto_memneq(hmac, rx_opt->mptcp.hmac, sizeof(hmac)))
Signature · 1 line
2.17.2
author
#7 lore raw

PATCH v4 5/5 mptcp: v1 ADD_ADDR changes: use subflow_generate_hmac()

In reply to Peter Krystad

Use subflow_generate_hmac() to create hmac from nonces.

squash-to: Add handling of outgoing MP_JOIN requests

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>
---
 net/mptcp/subflow.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
net/mptcp/subflow.c +4 -4
index a857ea8cf6ad..728367db6901 100644
@@ -194,9 +194,9 @@ static bool subflow_thmac_valid(struct mptcp_subflow_context *subflow)
 	u8 hmac[MPTCPOPT_HMAC_LEN];
 	u64 thmac;
 
-	mptcp_crypto_hmac_sha(subflow->remote_key, subflow->local_key,
+	subflow_generate_hmac(subflow->remote_key, subflow->local_key,
 			      subflow->remote_nonce, subflow->local_nonce,
-			      (u32 *)hmac);
+			      hmac);
 
 	thmac = get_unaligned_be64(hmac);
 	pr_debug("subflow=%p, token=%u, thmac=%llu, subflow->thmac=%llu\n",
@@ -238,10 +238,10 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb)
 			goto do_reset;
 		}
 
-		mptcp_crypto_hmac_sha(subflow->local_key, subflow->remote_key,
+		subflow_generate_hmac(subflow->local_key, subflow->remote_key,
 				      subflow->local_nonce,
 				      subflow->remote_nonce,
-				      (u32 *)subflow->hmac);
+				      subflow->hmac);
 
 		if (skb)
 			subflow->ssn_offset = TCP_SKB_CB(skb)->seq;
Signature · 1 line
2.17.2
#3 lore raw

[MPTCP] Re: [PATCH v4 2/5] mptcp: v1 ADD_ADDR changes: options and parsing

In reply to Peter Krystad

Hi Peter,

Quoted 43 lines · Peter Krystad

Remove family field and add hmac and echo fields to struct mptcp_options_received. Parse incoming hmac on ADD_ADDR option, and send hmac with outgoing option.

squashto: Add ADD_ADDR handling

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>
---
 include/linux/tcp.h  |  19 ++++---
 include/net/mptcp.h  |   2 +
 net/mptcp/options.c  | 132 +++++++++++++++++++++++++++++++++----------
 net/mptcp/protocol.h |  16 ++++--
 4 files changed, 128 insertions(+), 41 deletions(-)
include/linux/tcp.h +6 -5
index 1e733f9fb4ab..2fa145aae5ae 100644
@@ -86,9 +86,13 @@ struct mptcp_options_received {
 	u64	data_seq;
 	u32	subflow_seq;
 	u16	data_len;
-	u8	mp_capable : 1,
+	u16	mp_capable : 1,
 		mp_join : 1,
-		dss : 1;
+		dss : 1,
+		add_addr : 1,
+		rm_addr : 1,
+		family : 4,
+		echo : 1;
 	u8	use_map:1,
 		dsn64:1,
 		data_fin:1,
@@ -96,16 +100,15 @@ struct mptcp_options_received {
 		ack64:1,
 		mpc_map:1,
 		__unused:2;
-	u8	add_addr : 1,
-		rm_addr : 1,
-		family : 4;
 	u8	addr_id;
 	union {

include/linux/tcp.h struct mptcp_options_received { · line 111

Quoted 10 lines
include/linux/tcp.h +5 -3
-		struct	in_addr	addr;
-#if IS_ENABLED(CONFIG_IPV6)
-		struct	in6_addr addr6;
+		struct in_addr	addr;
+#if IS_ENABLED(CONFIG_MPTCP_IPV6)
+		struct in6_addr	addr6;
 #endif
 	};
+	u64	ahmac;
+	u8	rm_id;

I think we will have 2 bytes hole before the above union. If so, 'rm_id' could be moved there.

Other than that, LGTM.

Thanks,

Paolo

author
#4 lore raw

[MPTCP] Re: [PATCH v4 2/5] mptcp: v1 ADD_ADDR changes: options and parsing

Quoted 51 lines · Paolo Abeni

Hi Peter,

Quoted 48 lines · Peter Krystad

Remove family field and add hmac and echo fields to struct mptcp_options_received. Parse incoming hmac on ADD_ADDR option, and send hmac with outgoing option.

squashto: Add ADD_ADDR handling

Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>
---
 include/linux/tcp.h  |  19 ++++---
 include/net/mptcp.h  |   2 +
 net/mptcp/options.c  | 132 +++++++++++++++++++++++++++++++++----------
 net/mptcp/protocol.h |  16 ++++--
 4 files changed, 128 insertions(+), 41 deletions(-)
include/linux/tcp.h +8 -8
index 1e733f9fb4ab..2fa145aae5ae 100644
@@ -86,9 +86,13 @@ struct mptcp_options_received {
 	u64	data_seq;
 	u32	subflow_seq;
 	u16	data_len;
-	u8	mp_capable : 1,
+	u16	mp_capable : 1,
 		mp_join : 1,
-		dss : 1;
+		dss : 1,
+		add_addr : 1,
+		rm_addr : 1,
+		family : 4,
+		echo : 1;
 	u8	use_map:1,
 		dsn64:1,
 		data_fin:1,
@@ -96,16 +100,15 @@ struct mptcp_options_received {
 		ack64:1,
 		mpc_map:1,
 		__unused:2;
-	u8	add_addr : 1,
-		rm_addr : 1,
-		family : 4;
 	u8	addr_id;
 	union {
-		struct	in_addr	addr;
-#if IS_ENABLED(CONFIG_IPV6)
-		struct	in6_addr addr6;
+		struct in_addr	addr;
+#if IS_ENABLED(CONFIG_MPTCP_IPV6)
Quoted 8 lines

include/linux/tcp.h struct mptcp_options_received { · line 111

Quoted 5 lines
include/linux/tcp.h +3 -0
+		struct in6_addr	addr6;
 #endif
 	};
+	u64	ahmac;
+	u8	rm_id;

I think we will have 2 bytes hole before the above union. If so, 'rm_id' could be moved there.

I'll move rm_id and join_id so we get 4 u8's in a row.

Peter.

Quoted 7 lines

Other than that, LGTM.

Thanks,

Paolo