Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: Jack Wallner <jackwallner@gmail.com>
To: Kees Cook <kees@kernel.org>
Cc: linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Herbert Xu" <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	linux-crypto@vger.kernel.org,
	"Srujana Challa" <schalla@marvell.com>,
	"Bharat Bhushan" <bbhushan2@marvell.com>,
	"Manivannan Sadhasivam" <mani@kernel.org>,
	"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
	"Kishon Vijay Abraham I" <kishon@kernel.org>,
	"Frank Li" <Frank.Li@kernel.org>, "Arnd Bergmann" <arnd@arndb.de>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	linux-pci@vger.kernel.org,
	"Ajit Khaparde" <ajit.khaparde@broadcom.com>,
	"Sriharsha Basavapatna" <sriharsha.basavapatna@broadcom.com>,
	"Andrew Lunn" <andrew+netdev@lunn.ch>,
	"Eric Dumazet" <edumazet@kernel.org>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	netdev@vger.kernel.org, "Sunil Goutham" <sgoutham@marvell.com>,
	"Geetha sowjanya" <gakula@marvell.com>,
	"Ratheesh Kannoth" <rkannoth@marvell.com>,
	"Subbaraya Sundeep" <sbhatta@marvell.com>,
	"Ketan Mukadam" <ketan.mukadam@broadcom.com>,
	"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
	"Martin K. Petersen" <mkp@kernel.org>,
	linux-scsi@vger.kernel.org, "Andy Lutomirski" <luto@kernel.org>,
	"Thomas Gleixner" <tglx@kernel.org>,
	"Vincenzo Frascino" <vincenzo.frascino@arm.com>
Subject: [PATCH 0/8] Preserve object size through PTR_ALIGN()
Date: Sun, 29 Nov 2026 00:56:02 -0800	[thread overview]
Message-ID: <20261129085612.22266-1-jackwallner@gmail.com> (raw)

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


             reply	other threads:[~2026-11-29  8:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29  8:56 Jack Wallner [this message]
2026-11-29  8:56 ` [PATCH 6/8] scsi: be2iscsi: Use ALIGN() on a DMA address Jack Wallner

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=20261129085612.22266-1-jackwallner@gmail.com \
    --to=jackwallner@gmail.com \
    --cc=Frank.Li@kernel.org \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=ajit.khaparde@broadcom.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=arnd@arndb.de \
    --cc=bbhushan2@marvell.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=gakula@marvell.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=kees@kernel.org \
    --cc=ketan.mukadam@broadcom.com \
    --cc=kishon@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kwilczynski@kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mani@kernel.org \
    --cc=mkp@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rkannoth@marvell.com \
    --cc=sbhatta@marvell.com \
    --cc=schalla@marvell.com \
    --cc=sgoutham@marvell.com \
    --cc=sriharsha.basavapatna@broadcom.com \
    --cc=tglx@kernel.org \
    --cc=vincenzo.frascino@arm.com \
    /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