Go to file
Florian Westphal b2f742c846 netfilter: nf_tables: restart set lookup on base_seq change
The hash, hash_fast, rhash and bitwise sets may indicate no result even
though a matching element exists during a short time window while other
cpu is finalizing the transaction.

This happens when the hash lookup/bitwise lookup function has picked up
the old genbit, right before it was toggled by nf_tables_commit(), but
then the same cpu managed to unlink the matching old element from the
hash table:

cpu0					cpu1
  has added new elements to clone
  has marked elements as being
  inactive in new generation
					perform lookup in the set
  enters commit phase:
					A) observes old genbit
   increments base_seq
I) increments the genbit
II) removes old element from the set
					B) finds matching element
					C) returns no match: found
					element is not valid in old
					generation

					Next lookup observes new genbit and
					finds matching e2.

Consider a packet matching element e1, e2.

cpu0 processes following transaction:
1. remove e1
2. adds e2, which has same key as e1.

P matches both e1 and e2.  Therefore, cpu1 should always find a match
for P. Due to above race, this is not the case:

cpu1 observed the old genbit.  e2 will not be considered once it is found.
The element e1 is not found anymore if cpu0 managed to unlink it from the
hlist before cpu1 found it during list traversal.

The situation only occurs for a brief time period, lookups happening
after I) observe new genbit and return e2.

This problem exists in all set types except nft_set_pipapo, so fix it once
in nft_lookup rather than each set ops individually.

Sample the base sequence counter, which gets incremented right before the
genbit is changed.

Then, if no match is found, retry the lookup if the base sequence was
altered in between.

If the base sequence hasn't changed:
 - No update took place: no-match result is expected.
   This is the common case.  or:
 - nf_tables_commit() hasn't progressed to genbit update yet.
   Old elements were still visible and nomatch result is expected, or:
 - nf_tables_commit updated the genbit:
   We picked up the new base_seq, so the lookup function also picked
   up the new genbit, no-match result is expected.

If the old genbit was observed, then nft_lookup also picked up the old
base_seq: nft_lookup_should_retry() returns true and relookup is performed
in the new generation.

This problem was added when the unconditional synchronize_rcu() call
that followed the current/next generation bit toggle was removed.

Thanks to Pablo Neira Ayuso for reviewing an earlier version of this
patchset, for suggesting re-use of existing base_seq and placement of
the restart loop in nft_set_do_lookup().

Fixes: 0cbc06b3fa ("netfilter: nf_tables: remove synchronize_rcu in commit phase")
Signed-off-by: Florian Westphal <fw@strlen.de>
2025-09-10 20:30:37 +02:00
Documentation doc: mptcp: net.mptcp.pm_type is deprecated 2025-09-09 18:39:52 -07:00
LICENSES
arch Including fixes from netfilter, wireless and Bluetooth. 2025-09-04 09:59:15 -07:00
block block: validate QoS before calling __rq_qos_done_bio() 2025-08-26 10:34:08 -06:00
certs
crypto
drivers macsec: sync features on RTM_NEWLINK 2025-09-09 18:28:27 -07:00
fs a ksmbd server fix 2025-09-03 20:44:15 -07:00
include netfilter: nf_tables: make nft_set_do_lookup available unconditionally 2025-09-10 20:30:37 +02:00
init hardening: Require clang 20.1.0 for __counted_by 2025-08-29 12:04:53 -07:00
io_uring io_uring/kbuf: always use READ_ONCE() to read ring provided buffer lengths 2025-08-28 05:48:34 -06:00
ipc
kernel sched: Fix sched_numa_find_nth_cpu() if mask offline 2025-09-03 12:20:06 -04:00
lib hardening fixes for v6.17-rc4 2025-08-31 08:56:45 -07:00
mm slab fixes for 6.17-rc5 2025-09-04 09:54:20 -07:00
net netfilter: nf_tables: restart set lookup on base_seq change 2025-09-10 20:30:37 +02:00
rust rust: mm: mark VmaNew as transparent 2025-08-27 22:45:41 -07:00
samples
scripts kasan: fix GCC mem-intrinsic prefix with sw tags 2025-08-27 22:45:43 -07:00
security + Features 2025-08-04 08:17:28 -07:00
sound ALSA: hda/hdmi: Add pin fix for another HP EliteDesk 800 G4 model 2025-09-01 13:51:57 +02:00
tools selftests: mptcp: shellcheck: support v0.11.0 2025-09-09 18:39:52 -07:00
usr
virt
.clang-format
.clippy.toml
.cocciconfig
.editorconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap MAINTAINERS: Update Nobuhiro Iwamatsu's email address 2025-09-01 10:36:10 +02:00
.pylintrc
.rustfmt.toml
COPYING
CREDITS MAINTAINERS: retire Boris from TLS maintainers 2025-08-26 17:36:01 -07:00
Kbuild
Kconfig
MAINTAINERS Including fixes from netfilter, wireless and Bluetooth. 2025-09-04 09:59:15 -07:00
Makefile Linux 6.17-rc4 2025-08-31 15:33:07 -07:00
README

README

Linux kernel
============

There are several guides for kernel developers and users. These guides can
be rendered in a number of formats, like HTML and PDF. Please read
Documentation/admin-guide/README.rst first.

In order to build the documentation, use ``make htmldocs`` or
``make pdfdocs``.  The formatted documentation can also be read online at:

    https://www.kernel.org/doc/html/latest/

There are various text files in the Documentation/ subdirectory,
several of them using the reStructuredText markup notation.

Please read the Documentation/process/changes.rst file, as it contains the
requirements for building and running the kernel, and information about
the problems which may result by upgrading your kernel.