From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.176 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795942590; b=l1baYhwQV5/ZoUH2etkZyqq4z3o4p39CoyyIpL1B9SzaDgZEJ7c75qrN3EwpZMfggJ/y scIOPqTnhDeER5j79sjUrDI1TEv0zVQwibUh1ysCGkwKihKXbfB1MhabLrkaaicSv/C7J MYNdKrP1KajgJ231zEckfdz3kAVRLAhh+7/bipHO9OMT+syrUtTSki0T6dnL0cWMGRJzz LUl8F00UVKHHEVIdpgd5IoyDYbDp9fn9gA7tLYJvZ7yXnN+GZ+Zqal/lPnJoRossnytVl gNUrXg+Nm67ut7N40SUJtdUopdR5M5T887cBlLPRk0ZcN3HDXJu6s+v4poK1Fv7cW0Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795942590; 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:MIME-Version: Content-Transfer-Encoding; bh=nQOUOJrHqF0g/nQBtE9Zszixd53GFW85GTOtEczYuco=; b=JTGPrzC6UafeLqgQTZv51uBJKRcgcgE9RHTUrKFfSslyCKjJEDc8KG0QDH7eTRqY0lnt YmPMM59z0/I5y/8vYOH5YqByafiHVm7VO5Abn0SAYGOaf5PGLgGXom5nsmakJAbXXWgbV 6S4c6PYkM6Grn6eHKbJiDz7aZVJV+6MFRD8457bpKCRvgWHjtnvbIAPDpM3GZLukXsvOi 30qjlLf9OlzLnO4FkUjxj383saVQ8//kqEGERKDcDZPgfkixKBz4SptxDPrgaj9sx5Qd+ UW9yxGShrqco2jtYT8hIwaWXBooEW9r6PSHKV10CQ+m8pLSpFVkZsx+UM1EXdg9rX6A== 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="JLPN/nWP"; arc=none smtp.remote-ip=209.85.214.176 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 818A5606A327 for ; Sun, 29 Nov 2026 08:56:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 818A5606A327 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=JLPN/nWP Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2f01f296937so69924775ad.3 for ; Sun, 29 Nov 2026 00:56:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795942589; x=1796547389; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=nQOUOJrHqF0g/nQBtE9Zszixd53GFW85GTOtEczYuco=; b=JLPN/nWPXdWDWsPWKzjyrue9UzLSwl27HltDSu7lqSS0sgLpg56VT7oXEuW2vjrR+C r+iwwSNJM9LHJLHlaNH5bqnBECPexzvJBxnDoHyqblFIuWggPgx4FrnanLjsM7lcvnFG 6aDEG9YzGCSC3UfJtIznfeBbi4sC3rcD1OfLnuKC4vhMngaK8T3D+KFiY+LUpsKYi3CW K3MxAZVkRJTC+lt5yAVHWNNhjYfAb4sO9mrsZ75vCDmhRcnP5Lse2jVPHX2BE8nXQ2i3 F7n97WRHqLh5Zl/Ba2Jto4Lu3hANsf1Rde0PujxZxk/PBV+RIpG5s9+Z/7L6iWXVNIuh +YYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795942589; x=1796547389; h=content-transfer-encoding:mime-version: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=nQOUOJrHqF0g/nQBtE9Zszixd53GFW85GTOtEczYuco=; b=dLepEzEsBmcapqtTe21dZXSy4GkMaLQ0dGoKXUFywaaAGyar6TybSEvmzGx3xLqzKf 3jG9mvO/dM+vAXJF2X4tV6rEaw5uqWc6M6GwLzkDQTLCTvaVim6lLzw7IhSjPJFbNt4k E0OzWYyZMjPjuv794U5PPww/VJa4xQ5ASnNAKILhNi/ydIbcShz0C7f1Zab7xkiyPD/R nIvRCkB3axYarW0zt//7HgBIavseBppPBu8+GxNWXZZOjaWzs2z8MWzFUOVKI3KfCyJU KufL2ALIjJBncejkpSdxzD1BTgZI6VDfhU3oPO8ey8HtOCsKldPsLGRSwBfSWqPRg9b7 EEzQ== X-Forwarded-Encrypted: i=1; AL+hErE11oSnLOfSnZxGxUypAXeFDqv0ejyYtScfKKXXoNOihLmX5Lwph3FuI2921bD2Uf8q5li6GiJw3hY=@vger.kernel.org X-Gm-Message-State: APuU4Z/kHgPNsW7uyzSKkT7gYrWrqtP4CIDUEYOlbqALd87xuqzJg/RQ DUnG96RG/ks5DwX2+O8dnXyazEc9tmeMoSrGJ/d0625n5+Q4dZEDYuph X-Gm-Gg: AZFdTZe765XGQbMGEwfXe/h03IexXfL9XQJLQ7v/gvxBRD1f7FdJe24NiZNT/CiJdnq cqewU2sbaL/9Qt/1IkIKUxRwvQf2vki5Oh1e9DqASB/6QNpI/cOtaL65mHDNL8N9+28EEojGIRp e1gQbzLnA5JBnXy1m6ljwVIzQK/as0SwiXgYDD9aRsM6+oCAe/rXxyLOEwbYpv0DMqpCRvoGFA8 vjOhK1KjqqhqVzqoAQVILkf3TQRa2y+quKK4EwVmCNsVLp1Lp2FezOGgUCoK4QLf0ZsWbgy0PHr 7sif9NU4oSeCZl8eO9UEL+1elYN33Fc2qhZNH7UR+IlkiPX4Kq03vrdFS4uMeGpleWgMOprLDbn QtrqIm4CUqiMUgryx7EiEYuGkvzqPSh4i/0olTS645sedK/EnG/wLDQOvg0DwJSS8FG4RwfIjsJ gFDrGST5zJ5kMjM8WS1Xyun7/Ox3G/95HZeSVrCNX5Api+cCoYHw7F2s4B3fDWSq8KJauk19HQz DF9dqSDqVah7fPU8aHPVx9smbSzBixinGE8rUFqzVJy6DCFF+WcyLzid28RJoRZN/xdRYv58t54 pQCQVg6Hgs67bb/nPDg9lOfWUfc/1sc5aUWaMcgGVYgPgduAH+9qGDx5WyY8p0Ai4KlatBYfOCa m8S0pIOmx1bEJfMjlMBfUsCgQCnf9y/1pEvPvlP4JB/LT9/2qyVRShgCEtkH82Xb9xmSvYmDorY 71zqLi X-Received: by 2002:a17:902:e88e:b0:2f0:4f8d:377a with SMTP id d9443c01a7336-2f04f8d38d3mr290354535ad.34.1795942588601; Sun, 29 Nov 2026 00:56:28 -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.24 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 29 Nov 2026 00:56:27 -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, Srujana Challa , Bharat Bhushan , Manivannan Sadhasivam , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Frank Li , Arnd Bergmann , Greg Kroah-Hartman , linux-pci@vger.kernel.org, Ajit Khaparde , Sriharsha Basavapatna , Andrew Lunn , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, Sunil Goutham , Geetha sowjanya , Ratheesh Kannoth , Subbaraya Sundeep , Ketan Mukadam , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino Subject: [PATCH 0/8] Preserve object size through PTR_ALIGN() Date: Sun, 29 Nov 2026 00:56:02 -0800 Message-ID: <20261129085612.22266-1-jackwallner@gmail.com> X-Mailer: git-send-email 2.54.0 X-Mailing-List: linux-pci@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 PTR_ALIGN() rounds a pointer up by casting it to unsigned long and back, which makes the compiler lose track of the object the pointer belongs to. __builtin_object_size() and __builtin_dynamic_object_size() then return "unknown" for the result and FORTIFY_SOURCE cannot bound accesses made through it. This is KSPP issue 191: https://github.com/KSPP/linux/issues/191 Patch 7 changes PTR_ALIGN() to add the padding to the original pointer instead, which is the approach the October triage note on that issue suggests. Patch 8 adds a KUnit test. Patches 1 to 6 prepare callers. Patch 1 changes two crypto templates that compute an address starting one past the end of a struct member. That only escaped a FORTIFY warning because of the integer cast in PTR_ALIGN(). Patches 2 to 6 convert the ten callers that pass a dma_addr_t to PTR_ALIGN() over to ALIGN(), one patch per subsystem. Patches 3, 4 and 6 are needed before patch 7: without them it adds cast warnings on 32-bit kernels with a 64-bit dma_addr_t. Patches 2 and 5 are for drivers that depend on 64BIT, where nothing would warn, and are only there so that no caller passes an integer to a macro meant for pointers. PTR_ALIGN_DOWN() is not changed. Its result is often meant to point before the object its argument points into (the start of a page or of a block of page table entries), so it needs its own look at the 25 users. Patch 7 has the details. I do not know which tree this should go through. The driver patches are independent of each other and can be picked up by their maintainers. If it is easier, the whole series could go through the hardening tree with acks. Testing, on mainline at 946d9ed1aa02 (v7.4-rc4 plus a few merges), all with the full series applied unless noted: - lib/tests/fortify_kunit and the crypto self-tests (CRYPTO_SELFTESTS_FULL) under QEMU on x86-64, built with GCC 13.3 and with Clang 18, with and without KASAN: 26 of 26 fortify cases pass and there is no FORTIFY or KASAN report. With the old macro the new test case fails on both compilers and the other 25 pass. Without patch 1 the GCC boot prints the warning quoted in patch 1. - The same boot with Clang 18, UBSAN_BOUNDS and UBSAN_TRAP, which turns on -fsanitize=local-bounds, with and without the series: no trap. - allmodconfig builds with W=1 of the C files that use PTR_ALIGN(), before and after: x86-64 and i386 with GCC, and x86-64, arm64, arm, riscv and powerpc with Clang. No new diagnostics in any file that builds. arch/x86/kernel/unwind_frame.c is not part of that configuration and fails to compile with and without the series. 125 of the 136 files build in at least one of these. Six more build with the series applied on s390, loongarch and mips with Clang, without a diagnostic from the macro. The other five did not build in any configuration I tried. - sparse (built from git) on the callers that align __user and __iomem pointers on x86-64: no new warnings, also with -Wcast-to-as. - The compile-time scan described in patch 7, which is how I looked for callers that would get a new FORTIFY report. Not tested: any of the drivers on real hardware, GCC other than 13.3, Clang other than 18, LTO builds, and sparse on the arm64 __user caller. linux-next has four new PTR_ALIGN() users in lib/crypto/tests/ that the scan did not cover. They align pointers into buffers allocated with room for the padding. Use of AI tools, as Documentation/process/generated-content.rst asks: the code, the test and the changelogs in this series were written by an AI coding assistant (Anthropic's Claude, run in Claude Code). I asked it to pick one open KSPP issue and produce a fix that could be merged, and then had separate Claude sessions review the result with the instruction to find reasons to reject it. Those reviews are where the caller changes in patches 1 to 6, the compile-time scan and the UBSAN boot came from. The assistant also ran every build, boot and scan listed above, on my machines. I have read the series and the test results, and I am responsible for it. Jack Wallner (8): crypto: gcm, ccm - Derive the rfc4106/rfc4309 IV from the request context crypto: nitrox, octeontx, octeontx2 - Use ALIGN() on DMA addresses misc: pci_endpoint_test: Use ALIGN() on DMA addresses be2net: Use ALIGN() on a DMA address octeontx2-pf: Use ALIGN() on a DMA address scsi: be2iscsi: Use ALIGN() on a DMA address vdso/align: Preserve object size through PTR_ALIGN() kunit/fortify: Add PTR_ALIGN() object size test crypto/ccm.c | 2 +- crypto/gcm.c | 2 +- drivers/crypto/cavium/nitrox/nitrox_lib.c | 2 +- .../crypto/marvell/octeontx/otx_cptpf_ucode.c | 2 +- drivers/crypto/marvell/octeontx2/otx2_cptlf.h | 3 +- drivers/misc/pci_endpoint_test.c | 8 +-- drivers/net/ethernet/emulex/benet/be_main.c | 2 +- .../marvell/octeontx2/nic/cn10k_ipsec.c | 2 +- drivers/scsi/be2iscsi/be_main.c | 2 +- include/vdso/align.h | 23 ++++++- lib/tests/fortify_kunit.c | 63 +++++++++++++++++++ 11 files changed, 97 insertions(+), 14 deletions(-) base-commit: 946d9ed1aa021d572467a1cdcdc2991f89b788a1 -- 2.43.0