Skip to contentSkip to conversation

crypto: vmac: fix misaligned pointer handling in vmac_update

PATCH In review Atharva Tiwari 2 participants 2 messages Dec 26, 2024 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: vmac: fix misaligned pointer handling in vmac_update

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

---
 crypto/vmac.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
crypto/vmac.c +13 -3
index 2ea384645ecf..8383a98ad778 100644
@@ -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;
 	}
 
Signature · 1 line
2.39.5
maintainer
#1 lore raw
Quoted 13 lines · Atharva Tiwari

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

---
 crypto/vmac.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
crypto/vmac.c +0 -0
index 2ea384645ecf..8383a98ad778 100644

crypto/vmac.c static int vmac_update(struct shash_desc *desc, const u8 *p, unsigned int len) · line 523

Quoted 6 lines
crypto/vmac.c +0 -3
@@ -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,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt