From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.179 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795942591; b=ugwKn1RWfGDQ9W4jGDaMORlRK2QdyoaZLLTNYgJsyRYDwt77DIPgRQPoQGXnIvCcLUgZ zdQbZLpIOdhI5GUvCumBIQy6btpGkDqA141PBw10myFXC4HuOjtPWC3Mewm3qfh56AYjO QIgvWKtLrdFc+u4Q4F7iDRVMK4b75BtkO6/K6XciKrt9dJZSEF7RYjR+LxRFtcoV96TY8 rrxoLvfW4QZST+6RMntnGFpdzOfdddjT7RolwmSafnYgeyVN3LXoVEHvaN58P5ZsSWCSG bPTbtMBdN2eRU0nRpVwbmPWIY1wQPxKl7Vp6dg6b4l7RYSQ5bBN/FZLhU/U/6QcVeAQ== 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=QXQ+IU3y6r4Td2ZQoCp1f2MIH0J36PmqnucOTJn4pGQi4iFNrZzz9oc2xR6+qrYChJdq 53H6d34ynrxqQbrbzMOmLm/iGMqEV9p/SLMKB6m5uc9ycbKYKHO5ETdNeiUPRo3jH/yXe 7o5DilaWptb454to0UnxGjD31m+E412ii7h/DQd7HDwWtDvv7UGYULD0IUt6q3/6Slflk dIb5oHP5HAQYjMU8Grel1OPIle3ZB3mnjGDom+beIXVWjKsH9VB1zIn5TIcB9Ohvtau5Z 4tYbxdAv/UayHOjFLDaH435KQpMdzLg67Tt6Yi/Xc7dPmImP/qafnEasKidgUcM8KTg== 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.179 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (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 EF43C606A685 for ; Sun, 29 Nov 2026 08:56:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EF43C606A685 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-f179.google.com with SMTP id d2e1a72fcca58-8b3577deeb0so4193841b3a.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=Sm9KcOSBect+DjKZSpo32HTkzg80GoGrVHJllhganbjP9TIx4taw/USdwIP3cLggKE ko2KvhaP5BaKD59L9ASqkG5fXEL1BVNV7oiOk2PaMXfhJjLAkOBMQVoJWpPVpKAZpi5U Y/u4+mKFOmbQJEbxjSwMrv81WT8Y+ATfEU8PuCZQwxO+/YzKi3aQTzMYIC9gNM4n6gJn do/fauwAo8N4O9qEMNaINUcSa6xoaKSowm3rMrdtTrbgad9Pb/AlZS+P6JhiiIeB9Y77 W6nheWLfm4v9wnkBhih0uNoKeBWq37lGMKko7SYQlEszPMxyzCNNxP3wdiZ2OGugREbv UfDQ== X-Forwarded-Encrypted: i=1; AL+hErF65ZTJZxmrxniJj8cy4vboC2zqDoIJxwiGRg/1E20oIQVWOe7yLyGimmo9P3h4btRJVkczgKxgpJoJNpQ=@vger.kernel.org X-Gm-Message-State: APuU4Z/PcDMzQSwlzuxVh/G+GuhOgpJ8VyjlK6TG/PqMcExHpcWs16x2 aAjhI0/eEmkU7X84eF9bFOG3EgLjaS/JH+b0ej7lk0jmxZABqkwC/crj X-Gm-Gg: AZFdTZcXYk7gOeKw75D8j8B2Q1eUa3jzh1vOngE4KuzKr5ANSlSszD5Si7HpfTVb1AM URkgXK/RugKmwhv9B3ML8x9lGU0ShxwET3EHsPLvEl1nAzCtF4RwirEf2KlKFKusoCiX79U2Bnb dOtQZSi5MmM2eKslnLx+DYVzVlWtIyVHQbbxqVSGUerb6ZxFm011DzlYGKK2WWU5jqVzWO9S6UI uqveFBeWv42DO2CoNTvR4Uo1jdCycATkxPOb1lH5Tq/oHaHkX7hJV7C8tD30tnVNyx9O6e4k949 YZZDaFNu6Nd3Rv8/i/YwpDMbJjC3sTVQq+vyzGDHD+uKrW8DE3AHh/jS1D7oGaX5iYcz2go0fMJ GISiG80hRrPhzdlgvQ7FB4kXWSXZH57KPXrwvEwuIGkE+2vRgje3sjDJ4cGZhBVv/tN6Ce3VDhl LcdIw7RrRrv3wEdHKYEg9LSFbP47mdjipza+eDTVLmQm/vx+NXcEXvwpzQwK2UUoaLH0X2nLNz5 b/F4rvN1qRjtaSi3B4yClmPH3Uk6g4StDNXUkoydgD3nYX9BAlQxdQuFjQUOWSsOqZg7S8EijJa B/o9dWuHq6ADp0bfBwuH+duO+MXYXY18Z2AqWuyJbddCvOuJTE+aOKhQnI/QO4TakvXZYTIqcDy 7nH8DgEZ+VDPhdpt8tu6a4EdI+Qqhv6RI+9cBjrait6g6P14lQVs+ucbjUjf/d5AfpOaz7e1ik3 VhFYBf 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-kernel@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