Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: Jack Wallner <jackwallner@gmail.com>
Cc: kees@kernel.org, linux-hardening@vger.kernel.org,
	linux-kernel@vger.kernel.org, davem@davemloft.net,
	linux-crypto@vger.kernel.org
Subject: Re: [PATCH 1/8] crypto: gcm, ccm - Derive the rfc4106/rfc4309 IV from the request context
Date: Fri, 4 Dec 2026 13:50:19 +0800	[thread overview]
Message-ID: <axJUm6FG_lJS4voP@gondor.apana.org.au> (raw)
In-Reply-To: <20261129085612.22266-2-jackwallner@gmail.com>

Jack Wallner <jackwallner@gmail.com> 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@gmail.com>
> ---
> crypto/ccm.c | 2 +-
> crypto/gcm.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)

Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

  reply	other threads:[~2026-12-04  5:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29  8:56 [PATCH 0/8] Preserve object size through PTR_ALIGN() Jack Wallner
2026-11-29  8:56 ` [PATCH 1/8] crypto: gcm, ccm - Derive the rfc4106/rfc4309 IV from the request context Jack Wallner
2026-12-04  5:50   ` Herbert Xu [this message]
2026-11-29  8:56 ` [PATCH 2/8] crypto: nitrox, octeontx, octeontx2 - Use ALIGN() on DMA addresses Jack Wallner
2026-12-04  5:50   ` 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=axJUm6FG_lJS4voP@gondor.apana.org.au \
    --to=herbert@gondor.apana.org.au \
    --cc=davem@davemloft.net \
    --cc=jackwallner@gmail.com \
    --cc=kees@kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-hardening@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