Skip to contentSkip to conversation

mptcp: use rightmost 64 bits in ADD_ADDR HMAC

PATCH In review Todd Malsbary 4 participants 9 messages May 18, 2020 – May 20, 2020

Subsystems (2)
lore
Share & tools
lore

Todd Malsbary

author
#0 lore raw

PATCH 1/1 mptcp: use rightmost 64 bits in ADD_ADDR HMAC

This changes the HMAC used in the ADD_ADDR option from the leftmost 64 bits to the rightmost 64 bits as described in RFC 8684, section 3.4.1.

Signed-off-by Todd Malsbary <todd.malsbary(a)linux.intel.com>

---

I found this while adding support to packetdrill for the ADD_ADDR v1 option. The computation I used for the HMAC in the pending packetdrill work gave a different result than what was being computed by the kernel.

It appears that the usage of the leftmost bits has been in place since at least 2016 in the out-of-tree code (commit de09a83186666). Given that, is the issue in the implementation or the RFC?

 net/mptcp/options.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/mptcp/options.c +2 -2
index ece6f92cf7d1..0e11fb3d908f 100644
@@ -550,7 +550,7 @@ static u64 add_addr_generate_hmac(u64 key1, u64 key2, u8 addr_id,
 
 	mptcp_crypto_hmac_sha(key1, key2, msg, 7, hmac);
 
-	return get_unaligned_be64(hmac);
+	return get_unaligned_be64(&hmac[MPTCP_ADDR_HMAC_LEN - sizeof(u64)]);
 }
 
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
@@ -567,7 +567,7 @@ static u64 add_addr6_generate_hmac(u64 key1, u64 key2, u8 addr_id,
 
 	mptcp_crypto_hmac_sha(key1, key2, msg, 19, hmac);
 
-	return get_unaligned_be64(hmac);
+	return get_unaligned_be64(&hmac[MPTCP_ADDR_HMAC_LEN - sizeof(u64)]);
 }
 #endif
 
Signature · 1 line
2.25.4
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Todd Malsbary

This changes the HMAC used in the ADD_ADDR option from the leftmost 64 bits to the rightmost 64 bits as described in RFC 8684, section 3.4.1.

Signed-off-by Todd Malsbary <todd.malsbary(a)linux.intel.com>

Nice find!

Acked-by Christoph Paasch <cpaasch(a)apple.com>

And I need to change out-of-tree MPTCP as well ;-)

Christoph

Reviewed-by
#2 lore raw

Hi Todd,

Quoted 7 lines · Christoph Paasch
Quoted 4 lines · Todd Malsbary

This changes the HMAC used in the ADD_ADDR option from the leftmost 64 bits to the rightmost 64 bits as described in RFC 8684, section 3.4.1.

Signed-off-by Todd Malsbary <todd.malsbary(a)linux.intel.com>

Nice find!

Yes, good catch!

Reviewed-by Matthieu Baerts <matthieu.baerts(a)tessares.net>

I guess we should send that to -net branch, ideally before the release of v5.7, not to introduce incompatibilities between versions. What do you think?

Quoted 4 lines

I found this while adding support to packetdrill for the ADD_ADDR v1 option. The computation I used for the HMAC in the pending packetdrill work gave a different result than what was being computed by the kernel.

Good to hear you are looking at adding ADD_ADDRv1 support to packetdrill! :)

Cheers,
Matt

Signature · 5 lines
Matthieu Baerts | R&D Engineer
matthieu.baerts(a)tessares.net
Tessares SA | Hybrid Access Solutions
www.tessares.net
1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium
author
#3 lore raw

Hi Matthieu,

Quoted 11 lines · Matthieu Baerts

Hi Todd,

Quoted 7 lines · Christoph Paasch
Quoted 4 lines · Todd Malsbary

This changes the HMAC used in the ADD_ADDR option from the leftmost 64 bits to the rightmost 64 bits as described in RFC 8684, section 3.4.1.

Signed-off-by Todd Malsbary <todd.malsbary(a)linux.intel.com>

Nice find!

Quoted 8 lines

Yes, good catch!

Reviewed-by Matthieu Baerts <matthieu.baerts(a)tessares.net>

I guess we should send that to -net branch, ideally before the release of v5.7, not to introduce incompatibilities between versions. What do you think?

Sounds good to me. Just to double check on the process: send this patch out again to the netdev list with [PATCH net] as the prefix, and cc this list?

