diff mbox

[2/2] crypto: img-hash - shift wrapping bug in img_hash_hw_init()

Message ID 20150320142144.GB5108@mwanda (mailing list archive)
State Superseded
Delegated to: Herbert Xu
Headers show

Commit Message

Dan Carpenter March 20, 2015, 2:21 p.m. UTC
"hdev->req->nbytes" is an unsigned int so we so we lose the upper 3
bytes to the shift wrap bug.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

James Hartley March 20, 2015, 6:55 p.m. UTC | #1
Hi Dan, 

I'm assuming you mean the upper 3 bits rather than bytes?

Thanks for the patch

James.

> -----Original Message-----
> From: Dan Carpenter [mailto:dan.carpenter@oracle.com]
> Sent: 20 March 2015 14:22
> To: Herbert Xu; James Hartley
> Cc: David S. Miller; linux-crypto@vger.kernel.org; kernel-
> janitors@vger.kernel.org
> Subject: [patch 2/2] crypto: img-hash - shift wrapping bug in
> img_hash_hw_init()
> 
> "hdev->req->nbytes" is an unsigned int so we so we lose the upper 3 bytes to
> the shift wrap bug.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/drivers/crypto/img-hash.c b/drivers/crypto/img-hash.c index
> 601ab35..ad47d0d 100644
> --- a/drivers/crypto/img-hash.c
> +++ b/drivers/crypto/img-hash.c
> @@ -464,7 +464,7 @@ static int img_hash_hw_init(struct img_hash_dev
> *hdev)
>  	img_hash_write(hdev, CR_RESET, CR_RESET_UNSET);
>  	img_hash_write(hdev, CR_INTENAB, CR_INT_NEW_RESULTS_SET);
> 
> -	nbits = (hdev->req->nbytes << 3);
> +	nbits = (u64)hdev->req->nbytes << 3;
>  	u = nbits >> 32;
>  	l = nbits;
>  	img_hash_write(hdev, CR_MESSAGE_LENGTH_H, u);
--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/crypto/img-hash.c b/drivers/crypto/img-hash.c
index 601ab35..ad47d0d 100644
--- a/drivers/crypto/img-hash.c
+++ b/drivers/crypto/img-hash.c
@@ -464,7 +464,7 @@  static int img_hash_hw_init(struct img_hash_dev *hdev)
 	img_hash_write(hdev, CR_RESET, CR_RESET_UNSET);
 	img_hash_write(hdev, CR_INTENAB, CR_INT_NEW_RESULTS_SET);
 
-	nbits = (hdev->req->nbytes << 3);
+	nbits = (u64)hdev->req->nbytes << 3;
 	u = nbits >> 32;
 	l = nbits;
 	img_hash_write(hdev, CR_MESSAGE_LENGTH_H, u);