Re: [PATCH v3 2/2] crypto: caam - Use bounce buffer for unaligned RSA destination buffers

From: Changwei Zou

Date: Wed Nov 11 2026 - 14:28:02 EST


Hi Herbert,

Thanks a lot.
This is a valid finding, I'll fix it in v4.

> rsa_edesc_alloc() allocates req_ctx->bounce_buf with size
> ALIGN(req->dst_len, dma_get_cache_alignment()), but initializes the
> bounce scatterlist entry via sg_init_one(&req_ctx->dst,
> req_ctx->bounce_buf, req->dst_len) with the unaligned req->dst_len.

Correct. The bounce buffer is allocated with the aligned size, but the SG
is described with the possibly-unaligned req->dst_len.

So the fix is to describe the SG with the aligned allocation size:

unsigned int bounce_len =
ALIGN(req->dst_len, dma_get_cache_alignment());

req_ctx->bounce_buf = kzalloc(bounce_len, flags);
if (!req_ctx->bounce_buf)
return ERR_PTR(-ENOMEM);
sg_init_one(&req_ctx->dst, req_ctx->bounce_buf, bounce_len);

My own test case (loading signed kernel modules) used req->dst_len = 512
bytes, which is already cacheline-aligned, so this unaligned-length path
was not exercised and the issue was missed.

Kind regards,
Changwei