Linux Netfilter development
 help / color / mirror / Atom feed
* [PATCH request stable 6.12 6.6 6.1] netfilter: nf_tables_netdev_event UAF of binding chain
@ 2026-09-25  2:00 Yu Junzhe
  2026-09-25  5:07 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 14+ messages in thread
From: Yu Junzhe @ 2026-09-25  2:00 UTC (permalink / raw)
  To: stable
  Cc: Greg Kroah-Hartman, Sasha Levin, Pablo Neira Ayuso,
	Florian Westphal, netfilter-devel

Hello,

Please consider a backport of the following use-after-free to the
longterm trees that still have it: 6.12, 6.6, and 6.1. 6.18 and newer
are not affected.

There is no single upstream commit to cherry-pick. On current linux.git
the netdev notifier no longer calls __nft_release_basechain(); it only
unregisters the per-device hook. That change arrived as part of the
netdev-hook rework and does not apply to these stable trees.

Bug
===

nf_tables_netdev_event() walks table->chains with
list_for_each_entry_safe. On NETDEV_UNREGISTER of the last hook,
nft_netdev_event() calls __nft_release_basechain(). Releasing the base
chain deactivates a JUMP to an NFT_CHAIN_BINDING chain, which
nft_chain_del()s that successor and nft_immediate_destroy() kfree()s
it. The walker's saved nr still points at the freed nft_chain.

Still present in:

  linux-6.12.y  (6.12.111)  nft_chain_filter.c: __nft_release_basechain()
  linux-6.6.y   (6.6.157)
  linux-6.1.y   (6.1.188)

Gone in linux-6.18.y and linux-7.0.y.

Reproducer (nftables 1.0.9)
===========================

An anonymous jump is what sets NFT_CHAIN_BINDING (chain flags 0x4).
Commit the base chain first, then add the jump in a second command.
Chains are appended to table->chains, and the walker frees the chain
that follows the base chain. One nft -f that contains both creates the
binding chain first and does not hit this path.

  ip link add br0 type bridge
  ip link set br0 up
  nft -f - <<'EOF'
  table netdev t {
          chain in {
                  type filter hook ingress device "br0" priority 0; policy accept;
          }
  }
  EOF
  nft add rule netdev t in 'jump { accept; }'
  ip link del br0

The namespace must still be alive. Netns teardown is too late: nft
pernet exit wins that race. Needs CAP_NET_ADMIN. Do not run on a host
kernel.

Confirmed on Linux 6.6.144 KASAN (same __nft_release_basechain() walk
as 6.6.y and 6.12.y). I have not booted 6.12.111 or 6.1.188.

  BUG: KASAN: slab-use-after-free in nf_tables_netdev_event+0x635/0x970
  Read of size 8 at addr ff110000037faa20 by task ip/229
  Freed by task 229:
    nft_immediate_destroy
    __nft_release_basechain_now
    __nft_release_basechain
    nf_tables_netdev_event

The read is 8 bytes at offset 32 of a kmalloc-128 object
(nft_chain.list).

Thanks,
Yu Junzhe
FuzzAnything <fuzzanything@gmail.com>

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2026-10-02 21:44 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-25  2:00 [PATCH request stable 6.12 6.6 6.1] netfilter: nf_tables_netdev_event UAF of binding chain Yu Junzhe
2026-09-25  5:07 ` Greg Kroah-Hartman
2026-09-25  7:51   ` Yu Junzhe
2026-09-25  7:51     ` [PATCH 6.12 1/2] netfilter: nf_tables: Tolerate chains with no remaining hooks Yu Junzhe
2026-09-25  7:51     ` [PATCH 6.12 2/2] netfilter: nf_tables: Simplify chain netdev notifier Yu Junzhe
2026-09-25  7:51     ` [PATCH 6.6 6.1 1/2] netfilter: nf_tables: Tolerate chains with no remaining hooks Yu Junzhe
2026-09-25 18:47       ` Sasha Levin
2026-10-01  3:51         ` [PATCH 6.1] netfilter: nf_tables: fix UAF in nf_tables_netdev_event walker Ma Xinmeng
2026-10-01  8:46           ` Pablo Neira Ayuso
2026-10-02  4:25             ` [PATCH 6.1 1/2] netfilter: nf_tables: allow to create netdev chain without device Ma Xinmeng
2026-10-02 21:10               ` Sasha Levin
2026-10-02 21:44                 ` Pablo Neira Ayuso
     [not found]             ` <20261002042509.711-1-1564938642@qq.com>
2026-10-02  4:25               ` [PATCH 6.1 2/2] netfilter: nf_tables: support for adding new devices to an existing netdev chain Ma Xinmeng
2026-09-25  7:51     ` [PATCH 6.6 6.1 2/2] netfilter: nf_tables: Simplify chain netdev notifier Yu Junzhe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox