From: Atharva Tiwari <evepolonium@gmail.com>
Cc: evepolonium@gmail.com, Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] crypto: vmac: fix misaligned pointer handling in vmac_update
Date: Thu, 26 Dec 2024 19:18:47 +0530 [thread overview]
Message-ID: <20241226134847.6690-1-evepolonium@gmail.com> (raw)
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
next reply other threads:[~2024-12-26 13:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-26 13:48 Atharva Tiwari [this message]
2024-12-26 14:07 ` Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241226134847.6690-1-evepolonium@gmail.com \
--to=evepolonium@gmail.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®