Skip to contentSkip to conversation

ffs-const update for v6.18-rc1

GIT PULL Merged Kees Cook 2 participants 2 messages Sep 29, 2025 – Sep 30, 2025

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

Hi Linus,

Please pull this ffs() attribute-const update for v6.18-rc1. While working on various hardening refactoring a while back we encountered inconsistencies in the application of __attribute_const__ on the ffs() family of functions. This series fixes this across all archs and adds KUnit tests. Notably, this found a theoretical underflow in PCI (also fixed here) and uncovered an inefficiency in ARC (fixed in the ARC arch PR). I kept the series separate from the general hardening PR since it is a stand-alone "topic".

Thanks!

-Kees

The following changes since commit c17b750b3ad9f45f2b6f7e6f7f4679844244f0b9:

Linux 6.17-rc2 (2025-08-17 15:22:10 -0700)

are available in the Git repository at:

https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git tags/ffs-const-v6.18-rc1

for you to fetch changes up to 95719dfa323709c06ec34cc96e73e0788e19934f:

KUnit: ffs: Validate all the __attribute_const__ annotations (2025-09-08 14:58:52 -0700)

----------------------------------------------------------------
ffs-const update for v6.18-rc1

- PCI: Fix theoretical underflow in use of ffs().

- Universally apply __attribute_const__ to all architecture's ffs()-family of functions.

- Add KUnit tests for ffs() behavior and const-ness.

----------------------------------------------------------------
Kees Cook (18):
PCI: Test for bit underflow in pcie_set_readrq()
KUnit: Introduce ffs()-family tests
bitops: Add __attribute_const__ to generic ffs()-family implementations
csky: Add __attribute_const__ to ffs()-family implementations
x86: Add __attribute_const__ to ffs()-family implementations
powerpc: Add __attribute_const__ to ffs()-family implementations
sh: Add __attribute_const__ to ffs()-family implementations
alpha: Add __attribute_const__ to ffs()-family implementations
hexagon: Add __attribute_const__ to ffs()-family implementations
riscv: Add __attribute_const__ to ffs()-family implementations
openrisc: Add __attribute_const__ to ffs()-family implementations
m68k: Add __attribute_const__ to ffs()-family implementations
mips: Add __attribute_const__ to ffs()-family implementations
parisc: Add __attribute_const__ to ffs()-family implementations
s390: Add __attribute_const__ to ffs()-family implementations
xtensa: Add __attribute_const__ to ffs()-family implementations
sparc: Add __attribute_const__ to ffs()-family implementations
KUnit: ffs: Validate all the __attribute_const__ annotations

 lib/Kconfig.debug                          |  14 +
 lib/tests/Makefile                         |   1 +
 arch/alpha/include/asm/bitops.h            |  14 +-
 arch/csky/include/asm/bitops.h             |   8 +-
 arch/hexagon/include/asm/bitops.h          |  10 +-
 arch/m68k/include/asm/bitops.h             |  14 +-
 arch/mips/include/asm/bitops.h             |   8 +-
 arch/openrisc/include/asm/bitops/__ffs.h   |   2 +-
 arch/openrisc/include/asm/bitops/__fls.h   |   2 +-
 arch/openrisc/include/asm/bitops/ffs.h     |   2 +-
 arch/openrisc/include/asm/bitops/fls.h     |   2 +-
 arch/parisc/include/asm/bitops.h           |   6 +-
 arch/powerpc/include/asm/bitops.h          |   4 +-
 arch/riscv/include/asm/bitops.h            |   6 +-
 arch/s390/include/asm/bitops.h             |  10 +-
 arch/sh/include/asm/bitops.h               |   4 +-
 arch/sparc/include/asm/bitops_64.h         |   8 +-
 arch/x86/include/asm/bitops.h              |  12 +-
 arch/xtensa/include/asm/bitops.h           |  10 +-
 include/asm-generic/bitops/__ffs.h         |   2 +-
 include/asm-generic/bitops/__fls.h         |   2 +-
 include/asm-generic/bitops/builtin-__ffs.h |   2 +-
 include/asm-generic/bitops/builtin-__fls.h |   2 +-
 include/asm-generic/bitops/builtin-fls.h   |   2 +-
 include/asm-generic/bitops/ffs.h           |   2 +-
 include/asm-generic/bitops/fls.h           |   2 +-
 include/asm-generic/bitops/fls64.h         |   4 +-
 include/linux/bitops.h                     |   2 +-
 drivers/pci/pci.c                          |   6 +-
 lib/clz_ctz.c                              |   8 +-
 lib/tests/ffs_kunit.c                      | 566 +++++++++++++++++++++++++++++
 31 files changed, 661 insertions(+), 76 deletions(-)
 create mode 100644 lib/tests/ffs_kunit.c
Signature · 1 line
Kees Cook
merge bot Merged
#1 lore raw
The pull request you sent on Mon, 29 Sep 2025 12:02:45 -0700:

The pull request you sent on Mon, 29 Sep 2025 12:02:45 -0700:

Quoted 1 line

https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git tags/ffs-const-v6.18-rc1

has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/8c1ed3021883f5e49f74dfb41ce0a24e5d07fdf0

Thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/prtracker.html