Re: [PATCH 1/8] crypto: gcm, ccm - Derive the rfc4106/rfc4309 IV from the request context
From: Herbert Xu
Date: Fri Dec 04 2026 - 00:50:31 EST
Jack Wallner <jackwallner@xxxxxxxxx> wrote:
> 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(-)
Acked-by: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
--
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt