lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20241226161456.191215-1-evepolonium@gmail.com>
Date: Thu, 26 Dec 2024 21:44:56 +0530
From: Atharva Tiwari <evepolonium@...il.com>
To: 
Cc: evepolonium@...il.com,
	Herbert Xu <herbert@...dor.apana.org.au>,
	"David S. Miller" <davem@...emloft.net>,
	linux-crypto@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: [PATCH] crypto: vmac - Fix misalignment issue during vmac_update

The `vmac_update` function previously assumed that `p` was aligned,
which could lead to misaligned memory accesses when processing blocks.
This patch resolves the issue by, 
introducing a temporary buffer to ensure alignment.

Changes include:
- Allocating a temporary buffer (`__le64 *data`) to store aligned blocks.
- Using `get_unaligned_le64` to safely read data into the temporary buffer.
- Iteratively processing blocks with the `vhash_blocks` function.
- Properly freeing the allocated temporary buffer after processing.

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

diff --git a/crypto/vmac.c b/crypto/vmac.c
index 2ea384645ecf..513fbd5bc581 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;
+		const u8 *end = p + n;
+		const uint16_t num_blocks = VMAC_NHBYTES/sizeof(__le64);
+		__le64 *data = kmalloc(num_blocks * sizeof(__le64), GFP_KERNEL);
+
+		while (p < end) {
+			for (unsigned short i = 0; i < num_blocks; i++) {
+				data[i] = get_unaligned_le64(p + i * sizeof(__le64));
+			}
+
+			vhash_blocks(tctx, dctx, data, 1);
+			p += VMAC_NHBYTES;
+		}
+		kfree(data);
 		len -= n;
 	}
 
-- 
2.39.5


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