Re: 2.6.13rc3: crypto horribly broken on all 64bit archs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Jul 17, 2005 at 02:20:21PM +0200, Andreas Steinmetz wrote:
> from include/linux/kernel.h:
> 
> #define ALIGN(x,a) (((x)+(a)-1)&~((a)-1))
> 
> from crypto/cipher.c:
> 
> unsigned int alignmask = ...
> u8 *src = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);

The type foolery you suggested is un-obvious, especially at review time.
How about the following instead?

-andy

# HG changeset patch
# User [email protected]
# Node ID ff4d8285dcb581b8340b133c22780c4fcc0dabb3
# Parent  2b0b2208676a22741fc3b1681ca9dd555ca40dfd
Add new PTR_ALIGN macro to encapsulate necessary casting, and use it in
the places where ALIGN was used on pointers.

Signed-Off-By: Andy Isaacson <[email protected]>

diff -r 2b0b2208676a -r ff4d8285dcb5 crypto/cipher.c
--- a/crypto/cipher.c	Sun Jul 17 03:06:51 2005
+++ b/crypto/cipher.c	Tue Jul 19 18:51:11 2005
@@ -43,7 +43,7 @@
 {
 	unsigned int alignmask = crypto_tfm_alg_alignmask(desc->tfm);
 	u8 buffer[bsize * 2 + alignmask];
-	u8 *src = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
+	u8 *src = PTR_ALIGN(buffer, alignmask + 1);
 	u8 *dst = src + bsize;
 	unsigned int n;
 
@@ -166,7 +166,7 @@
 	if (unlikely(((unsigned long)iv & alignmask))) {
 		unsigned int ivsize = tfm->crt_cipher.cit_ivsize;
 		u8 buffer[ivsize + alignmask];
-		u8 *tmp = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
+		u8 *tmp = PTR_ALIGN(buffer, alignmask + 1);
 		int err;
 
 		desc->info = memcpy(tmp, iv, ivsize);
diff -r 2b0b2208676a -r ff4d8285dcb5 drivers/crypto/padlock-aes.c
--- a/drivers/crypto/padlock-aes.c	Sun Jul 17 03:06:51 2005
+++ b/drivers/crypto/padlock-aes.c	Tue Jul 19 18:51:11 2005
@@ -287,7 +287,7 @@
 
 static inline struct aes_ctx *aes_ctx(void *ctx)
 {
-	return (struct aes_ctx *)ALIGN((unsigned long)ctx, PADLOCK_ALIGNMENT);
+	return PTR_ALIGN(ctx, PADLOCK_ALIGNMENT);
 }
 
 static int
diff -r 2b0b2208676a -r ff4d8285dcb5 include/linux/kernel.h
--- a/include/linux/kernel.h	Sun Jul 17 03:06:51 2005
+++ b/include/linux/kernel.h	Tue Jul 19 18:51:11 2005
@@ -29,6 +29,8 @@
 
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 #define ALIGN(x,a) (((x)+(a)-1)&~((a)-1))
+#define PTR_ALIGN(p,a) \
+	((void *)(((unsigned long)(p)+(a)-1)&~(((unsigned long)(a)-1))))
 
 #define	KERN_EMERG	"<0>"	/* system is unusable			*/
 #define	KERN_ALERT	"<1>"	/* action must be taken immediately	*/
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]
  Powered by Linux