lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 22 Nov 2007 20:11:55 -0800
From:	Stephen Hemminger <shemminger@...ux-foundation.org>
To:	Daniel Drake <dsd@...too.org>
Cc:	davem@...emloft.net, netdev@...r.kernel.org
Subject: Re: [PATCH] add compare_ether_addr_unaligned

On Fri, 23 Nov 2007 00:09:22 +0000 (GMT)
Daniel Drake <dsd@...too.org> wrote:

> David Miller found a problem in a wireless driver where I was using
> compare_ether_addr() on potentially unaligned data. Document that
> compare_ether_addr() is not safe for use everywhere, and add an equivalent
> function that works regardless of alignment.
> 
> Signed-off-by: Daniel Drake <dsd@...too.org>
> 
> Index: linux-2.6.24-rc3-git1/include/linux/etherdevice.h
> ===================================================================
> --- linux-2.6.24-rc3-git1.orig/include/linux/etherdevice.h
> +++ linux-2.6.24-rc3-git1/include/linux/etherdevice.h
> @@ -123,11 +123,13 @@ static inline void random_ether_addr(u8 
>  }
>  
>  /**
> - * compare_ether_addr - Compare two Ethernet addresses
> + * compare_ether_addr - Compare two 16-bit-aligned Ethernet addresses
>   * @addr1: Pointer to a six-byte array containing the Ethernet address
>   * @addr2: Pointer other six-byte array containing the Ethernet address
>   *
> - * Compare two ethernet addresses, returns 0 if equal
> + * Compare two ethernet addresses, returns 0 if equal. Both addresses must
> + * be 16-bit aligned. For unaligned or potentially unaligned address
> + * comparisons, use compare_ether_addr_unaligned() instead.
>   */
>  static inline unsigned compare_ether_addr(const u8 *addr1, const u8 *addr2)
>  {
> @@ -137,6 +139,21 @@ static inline unsigned compare_ether_add
>  	BUILD_BUG_ON(ETH_ALEN != 6);
>  	return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2])) != 0;
>  }
> +
> +/**
> + * compare_ether_addr_unaligned - Compare two Ethernet addresses
> + * @addr1: Pointer to a six-byte array containing the Ethernet address
> + * @addr2: Pointer other six-byte array containing the Ethernet address
> + *
> + * Compare two ethernet addresses, returns 0 if equal. compare_ether_addr()
> + * is faster than this function, but unless you can ensure alignment you
> + * must use this function instead.
> + */
> +static inline unsigned compare_ether_addr_unaligned(const u8 *addr1,
> +						    const u8 *addr2)
> +{
> +	return memcmp(addr1, addr2, ETH_ALEN);
> +}
>  #endif	/* __KERNEL__ */


You could probably get the similar speedup by doing xor by byte, rather
than falling back to memcmp.
-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