From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.175 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795942591; b=W+kNYuEymTbKt9TqHQVdVFINIK4hkpkcKZ5B5/yM0Dmpctb0NkLd2BcVZDdK5QKidW1n fN3PQl7XYKIwAXOqrf1s7CGiLZz/ovm83MeLuvnULckrYcwKDtp3jYO2hMJhSHu9kmpjP /0TIykMngFvr1CrtWm5YME0g9mILJPqSXNk9HY4Rnwtlrd51rbHWua/EFNakTyiWM3RuZ No3hF4p/bVwNGsmAnMXXfyP8odtCS18EHPNGnmMkn5a+eEgD8+InefykXCy5ZNCs3WdXS pQ6lBIq9mh/9uP/b+TQ1+Ekp74qGm20RCYua6GNZNjrqJEA8DGq3IP6bBuB08VlWQyg== 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-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=ZEt/TiNJ/cCWt7RIbo+FXCI/eU3xN/OikKpMxS3zkGaGL3/n3Q4kdEQFXcEhX8myL1kC QLfJUCJOcStcjfkSkZsms13hfQD0IIm0Ly8Op6u1EqvK66eTU50/c5eO+rTcVK7EsxHVB yjjYjLZ9mQS72PtdHZSaj9+qQVaFoLzvwtUzbfR0xW74aAZrp1aTIV97VSsAq3VOfKf+D Su8MfQNt6yRfiMJUqTdT2URH1m/iklwPRJQp+AWn5pUUyQ2PDG+uMjYMs82VGb1MTgbi7 VSruIaNUpOAWaq99Iqbz63tSd1Y6r9ukLlbW0iwznaG+1jjV4kAXtDfOrHl50aiMxsw== 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.214.175 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 E608D606A683 for ; Sun, 29 Nov 2026 08:56:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E608D606A683 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-pl1-f175.google.com with SMTP id d9443c01a7336-2f0426a65e0so55232285ad.3 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=0miMCfzGC0tGx/B7yB0QqqmvN0iRbGNsBLYTb6C7kdcfVCRdfpzuBtAmceiQ0BwWem gcrk4+xOaB+EETJ4c3DAcYvtaJ20XMaEHzFMrsR4bl2x7hXejxjYX3HK6hAyQNp3MqUE yGWODcetiLVuHAYCajpq8hmyFZ7M5v5dfSUuFSkb5AcA68Uvw7XTqAd0HrKwePHb+3GS +KT8/u90/4GJILAN22A2NcImoScpheEaqeLznzV4w80dcrg/8oRREcAJjsurAObTtNic lrn9DWx5hA6xm+LT2ibkHlASdVJ3tCvmCY2wI2ZPgOSbUoRQ1QVvJrN/bMPEFNCWhtsa 3wTw== X-Gm-Message-State: APuU4Z/owZ+Jddd2JgP2+Dmh6sAh7ihB9vT76yI4GohKB5Uuq+ZWQ4od STXgUrLlaf+IWMOw9Jg7DZ9PBUu4vXkIWrmzQj7FQqV6dlWAja9xIYaj X-Gm-Gg: AZFdTZd+h3+DSw9DnSfm4e+ojNusewEZs4V/qLKFqgT3ccldojLSnvEb0sOTe7cr4Zc sRweJX/WffXWIP6Ju6yUnbR5BCDbxhRx7f8c0H9URaeoOcBKzbaO9qvE8H4qiilodKnFjKqRAKQ aWTpd/GIjYxuQOFYtx5xh55vwE45FhiRvT5wDB0wtvPH6mIgN+Yiyf5fhRYeSRBTR/Fyk2j7fxQ K3g4R6Ae6B+56przP1y6k0SBGcJO9svcuG3pB69voka5vXByA6yVm/ABCyMOd/fy4Rg/G4UUAg8 rT3RkWE/xGDSqjBx6thtgzXOPfz8doIYufsRHX2ABqYRB37Xbv8B+BxBlmOp6kMXoh5N3saqvkL jW/QEIKHhYZvUTRT6yw6ZKyLwTLCpggPwPPv9kaX4pWjvuF8orpDeeD23JhPVtOuQKFFLjUw4pN Gr5Xy9fsDLSulOGTtNUf7ntITkfDU5Mv14saymU5usv34QYFFEgxL6WCjgrZqVrc6rWqCOgmClC 43x4QKL+u4O72hnj17Qe6xI/qq85OSLVjxm7Obgjl0dG+e7PmyrEQ/pH6jFjLSxthGoCLq+WPOm KxKSCFu7q9RREMdR+6JaxO8PV6PhTbEuuDSHm8W06jJomY6HJMvD4cJxYo44TqfqLFJaPYnvF5D R4mzLOh8uiirLnv88kuN1b87dqq5Ko/h9B2ymVdYSYPh6dE3JRmY9OeBA5i2N8ezswmkWsQMEYJ Gq+Ahc 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-hardening@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