[PATCH v2 18/30] crypto: sa2ul - handle unaligned IV buffers
From: Manorit Chawdhry
Date: Wed Nov 04 2026 - 00:48:40 EST
Request IV buffers need not be word aligned. Use unaligned accesses
when formatting and returning IV words, preserving their byte order
without risking alignment faults.
Fixes: 7694b6ca649f ("crypto: sa2ul - Add crypto driver")
Fixes: d2c8ac187fc9 ("crypto: sa2ul - Add AEAD algorithm support")
Signed-off-by: Manorit Chawdhry <m-chawdhry@xxxxxx>
---
drivers/crypto/sa2ul.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/drivers/crypto/sa2ul.c b/drivers/crypto/sa2ul.c
index dac0f8a147e2..2c1d51b1cb88 100644
--- a/drivers/crypto/sa2ul.c
+++ b/drivers/crypto/sa2ul.c
@@ -14,6 +14,7 @@
#include <linux/dmapool.h>
#include <linux/kernel.h>
#include <linux/module.h>
+#include <linux/unaligned.h>
#include <linux/of.h>
#include <linux/of_platform.h>
#include <linux/platform_device.h>
@@ -579,11 +580,11 @@ static inline void sa_update_cmdl(struct sa_req *req, u32 *cmdl,
if (likely(upd_info->flags & SA_CMDL_UPD_ENC_IV)) {
__be32 *data = (__be32 *)&cmdl[upd_info->enc_iv.index];
- u32 *enc_iv = (u32 *)req->enc_iv;
+ const u8 *enc_iv = req->enc_iv;
for (j = 0; i < upd_info->enc_iv.size; i += 4, j++) {
- data[j] = cpu_to_be32(*enc_iv);
- enc_iv++;
+ data[j] = cpu_to_be32(get_unaligned((const u32 *)enc_iv));
+ enc_iv += sizeof(u32);
}
}
}
@@ -957,7 +958,7 @@ static void sa_aes_dma_in_callback(void *data)
{
struct sa_rx_data *rxd = data;
struct skcipher_request *req;
- u32 *result;
+ u8 *result;
__be32 *mdptr;
size_t ml, pl;
int i;
@@ -968,10 +969,11 @@ static void sa_aes_dma_in_callback(void *data)
if (req->iv) {
mdptr = (__be32 *)dmaengine_desc_get_metadata_ptr(rxd->tx_in, &pl,
&ml);
- result = (u32 *)req->iv;
+ result = req->iv;
for (i = 0; i < (rxd->enc_iv_size / 4); i++)
- result[i] = be32_to_cpu(mdptr[i + rxd->iv_idx]);
+ put_unaligned(be32_to_cpu(mdptr[i + rxd->iv_idx]),
+ (u32 *)(result + i * sizeof(u32)));
}
sa_free_sa_rx_data(rxd);
--
2.43.0