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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 20 Nov 2007 16:43:40 -0500
From:	"linux-os \(Dick Johnson\)" <linux-os@...logic.com>
To:	"Herbert Xu" <herbert@...dor.apana.org.au>
Cc:	"Linus Torvalds" <torvalds@...ux-foundation.org>,
	"Andrew Morton" <akpm@...ux-foundation.org>,
	"Linux Kernel Mailing List" <linux-kernel@...r.kernel.org>
Subject: Re: [KERNEL]: Avoid divide in IS_ALIGN


On Tue, 20 Nov 2007, Herbert Xu wrote:

> Hi:
>
> [KERNEL]: Avoid divide in IS_ALIGN
>
> I was happy to discover the brand new IS_ALIGN macro and quickly
> used it in my code.  To my dismay I found that the generated code
> used division to perform the test.
>
> This patch fixes it by changing the % test to an &.  This avoids
> the division.
>
> Signed-off-by: Herbert Xu <herbert@...dor.apana.org.au>
>
> Cheers,
> -- 
> Visit Openswan at http://www.openswan.org/
> Email: Herbert Xu ~{PmV>HI~} <herbert@...dor.apana.org.au>
> Home Page: http://gondor.apana.org.au/~herbert/
> PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
> --
> diff --git a/include/linux/kernel.h b/include/linux/kernel.h
> index 94bc996..39b3fa6 100644
> --- a/include/linux/kernel.h
> +++ b/include/linux/kernel.h
> @@ -35,7 +35,7 @@ extern const char linux_proc_banner[];
> #define ALIGN(x,a)		__ALIGN_MASK(x,(typeof(x))(a)-1)
> #define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
> #define PTR_ALIGN(p, a)		((typeof(p))ALIGN((unsigned long)(p), (a)))
> -#define IS_ALIGNED(x,a)		(((x) % ((typeof(x))(a))) == 0)
> +#define IS_ALIGNED(x, a)		(((x) & ((typeof(x))(a) - 1)) == 0)
>

Your macro modification is wrong.

Take 0x12345600, which is aligned on a 16-byte boundary.
Now, with your macro, we have for a 0x10 alignment:
      (0x12345600 & 0x0f) = (0x00 == 0) == TRUE (correct)
For an 0x20 alignment:
      (0x12345600 & 0x1f) = (0x00 == 0) == TRUE (incorrect)

In other words, the macro may work for some alignments, but
not all. It is therefore wrong. You need the modulus, the
remainder after division. Anything else is broken.

Cheers,
Dick Johnson
Penguin : Linux version 2.6.22.1 on an i686 machine (5588.30 BogoMips).
My book : http://www.AbominableFirebug.com/
_


****************************************************************
The information transmitted in this message is confidential and may be privileged.  Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited.  If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to DeliveryErrors@...logic.com - and destroy all copies of this information, including any attachments, without reading or disclosing them.

Thank you.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