All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] crypto: hash - Fix handling of small unaligned buffers
@ 2010-08-02 12:45 Szilveszter Ördög
  2010-08-04 13:48 ` Herbert Xu
  0 siblings, 1 reply; 6+ messages in thread
From: Szilveszter Ördög @ 2010-08-02 12:45 UTC (permalink / raw)
  To: linux-crypto; +Cc: Herbert Xu

If a scatterwalk chain contains an entry with an unaligned offset then
hash_walk_next() will cut off the next step at the next alignment point.

However, if the entry ends before the next alignment point then we will want to
process more data than it is available.

Fix this by checking whether the next aligment point is before the end of the
current entry.
---
 crypto/ahash.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/crypto/ahash.c b/crypto/ahash.c
index b8c59b8..f669822 100644
--- a/crypto/ahash.c
+++ b/crypto/ahash.c
@@ -47,8 +47,11 @@ static int hash_walk_next(struct crypto_hash_walk *walk)
 	walk->data = crypto_kmap(walk->pg, 0);
 	walk->data += offset;

-	if (offset & alignmask)
-		nbytes = alignmask + 1 - (offset & alignmask);
+	if (offset & alignmask) {
+		unsigned int unaligned = alignmask + 1 - (offset & alignmask);
+		if (nbytes > unaligned)
+			nbytes = unaligned;
+	}

 	walk->entrylen -= nbytes;
 	return nbytes;
-- 
1.5.5.6

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

* Re: [PATCH] crypto: hash - Fix handling of small unaligned buffers
  2010-08-02 12:45 [PATCH] crypto: hash - Fix handling of small unaligned buffers Szilveszter Ördög
@ 2010-08-04 13:48 ` Herbert Xu
  2010-08-04 20:59   ` David Miller
  0 siblings, 1 reply; 6+ messages in thread
From: Herbert Xu @ 2010-08-04 13:48 UTC (permalink / raw)
  To: Szilveszter Ördög; +Cc: linux-crypto, David S. Miller

On Mon, Aug 02, 2010 at 02:45:37PM +0200, Szilveszter Ördög wrote:
> If a scatterwalk chain contains an entry with an unaligned offset then
> hash_walk_next() will cut off the next step at the next alignment point.
> 
> However, if the entry ends before the next alignment point then we will want to
> process more data than it is available.
> 
> Fix this by checking whether the next aligment point is before the end of the
> current entry.
> ---
>  crypto/ahash.c |    7 +++++--
>  1 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/crypto/ahash.c b/crypto/ahash.c
> index b8c59b8..f669822 100644
> --- a/crypto/ahash.c
> +++ b/crypto/ahash.c
> @@ -47,8 +47,11 @@ static int hash_walk_next(struct crypto_hash_walk *walk)
>  	walk->data = crypto_kmap(walk->pg, 0);
>  	walk->data += offset;
> 
> -	if (offset & alignmask)
> -		nbytes = alignmask + 1 - (offset & alignmask);
> +	if (offset & alignmask) {
> +		unsigned int unaligned = alignmask + 1 - (offset & alignmask);
> +		if (nbytes > unaligned)
> +			nbytes = unaligned;
> +	}
> 
>  	walk->entrylen -= nbytes;
>  	return nbytes;

The patch looks OK to me.  Dave, what do you think?

But you forgot to attach a Signed-off-by line.  Please resend
with one attached.

Thanks!
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: [PATCH] crypto: hash - Fix handling of small unaligned buffers
  2010-08-04 13:48 ` Herbert Xu
@ 2010-08-04 20:59   ` David Miller
  0 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2010-08-04 20:59 UTC (permalink / raw)
  To: herbert; +Cc: slipszi, linux-crypto

From: Herbert Xu <herbert@gondor.apana.org.au>
Date: Wed, 4 Aug 2010 21:48:51 +0800

> On Mon, Aug 02, 2010 at 02:45:37PM +0200, Szilveszter Ördög wrote:
>> If a scatterwalk chain contains an entry with an unaligned offset then
>> hash_walk_next() will cut off the next step at the next alignment point.
>> 
>> However, if the entry ends before the next alignment point then we will want to
>> process more data than it is available.
>> 
>> Fix this by checking whether the next aligment point is before the end of the
>> current entry.
>> ---
>>  crypto/ahash.c |    7 +++++--
>>  1 files changed, 5 insertions(+), 2 deletions(-)
>> 
>> diff --git a/crypto/ahash.c b/crypto/ahash.c
>> index b8c59b8..f669822 100644
>> --- a/crypto/ahash.c
>> +++ b/crypto/ahash.c
>> @@ -47,8 +47,11 @@ static int hash_walk_next(struct crypto_hash_walk *walk)
>>  	walk->data = crypto_kmap(walk->pg, 0);
>>  	walk->data += offset;
>> 
>> -	if (offset & alignmask)
>> -		nbytes = alignmask + 1 - (offset & alignmask);
>> +	if (offset & alignmask) {
>> +		unsigned int unaligned = alignmask + 1 - (offset & alignmask);
>> +		if (nbytes > unaligned)
>> +			nbytes = unaligned;
>> +	}
>> 
>>  	walk->entrylen -= nbytes;
>>  	return nbytes;
> 
> The patch looks OK to me.  Dave, what do you think?

Looks good, thanks Szilveszter:

Acked-by: David S. Miller <davem@davemloft.net>

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

* Re: [PATCH] crypto: hash - Fix handling of small unaligned buffers
  2010-08-05 10:05 Szilveszter Ördög
@ 2010-08-06  1:27 ` Herbert Xu
  0 siblings, 0 replies; 6+ messages in thread
