From: Andy Isaacson <adi@hexapodia.org>
To: Andreas Steinmetz <ast@domdv.de>
Cc: Linux Kernel Mailinglist <linux-kernel@vger.kernel.org>,
jmorris@intercode.com.au, herbert@gondor.apana.org.au
Subject: Re: 2.6.13rc3: crypto horribly broken on all 64bit archs
Date: Tue, 19 Jul 2005 21:41:12 -0700 [thread overview]
Message-ID: <20050720044112.GA18957@hexapodia.org> (raw)
In-Reply-To: <42DA4D05.7000403@domdv.de>
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 adi@hexapodia.org
# 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 <adi@hexapodia.org>
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 */
prev parent reply other threads:[~2005-07-20 4:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-17 12:20 2.6.13rc3: crypto horribly broken on all 64bit archs Andreas Steinmetz
2005-07-17 20:45 ` Herbert Xu
2005-07-18 20:24 ` David S. Miller
2005-07-20 4:41 ` Andy Isaacson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20050720044112.GA18957@hexapodia.org \
--to=adi@hexapodia.org \
--cc=ast@domdv.de \
--cc=herbert@gondor.apana.org.au \
--cc=jmorris@intercode.com.au \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.