Thanks,
-Todd

#4 lore raw

Hi Todd,

Quoted 18 lines · Todd Malsbary

Hi Matthieu,

Quoted 15 lines · Matthieu Baerts

Hi Todd,

Quoted 7 lines · Christoph Paasch
Quoted 4 lines · Todd Malsbary

This changes the HMAC used in the ADD_ADDR option from the leftmost 64 bits to the rightmost 64 bits as described in RFC 8684, section 3.4.1.

Signed-off-by Todd Malsbary <todd.malsbary(a)linux.intel.com>

Nice find!

Yes, good catch!

Reviewed-by Matthieu Baerts <matthieu.baerts(a)tessares.net>
Quoted 8 lines
Quoted 4 lines

I guess we should send that to -net branch, ideally before the release of v5.7, not to introduce incompatibilities between versions. What do you think?

Sounds good to me. Just to double check on the process: send this patch out again to the netdev list with [PATCH net] as the prefix, and cc this list?

(We continued the discussion on IRC).
In short: yes but "Fixes" tag is required.

Cheers,
Matt

Signature · 5 lines
Matthieu Baerts | R&D Engineer
matthieu.baerts(a)tessares.net
Tessares SA | Hybrid Access Solutions
www.tessares.net
1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium
#5 lore raw
In reply to Todd Malsbary

Hello,

Quoted 23 lines · Todd Malsbary

This changes the HMAC used in the ADD_ADDR option from the leftmost 64 bits to the rightmost 64 bits as described in RFC 8684, section 3.4.1.

Signed-off-by Todd Malsbary <todd.malsbary(a)linux.intel.com>

---

I found this while adding support to packetdrill for the ADD_ADDR v1 option. The computation I used for the HMAC in the pending packetdrill work gave a different result than what was being computed by the kernel.

It appears that the usage of the leftmost bits has been in place since at least 2016 in the out-of-tree code (commit de09a83186666). Given that, is the issue in the implementation or the RFC?

 net/mptcp/options.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/mptcp/options.c +0 -0
index ece6f92cf7d1..0e11fb3d908f 100644

