crypto: vmac - Handle unaligned input in vmac_update
PATCH 1/1 crypto: vmac - Handle unaligned input in 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.
--- crypto/vmac.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
crypto/vmac.c +13 -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; +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; }
Signature · 1 line
2.39.5
Quoted 5 lines · Atharva Tiwari
The
vmac_updatefunction previously assumed thatpwas aligned, which could lead to misaligned memory accesses when processing blocks. This patch resolves the issue by,
introducing a temporary buffer to ensure alignment.
Quoted 7 lines
Changes include:
- Allocating a temporary buffer (__le64 *data) to store aligned blocks.
- Usingget_unaligned_le64to safely read data into the temporary buffer.
- Iteratively processing blocks with thevhash_blocksfunction.
- Properly freeing the allocated temporary buffer after processing.Signed-off-by Atharva Tiwari <[email protected]>
Are you using vmac for something? As far as I know it is unused upstream, and we should just remove it instead.
- Eric
Quoted 12 lines · Eric Biggers
Quoted 11 lines · Atharva Tiwari
The
vmac_updatefunction previously assumed thatpwas 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.
- Usingget_unaligned_le64to safely read data into the temporary buffer.
- Iteratively processing blocks with thevhash_blocksfunction.
- Properly freeing the allocated temporary buffer after processing.
Quoted 5 lines
Quoted 1 line
Signed-off-by Atharva Tiwari <[email protected]>Are you using vmac for something? As far as I know it is unused upstream, and we should just remove it instead.
I strongly suspect this was just to address the TODO in the source code, and this would be a good time to finally remove vmac
(https://lore.kernel.org/linux-crypto/[email protected])
from the kernel's museum of cryptographic algorithms. But let me know if you're in fact actually using it, and if so for what. Thanks!
- Eric
Herbert Xu
maintainerQuoted 25 lines · Atharva Tiwari
The
vmac_updatefunction previously assumed thatpwas 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.
- Usingget_unaligned_le64to safely read data into the temporary buffer.
- Iteratively processing blocks with thevhash_blocksfunction.
- Properly freeing the allocated temporary buffer after processing.Signed-off-by Atharva Tiwari <[email protected]>--- crypto/vmac.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)crypto/vmac.c +0
-1@@ -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 */
crypto/vmac.c static int vmac_update(struct shash_desc *desc, const u8 *p, unsigned int len) · line 528
Quoted 10 lines
crypto/vmac.c +8
-2-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)); + }
This is not what I meant by using get_unaligned_le64. I meant replacing the actual 64-bit accesses within vhash_blocks with get_unaligned_le64.
Cheers,
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