[PATCH 1/8] crypto: gcm, ccm - Derive the rfc4106/rfc4309 IV from the request context
From: Jack Wallner
Date: Sun Nov 29 2026 - 03:56:47 EST
crypto_rfc4106_crypt() and crypto_rfc4309_crypt() keep the IV for the
child request in the space that follows the child's request context.
They find that space by starting from "subreq + 1", where subreq points
to the subreq member of the request context structure.
"subreq + 1" is one past the end of that member, so as far as the
compiler can tell, everything stored through a pointer derived from it
lies outside the member: with GCC,
__builtin_dynamic_object_size(iv, 1) is 0. The memcpy() calls that fill
in the IV are spared a FORTIFY_SOURCE "field-spanning write" warning
only because PTR_ALIGN() casts the pointer to an integer and back, which
makes the compiler forget where it came from.
A later patch in this series makes PTR_ALIGN() keep the object size.
With it, a kernel built with GCC 13.3 reports this from the crypto
self-tests, which is how I found these two callers:
memcpy: detected field-spanning write (size 4) of single field "iv" at crypto/gcm.c:483 (size 0)
memcpy: detected field-spanning write (size 8) of single field "iv + 4" at crypto/gcm.c:484 (size 0)
Start from "rctx + 1" instead, as crypto_rfc4543_crypt() in gcm.c already
does. crypto_rfc4106_init_tfm() and crypto_rfc4309_init_tfm() size the
request from sizeof() of the request context structure, so "rctx + 1"
is also the address that calculation is based on. subreq is the last
member of both structures and nothing follows it, so the address does
not change. I checked that with a temporary build-time assertion of
sizeof() against offsetofend() of subreq, on x86-64, i386, arm, arm64,
riscv and powerpc.
No functional change. With this patch and the PTR_ALIGN() one applied,
the self-tests run without the warning. Nothing in my test boot
instantiates rfc4309, so for ccm.c I have no runtime report, only the
same construct and the same compile-time finding.
The change and this changelog were written by an AI coding assistant
(Claude, run in Claude Code) at my direction. See the cover letter for
how it was used and tested.
Signed-off-by: Jack Wallner <jackwallner@xxxxxxxxx>
---
crypto/ccm.c | 2 +-
crypto/gcm.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/crypto/ccm.c b/crypto/ccm.c
index 916441e4f..f03629982 100644
--- a/crypto/ccm.c
+++ b/crypto/ccm.c
@@ -603,7 +603,7 @@ static struct aead_request *crypto_rfc4309_crypt(struct aead_request *req)
struct crypto_rfc4309_ctx *ctx = crypto_aead_ctx(aead);
struct crypto_aead *child = ctx->child;
struct scatterlist *sg;
- u8 *iv = PTR_ALIGN((u8 *)(subreq + 1) + crypto_aead_reqsize(child),
+ u8 *iv = PTR_ALIGN((u8 *)(rctx + 1) + crypto_aead_reqsize(child),
crypto_aead_alignmask(child) + 1);
/* L' */
diff --git a/crypto/gcm.c b/crypto/gcm.c
index 5f16b237b..4ec24ff27 100644
--- a/crypto/gcm.c
+++ b/crypto/gcm.c
@@ -475,7 +475,7 @@ static struct aead_request *crypto_rfc4106_crypt(struct aead_request *req)
struct aead_request *subreq = &rctx->subreq;
struct crypto_aead *child = ctx->child;
struct scatterlist *sg;
- u8 *iv = PTR_ALIGN((u8 *)(subreq + 1) + crypto_aead_reqsize(child),
+ u8 *iv = PTR_ALIGN((u8 *)(rctx + 1) + crypto_aead_reqsize(child),
crypto_aead_alignmask(child) + 1);
scatterwalk_map_and_copy(iv + GCM_AES_IV_SIZE, req->src, 0, req->assoclen - 8, 0);
--
2.43.0