From: Herbert Xu @ 2010-08-06  1:27 UTC (permalink / raw)
  To: Szilveszter Ördög; +Cc: linux-crypto, davem

On Thu, Aug 05, 2010 at 12:05:49PM +0200, Szilveszter Ördög wrote:
> If a scatterwalk chain contains an entry with an unaligned offset then
> hash_walk_next() will cut off the next step at the next alignment point.
> 
> However, if the entry ends before the next alignment point then we a loop,
> which leads to a kernel oops.
> 
> Fix this by checking whether the next aligment point is before the end of the
> current entry.
> 
> Signed-off-by: Szilveszter Ördög <slipszi@gmail.com>

Patch applied to crypto-2.6.  Thanks!
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* [PATCH] crypto: hash - Fix handling of small unaligned buffers
@ 2010-08-05 10:05 Szilveszter Ördög
  2010-08-06  1:27 ` Herbert Xu
  0 siblings, 1 reply; 6+ messages in thread
From: Szilveszter Ördög @ 2010-08-05 10:05 UTC (permalink / raw)
  To: linux-crypto, Herbert Xu, davem

If a scatterwalk chain contains an entry with an unaligned offset then
hash_walk_next() will cut off the next step at the next alignment point.

However, if the entry ends before the next alignment point then we a loop,
which leads to a kernel oops.

Fix this by checking whether the next aligment point is before the end of the
current entry.

Signed-off-by: Szilveszter Ördög <slipszi@gmail.com>
---
Added the Signed-off-by line

 crypto/ahash.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/crypto/ahash.c b/crypto/ahash.c
index b8c59b8..f669822 100644
--- a/crypto/ahash.c
+++ b/crypto/ahash.c
@@ -47,8 +47,11 @@ static int hash_walk_next(struct crypto_hash_walk *walk)
 	walk->data = crypto_kmap(walk->pg, 0);
 	walk->data += offset;

-	if (offset & alignmask)
-		nbytes = alignmask + 1 - (offset & alignmask);
+	if (offset & alignmask) {
+		unsigned int unaligned = alignmask + 1 - (offset & alignmask);
+		if (nbytes > unaligned)
+			nbytes = unaligned;
+	}

 	walk->entrylen -= nbytes;
 	return nbytes;
-- 
1.5.5.6

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

* [PATCH] crypto: hash - Fix handling of small unaligned buffers
@ 2010-06-16 10:28 Szilveszter Ördög
  0 siblings, 0 replies; 6+ messages in thread
From: Szilveszter Ördög @ 2010-06-16 10:28 UTC (permalink / raw)
  To: linux-crypto

If a scatterwalk chain contains an entry with an unaligned offset then
hash_walk_next() will cut off the next step at the next alignment point.

However, if the entry ends before the next alignment point then we will want to
process more data than it is available.

Fix this by checking whether the next aligment point is before the end of the
current entry.
---
 crypto/ahash.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/crypto/ahash.c b/crypto/ahash.c
index b8c59b8..f669822 100644
--- a/crypto/ahash.c
+++ b/crypto/ahash.c
@@ -47,8 +47,11 @@ static int hash_walk_next(struct crypto_hash_walk *walk)
 	walk->data = crypto_kmap(walk->pg, 0);
 	walk->data += offset;

-	if (offset & alignmask)
-		nbytes = alignmask + 1 - (offset & alignmask);
+	if (offset & alignmask) {
+		unsigned int unaligned = alignmask + 1 - (offset & alignmask);
+		if (nbytes > unaligned)
+			nbytes = unaligned;
+	}

 	walk->entrylen -= nbytes;
 	return nbytes;
-- 
1.5.5.6

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

end of thread, other threads:[~2010-08-06  1:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-02 12:45 [PATCH] crypto: hash - Fix handling of small unaligned buffers Szilveszter Ördög
2010-08-04 13:48 ` Herbert Xu
2010-08-04 20:59   ` David Miller
  -- strict thread matches above, loose matches on Subject: below --
2010-08-05 10:05 Szilveszter Ördög
2010-08-06  1:27 ` Herbert Xu
2010-06-16 10:28 Szilveszter Ördög

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.