net/mptcp/options.c static u64 add_addr_generate_hmac(u64 key1, u64 key2, u8 addr_id, · line 553

Quoted 5 lines
net/mptcp/options.c +1 -1
@@ -550,7 +550,7 @@ static u64 add_addr_generate_hmac(u64 key1, u64 key2, u8 addr_id,
 
 	mptcp_crypto_hmac_sha(key1, key2, msg, 7, hmac);
 
-	return get_unaligned_be64(hmac);
+	return get_unaligned_be64(&hmac[MPTCP_ADDR_HMAC_LEN - sizeof(u64)]);

as I was trying to do the same change in out-of-tree MPTCP, I realize something maybe a little bit late:

I think MPTCP_ADDR_HMAC_LEN is the wrong variable, no?

We want to take the rightmost bits of the SHA-256 output. Meaning, we need to get the right most out of mptcp_hashed_key in mptcp_crypto_hmac_sha().

Because this latter function is already only copying the first 160bits to hashed_out - thus we are missing the remaining bits...

Right?

Christoph

Quoted 17 lines
net/mptcp/options.c +1 -1
 }
 
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
@@ -567,7 +567,7 @@ static u64 add_addr6_generate_hmac(u64 key1, u64 key2, u8 addr_id,
 
 	mptcp_crypto_hmac_sha(key1, key2, msg, 19, hmac);
 
-	return get_unaligned_be64(hmac);
+	return get_unaligned_be64(&hmac[MPTCP_ADDR_HMAC_LEN - sizeof(u64)]);
 }
 #endif
 
Signature · 4 lines
2.25.4
_______________________________________________
mptcp mailing list -- mptcp(a)lists.01.org
To unsubscribe send an email to mptcp-leave(a)lists.01.org
author
#6 lore raw

Hi Christoph,

Quoted 37 lines · Christoph Paasch

Hello,

Quoted 23 lines · Todd Malsbary

This changes the HMAC used in the ADD_ADDR option from the leftmost 64 bits to the rightmost 64 bits as described in RFC 8684, section 3.4.1.

Signed-off-by Todd Malsbary <todd.malsbary(a)linux.intel.com>

---

I found this while adding support to packetdrill for the ADD_ADDR v1 option. The computation I used for the HMAC in the pending packetdrill work gave a different result than what was being computed by the kernel.

It appears that the usage of the leftmost bits has been in place since at least 2016 in the out-of-tree code (commit de09a83186666). Given that, is the issue in the implementation or the RFC?

 net/mptcp/options.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/mptcp/options.c +0 -0
index ece6f92cf7d1..0e11fb3d908f 100644

net/mptcp/options.c static u64 add_addr_generate_hmac(u64 key1, u64 key2, u8 addr_id, · line 553

Quoted 5 lines
net/mptcp/options.c +1 -1
@@ -550,7 +550,7 @@ static u64 add_addr_generate_hmac(u64 key1, u64 key2, u8 addr_id,
 
 	mptcp_crypto_hmac_sha(key1, key2, msg, 7, hmac);
 
-	return get_unaligned_be64(hmac);
+	return get_unaligned_be64(&hmac[MPTCP_ADDR_HMAC_LEN - sizeof(u64)]);

as I was trying to do the same change in out-of-tree MPTCP, I realize something maybe a little bit late:

I think MPTCP_ADDR_HMAC_LEN is the wrong variable, no?

Quoted 10 lines

We want to take the rightmost bits of the SHA-256 output. Meaning, we need to get the right most out of mptcp_hashed_key in mptcp_crypto_hmac_sha().

Because this latter function is already only copying the first 160bits to hashed_out - thus we are missing the remaining bits...

Right?

I wondered the same thing, but my read of the RFC is the rightmost 64 bits of the 160 bits. From Section 3.4.1:

"The Truncated HMAC parameter present in this option is the rightmost 64 bits of an HMAC, negotiated and calculated in the same way as for MP_JOIN as described in Section 3.2."

Then back in Section 3.2 the HMAC is defined as:

"This specification defines that HMAC as defined in [RFC2104] is used, along with the SHA-256 hash algorithm [RFC6234], and that the output is truncated to the leftmost 160 bits (20 octets). Due to option space limitations, the HMAC included in the SYN/ACK is truncated to the leftmost 64 bits, but this is acceptable, ..."

I left the "Due to ..." sentence in there since that implies to me that the leftmost/rightmost selection is taken after the 160 bit truncation, but I'll admit that it could argued either way. Thoughts?

-Todd

#7 lore raw
Quoted 66 lines · Todd Malsbary

Hi Christoph,

Quoted 37 lines · Christoph Paasch

Hello,

Quoted 23 lines · Todd Malsbary

This changes the HMAC used in the ADD_ADDR option from the leftmost 64 bits to the rightmost 64 bits as described in RFC 8684, section 3.4.1.

Signed-off-by Todd Malsbary <todd.malsbary(a)linux.intel.com>

---

I found this while adding support to packetdrill for the ADD_ADDR v1 option. The computation I used for the HMAC in the pending packetdrill work gave a different result than what was being computed by the kernel.

It appears that the usage of the leftmost bits has been in place since at least 2016 in the out-of-tree code (commit de09a83186666). Given that, is the issue in the implementation or the RFC?

 net/mptcp/options.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/mptcp/options.c +0 -0
index ece6f92cf7d1..0e11fb3d908f 100644

net/mptcp/options.c static u64 add_addr_generate_hmac(u64 key1, u64 key2, u8 addr_id, · line 553

Quoted 5 lines
net/mptcp/options.c +1 -1
@@ -550,7 +550,7 @@ static u64 add_addr_generate_hmac(u64 key1, u64 key2, u8 addr_id,
 
 	mptcp_crypto_hmac_sha(key1, key2, msg, 7, hmac);
 
-	return get_unaligned_be64(hmac);
+	return get_unaligned_be64(&hmac[MPTCP_ADDR_HMAC_LEN - sizeof(u64)]);

as I was trying to do the same change in out-of-tree MPTCP, I realize something maybe a little bit late:

I think MPTCP_ADDR_HMAC_LEN is the wrong variable, no?

Quoted 10 lines

We want to take the rightmost bits of the SHA-256 output. Meaning, we need to get the right most out of mptcp_hashed_key in mptcp_crypto_hmac_sha().

Because this latter function is already only copying the first 160bits to hashed_out - thus we are missing the remaining bits...

Right?

I wondered the same thing, but my read of the RFC is the rightmost 64 bits of the 160 bits. From Section 3.4.1:

"The Truncated HMAC parameter present in this option is the rightmost 64 bits of an HMAC, negotiated and calculated in the same way as for MP_JOIN as described in Section 3.2."

Then back in Section 3.2 the HMAC is defined as:

"This specification defines that HMAC as defined in [RFC2104] is used, along with the SHA-256 hash algorithm [RFC6234], and that the output is truncated to the leftmost 160 bits (20 octets). Due to option space limitations, the HMAC included in the SYN/ACK is truncated to the leftmost 64 bits, but this is acceptable, ..."

Quoted 3 lines

I left the "Due to ..." sentence in there since that implies to me that the leftmost/rightmost selection is taken after the 160 bit truncation, but I'll admit that it could argued either way. Thoughts?

I would not have interpret it that way. I thought that the back-reference to Section 3.2 is more about the key-concatenation. The truncation to leftmost 160bits is to me just for the third ACK.

Christoph

#8 lore raw
Quoted 67 lines · Christoph Paasch
Quoted 66 lines · Todd Malsbary

Hi Christoph,

Quoted 37 lines · Christoph Paasch

Hello,

Quoted 23 lines · Todd Malsbary

This changes the HMAC used in the ADD_ADDR option from the leftmost 64 bits to the rightmost 64 bits as described in RFC 8684, section 3.4.1.

Signed-off-by Todd Malsbary <todd.malsbary(a)linux.intel.com>

---

I found this while adding support to packetdrill for the ADD_ADDR v1 option. The computation I used for the HMAC in the pending packetdrill work gave a different result than what was being computed by the kernel.

It appears that the usage of the leftmost bits has been in place since at least 2016 in the out-of-tree code (commit de09a83186666). Given that, is the issue in the implementation or the RFC?

 net/mptcp/options.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/mptcp/options.c +0 -0
index ece6f92cf7d1..0e11fb3d908f 100644

net/mptcp/options.c static u64 add_addr_generate_hmac(u64 key1, u64 key2, u8 addr_id, · line 553

Quoted 5 lines
net/mptcp/options.c +1 -1
@@ -550,7 +550,7 @@ static u64 add_addr_generate_hmac(u64 key1, u64 key2, u8 addr_id,
 
 	mptcp_crypto_hmac_sha(key1, key2, msg, 7, hmac);
 
-	return get_unaligned_be64(hmac);
+	return get_unaligned_be64(&hmac[MPTCP_ADDR_HMAC_LEN - sizeof(u64)]);

as I was trying to do the same change in out-of-tree MPTCP, I realize something maybe a little bit late:

I think MPTCP_ADDR_HMAC_LEN is the wrong variable, no?

Quoted 10 lines

We want to take the rightmost bits of the SHA-256 output. Meaning, we need to get the right most out of mptcp_hashed_key in mptcp_crypto_hmac_sha().

Because this latter function is already only copying the first 160bits to hashed_out - thus we are missing the remaining bits...

Right?

I wondered the same thing, but my read of the RFC is the rightmost 64 bits of the 160 bits. From Section 3.4.1:

"The Truncated HMAC parameter present in this option is the rightmost 64 bits of an HMAC, negotiated and calculated in the same way as for MP_JOIN as described in Section 3.2."

Then back in Section 3.2 the HMAC is defined as:

"This specification defines that HMAC as defined in [RFC2104] is used, along with the SHA-256 hash algorithm [RFC6234], and that the output is truncated to the leftmost 160 bits (20 octets). Due to option space limitations, the HMAC included in the SYN/ACK is truncated to the leftmost 64 bits, but this is acceptable, ..."

Quoted 7 lines
Quoted 3 lines

I left the "Due to ..." sentence in there since that implies to me that the leftmost/rightmost selection is taken after the 160 bit truncation, but I'll admit that it could argued either way. Thoughts?

I would not have interpret it that way. I thought that the back-reference to Section 3.2 is more about the key-concatenation. The truncation to leftmost 160bits is to me just for the third ACK.

It is ambiguously worded to me, but the thing that registered to me after looking at more context is that the 160-bit version for the third ACK is also referred to as a "Truncated HMAC" (in RFC6864, it was just "HMAC" since it was SHA1 and did not require truncation). That makes me lean toward using the rightmost bits of the full SHA256 hash. It also makes it so the truncated HMAC in the ADD_ADDR can't be copied from the 160-bit truncation seen on the wire (if that's even worth anything).

--
Mat Martineau
Intel