From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.177 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795942591; b=l84rkcwfFzdZkLAPrSir5YZRs6dLOAcdY6dzAnMcKmWNfNrRrc9qbu7wfuCcoJK8w8sr vV60oAthBp9BwlvT+W06SkAd6SqQmMA/sAIX8I0clm/7DkQdb6iaPidXXDB16D8EjQta3 nl+hfTukw44Vc541CmjYVsjUco9qkQ9Zk8yG9Bq7ounh7bvcDfkuJDDwbGKkxLvIX+O6T 8r2Bs+1YV/E6/eGiesw+M52gq9ePaT/kfhqSOaCRCJAlQHAZ6uxTev8BnX7rsQ9kAsp7l QGAs8XyK/88c59DEuSRyU7OhtKTovDtNRXONJJN+mQu9wX2aVg9xJXUzMD2j2BtaRBA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795942591; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=x8dO00KM7/VbVmy37O7gwS+8P2azZKbQ706owf+hq2Q=; b=Jog4VSXcMjDMchBrkwf4sZMsfc0VtShMZDlPA8shObzIbEKla5KCqBWrvoJEMk7sJ8o+ l+IDCA7uJjbEUg3n7mFXgZfAjKCt53W92gbnmSZjStApf8e8n4rQOyA7gJn7oYIzJuiiU tCKAYxdXbb8vbZaYFsJV3hwsinn5eW6hMW1aN19armnKa5THeyC+RkPuSeR0y/jvA7gJ/ NF80CsmvSJBZXN9VP7dOkY4m3/+NVTegbfQqqvqtWI3CJVsr6gKuTyE/BCS4sOPkTF+aN IV53/8BrQLsjDRYHWV11ad72+Bbxkjwc+W4LS/BYhCzW9t/Sm5FdIiZl46GNY/dFR3g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Ass2bmZE; arc=none smtp.remote-ip=209.85.210.177 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E06F0606A681 for ; Sun, 29 Nov 2026 08:56:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E06F0606A681 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Ass2bmZE Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-8b29b83fdf1so4822510b3a.2 for ; Sun, 29 Nov 2026 00:56:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795942590; x=1796547390; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=x8dO00KM7/VbVmy37O7gwS+8P2azZKbQ706owf+hq2Q=; b=Ass2bmZEfA8BCYvtjKy1Bi6D5/M5veBe4pWlysRGFnxOquQNmiOduNUKvbRCqYPZFz FD3SAb+nQ1o8zGRNQLrPpmdVpi33IeOgfBY0HdtqupzDl1TuCRnIetPIZESz0nFfgJna MfY5qZmzxNmiiLKmRskI0RjfFqlo5XtgPxAal1iCBc27sTB3g9cVCgJBKBdd6pIhVNkI txNom6Q9yAkJm1efZIT8Vg21AlzenEL8RtylqtX3iSZSjT7qr7c44S5l+D1iT6NIMA8C yEgwnI4ivPcc1ecR1rw6HrRH3QQvn2eY/iCoBy3BlCostYxyH9GIIhbDjfshZm2nhUdq ImXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795942590; x=1796547390; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=x8dO00KM7/VbVmy37O7gwS+8P2azZKbQ706owf+hq2Q=; b=Jg8RUiD/fsdC24/ZU8C4NpxEV2f4ATsdDoIx4IvAVmVJ4JsNDMUR1pN9N4ZvP9Besr MCnZGJ01GhYiRRzgipm7ela/TIGuFNW1nLtdX9O5NaDkLl8GhNT4yKzUOvO1IJsm8Qsz dY/N60lD1Oh0Pc92/zRGs8HSmX88HWlu+O8dmcoF8cHb3xjFE0BFjdH/1BiWzSHly3um +0lhfwFnCgkHPiyL4RLCqZeVjatNj38nyy/oQsr9qkbMeshK84nVGQm4s4Rdilu/Edux SDQeJxxyRV4pFd+HILfi4myIHZiKhSUhd/okbgj72piTjo0OZ/eWUh8xM7RGepLoFBZV 4A1w== X-Forwarded-Encrypted: i=1; AL+hErGp9oXiVIhP8YBx6q8myvml3pGYgyUMXpTwIWzxgVS5I102OmQ9mSYP5PfqTV6BB0d4yT1pbNtaz4+kwFw=@vger.kernel.org X-Gm-Message-State: APuU4Z8yKZ4x5zax5EyVaMul7lVHXaq1eGzCMX96GzZy59akUU9K7A0N 1pkdO8Fsl6TqDfYm4cO/nQqjgJodLu9FGVyvyypI09Cz3/+O4cjkWVg3V1y+LDBc X-Gm-Gg: AZFdTZdu/qZo+eDMVFEP+vw59zz2xi8bet1iC0O+OSEk7/vlqANvIQ8YiNKVqmBj5cT 5aCmANrifYtuhq/0cJfJyowYHls7BuquLRtnTRAFfpNE6zGTad8PUnetJIIR6tX84ZUnjDZemSM FsC1qL1cPg7W5vDoNb38uf0bvUBZuQPyeKTB22IoiPDm5G4WOfTjIafalZmrvqHPxJrQM45iU5V bnjFmWgmK5Wrpnp51dDHt4gWXwZt1yIehcXXVLHdCUxV6WZtUW1FU+6MMcqaQ3qndsFPo4NL8hJ YpYst3jMh9qef++9QtWNXiAMwlViBW2p9Z6TBGdzYEiEaevCx3LadDUKhpy/tlfVZfAufkz13r7 y5REw7e1uS4WhzmMjMwZMpnReZSxMZtqYMXq14RQoVXWiyz+M9rRm7h0eiqo+BNo5h2KQnc9l4h Yy4iZc48ezxYnGxAIPBeDbZfcVQDvsaG7ig3FIwg4d1/kbuvVYLGBKhhMqrYhSU711cDd25W0DP 38xa9D08e68G/5VDACxC4KvFAjGT0VKesrlR/Ap1FhU7tzK1Z9hx9iU2xXCB8OTI2fUb2iAXUAG snZ4gm1Vknw40hpQP/B/sxBD3x5ODVW4kFvHOwsGW7jBE4G8dh1n0opQ+lJu3GTupQsmI86ofdh 1nBm3YoLd4vAuJe3Gfo8Cpma87h6TRoIgtd3rJPm6mEIhSwM7npF0rN2ibTC5EUr1f6878MpRQH a63VjI X-Received: by 2002:a17:902:c949:b0:2ef:e0a1:1015 with SMTP id d9443c01a7336-2f121620114mr53624235ad.27.1795942590204; Sun, 29 Nov 2026 00:56:30 -0800 (PST) Received: from localhost.localdomain ([2601:1c2:4100:453:29cf:2f71:51d4:4a57]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f03f0c2091sm144767735ad.20.2026.11.29.00.56.29 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 29 Nov 2026 00:56:29 -0800 (PST) From: Jack Wallner To: Kees Cook Cc: linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, Herbert Xu , "David S. Miller" , linux-crypto@vger.kernel.org Subject: [PATCH 1/8] crypto: gcm, ccm - Derive the rfc4106/rfc4309 IV from the request context Date: Sun, 29 Nov 2026 00:56:03 -0800 Message-ID: <20261129085612.22266-2-jackwallner@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261129085612.22266-1-jackwallner@gmail.com> References: <20261129085612.22266-1-jackwallner@gmail.com> X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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