netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v2] ipv6: sr: Fix MAC comparison to be constant-time
@ 2025-08-18 20:27 Eric Biggers
  2025-08-20 15:37 ` Andrea Mayer
  2025-08-21  2:40 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Biggers @ 2025-08-18 20:27 UTC (permalink / raw)
  To: netdev, Andrea Mayer
  Cc: linux-crypto, David Lebrun, Minhong He, Eric Biggers, stable

To prevent timing attacks, MACs need to be compared in constant time.
Use the appropriate helper function for this.

Fixes: bf355b8d2c30 ("ipv6: sr: add core files for SR HMAC support")
Cc: stable@vger.kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---

v2: sent as standalone patch targeting net instead of net-next.

 net/ipv6/seg6_hmac.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/ipv6/seg6_hmac.c b/net/ipv6/seg6_hmac.c
index f78ecb6ad8383..5dae892bbc73b 100644
--- a/net/ipv6/seg6_hmac.c
+++ b/net/ipv6/seg6_hmac.c
@@ -33,10 +33,11 @@
 #include <net/ip6_route.h>
 #include <net/addrconf.h>
 #include <net/xfrm.h>
 
 #include <crypto/hash.h>
+#include <crypto/utils.h>
 #include <net/seg6.h>
 #include <net/genetlink.h>
 #include <net/seg6_hmac.h>
 #include <linux/random.h>
 
@@ -278,11 +279,11 @@ bool seg6_hmac_validate_skb(struct sk_buff *skb)
 		return false;
 
 	if (seg6_hmac_compute(hinfo, srh, &ipv6_hdr(skb)->saddr, hmac_output))
 		return false;
 
-	if (memcmp(hmac_output, tlv->hmac, SEG6_HMAC_FIELD_LEN) != 0)
+	if (crypto_memneq(hmac_output, tlv->hmac, SEG6_HMAC_FIELD_LEN))
 		return false;
 
 	return true;
 }
 EXPORT_SYMBOL(seg6_hmac_validate_skb);

base-commit: 715c7a36d59f54162a26fac1d1ed8dc087a24cf1
-- 
2.50.1


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

* Re: [PATCH net v2] ipv6: sr: Fix MAC comparison to be constant-time
  2025-08-18 20:27 [PATCH net v2] ipv6: sr: Fix MAC comparison to be constant-time Eric Biggers
@ 2025-08-20 15:37 ` Andrea Mayer
  2025-08-21  2:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Andrea Mayer @ 2025-08-20 15:37 UTC (permalink / raw)
  To: Eric Biggers
  Cc: netdev, linux-crypto, David Lebrun, Minhong He, stable,
	stefano.salsano, Paolo Lungaroni, Andrea Mayer

On Mon, 18 Aug 2025 13:27:24 -0700
Eric Biggers <ebiggers@kernel.org> wrote:

> To prevent timing attacks, MACs need to be compared in constant time.
> Use the appropriate helper function for this.
> 
> Fixes: bf355b8d2c30 ("ipv6: sr: add core files for SR HMAC support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Eric Biggers <ebiggers@kernel.org>
> ---
> 
> v2: sent as standalone patch targeting net instead of net-next.
> 
>  net/ipv6/seg6_hmac.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 

The fix looks good to me. Thanks!

Ciao,
Andrea

Reviewed-by: Andrea Mayer <andrea.mayer@uniroma2.it>

> diff --git a/net/ipv6/seg6_hmac.c b/net/ipv6/seg6_hmac.c
> index f78ecb6ad8383..5dae892bbc73b 100644
> --- a/net/ipv6/seg6_hmac.c
> +++ b/net/ipv6/seg6_hmac.c
> @@ -33,10 +33,11 @@
>  #include <net/ip6_route.h>
>  #include <net/addrconf.h>
>  #include <net/xfrm.h>
>  
>  #include <crypto/hash.h>
> +#include <crypto/utils.h>
>  #include <net/seg6.h>
>  #include <net/genetlink.h>
>  #include <net/seg6_hmac.h>
>  #include <linux/random.h>
>  
> @@ -278,11 +279,11 @@ bool seg6_hmac_validate_skb(struct sk_buff *skb)
>  		return false;
>  
>  	if (seg6_hmac_compute(hinfo, srh, &ipv6_hdr(skb)->saddr, hmac_output))
>  		return false;
>  
> -	if (memcmp(hmac_output, tlv->hmac, SEG6_HMAC_FIELD_LEN) != 0)
> +	if (crypto_memneq(hmac_output, tlv->hmac, SEG6_HMAC_FIELD_LEN))
>  		return false;
>  
>  	return true;
>  }
>  EXPORT_SYMBOL(seg6_hmac_validate_skb);
> 
> base-commit: 715c7a36d59f54162a26fac1d1ed8dc087a24cf1
> -- 
> 2.50.1
>

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

* Re: [PATCH net v2] ipv6: sr: Fix MAC comparison to be constant-time
  2025-08-18 20:27 [PATCH net v2] ipv6: sr: Fix MAC comparison to be constant-time Eric Biggers
  2025-08-20 15:37 ` Andrea Mayer
@ 2025-08-21  2:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-08-21  2:40 UTC (permalink / raw)
  To: Eric Biggers
  Cc: netdev, andrea.mayer, linux-crypto, dlebrun, heminhong, stable

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Mon, 18 Aug 2025 13:27:24 -0700 you wrote:
> To prevent timing attacks, MACs need to be compared in constant time.
> Use the appropriate helper function for this.
> 
> Fixes: bf355b8d2c30 ("ipv6: sr: add core files for SR HMAC support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Eric Biggers <ebiggers@kernel.org>
> 
> [...]

Here is the summary with links:
  - [net,v2] ipv6: sr: Fix MAC comparison to be constant-time
    https://git.kernel.org/netdev/net/c/a458b2902115

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] 3+ messages in thread

end of thread, other threads:[~2025-08-21  2:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-18 20:27 [PATCH net v2] ipv6: sr: Fix MAC comparison to be constant-time Eric Biggers
2025-08-20 15:37 ` Andrea Mayer
2025-08-21  2:40 ` 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).