mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] crypto: vmac: fix misaligned pointer handling in vmac_update
@ 2024-12-26 13:48 Atharva Tiwari
  2024-12-26 14:07 ` Herbert Xu
  0 siblings, 1 reply; 2+ messages in thread
From: Atharva Tiwari @ 2024-12-26 13:48 UTC (permalink / raw)
  Cc: evepolonium, Herbert Xu, David S. Miller, linux-crypto, linux-kernel

Handle pontential misalignment of the input pointer(p) in vmac_update
by copying the data to a temp buffer before processing.

Signed-off-by: Atharva Tiwari <evepolonium@gmail.com>
---
 crypto/vmac.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/crypto/vmac.c b/crypto/vmac.c
index 2ea384645ecf..8383a98ad778 100644
--- a/crypto/vmac.c
+++ b/crypto/vmac.c
@@ -518,9 +518,19 @@ static int vmac_update(struct shash_desc *desc, const u8 *p, unsigned int len)
 
 	if (len >= VMAC_NHBYTES) {
 		n = round_down(len, VMAC_NHBYTES);
-		/* TODO: 'p' may be misaligned here */
-		vhash_blocks(tctx, dctx, (const __le64 *)p, n / VMAC_NHBYTES);
-		p += n;
+		if (!IS_ALIGNED((unsigned long)p, sizeof(__le64))) {
+			/* handle misallignment by copying data to ta temporary buffer */
+			u8 temp_buf[VMAC_NHBYTES];
+			const u8 *end = p + n;
+			while (p < end) {
+				memcpy(temp_buf, p, VMAC_NHBYTES);
+				vhash_blocks(tctx, dctx, (const __le64 *)temp_buf, 1);
+				p += VMAC_NHBYTES;
+			}
+		} else {
+			vhash_blocks(tctx, dctx, (const __le64 *)p, n / VMAC_NHBYTES);
+			p += n;
+		}
 		len -= n;
 	}
 
-- 
2.39.5


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

* Re: [PATCH] crypto: vmac: fix misaligned pointer handling in vmac_update
  2024-12-26 13:48 [PATCH] crypto: vmac: fix misaligned pointer handling in vmac_update Atharva Tiwari
@ 2024-12-26 14:07 ` Herbert Xu
  0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2024-12-26 14:07 UTC (permalink / raw)
  To: Atharva Tiwari; +Cc: David S. Miller, linux-crypto, linux-kernel, Eric Biggers

On Thu, Dec 26, 2024 at 07:18:47PM +0530, Atharva Tiwari wrote:
> Handle pontential misalignment of the input pointer(p) in vmac_update
> by copying the data to a temp buffer before processing.
> 
> Signed-off-by: Atharva Tiwari <evepolonium@gmail.com>
> ---
>  crypto/vmac.c | 16 +++++++++++++---
>  1 file changed, 13 insertions(+), 3 deletions(-)
> 
> diff --git a/crypto/vmac.c b/crypto/vmac.c
> index 2ea384645ecf..8383a98ad778 100644
> --- a/crypto/vmac.c
> +++ b/crypto/vmac.c
> @@ -518,9 +518,19 @@ static int vmac_update(struct shash_desc *desc, const u8 *p, unsigned int len)
>  
>  	if (len >= VMAC_NHBYTES) {
>  		n = round_down(len, VMAC_NHBYTES);
> -		/* TODO: 'p' may be misaligned here */
> -		vhash_blocks(tctx, dctx, (const __le64 *)p, n / VMAC_NHBYTES);
> -		p += n;

Please use the get_unaligned_le64 helper instead of copying.

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] 2+ messages in thread

end of thread, other threads:[~2024-12-26 14:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-26 13:48 [PATCH] crypto: vmac: fix misaligned pointer handling in vmac_update Atharva Tiwari
2024-12-26 14:07 ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®