From: Florian Westphal Date: Wed, 28 Jan 2026 23:07:18 +0000 (+0100) Subject: tests: shell: add test case for interval set with timeout and aborted transaction X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=HEAD;p=thirdparty%2Fnftables.git tests: shell: add test case for interval set with timeout and aborted transaction Add a regression test for rbtree+bsearch getting out-of-sync in nf-next kernel. This covers the syzkaller reproducer from https://syzkaller.appspot.com/bug?extid=d417922a3e7935517ef6 which triggers abort with earlier gc at insert time and additional corner case where transaction passes without recording a relevant change in the set (i.e. no call to either abort or commit). This test passes even on buggy kernels unless KASAN is enabled. Signed-off-by: Florian Westphal --- diff --git a/tests/shell/testcases/sets/dumps/rbtree_timeout_no_commit.json-nft b/tests/shell/testcases/sets/dumps/rbtree_timeout_no_commit.json-nft new file mode 100644 index 00000000..3cf22678 --- /dev/null +++ b/tests/shell/testcases/sets/dumps/rbtree_timeout_no_commit.json-nft @@ -0,0 +1,34 @@ +{ + "nftables": [ + { + "metainfo": { + "version": "VERSION", + "release_name": "RELEASE_NAME", + "json_schema_version": 1 + } + }, + { + "table": { + "family": "ip", + "name": "t", + "handle": 0 + } + }, + { + "set": { + "family": "ip", + "name": "s", + "table": "t", + "type": "ipv4_addr", + "handle": 0, + "flags": [ + "interval", + "timeout" + ], + "elem": [ + "10.0.0.1" + ] + } + } + ] +} diff --git a/tests/shell/testcases/sets/dumps/rbtree_timeout_no_commit.nft b/tests/shell/testcases/sets/dumps/rbtree_timeout_no_commit.nft new file mode 100644 index 00000000..df0be9af --- /dev/null +++ b/tests/shell/testcases/sets/dumps/rbtree_timeout_no_commit.nft @@ -0,0 +1,7 @@ +table ip t { + set s { + type ipv4_addr + flags interval,timeout + elements = { 10.0.0.1 } + } +} diff --git a/tests/shell/testcases/sets/rbtree_timeout_no_commit b/tests/shell/testcases/sets/rbtree_timeout_no_commit new file mode 100755 index 00000000..38f5afc0 --- /dev/null +++ b/tests/shell/testcases/sets/rbtree_timeout_no_commit @@ -0,0 +1,63 @@ +#!/bin/bash + +# Test for bug added with kernel commit +# 7e43e0a1141d ("netfilter: nft_set_rbtree: translate rbtree to array for binary search") +# where the binary search blob gets out-of-sync with the rbtree, holding pointers +# to elements that have been free'd by garbage collection. +# +# 1. add new element, transaction is later aborted. +# Commit hook isn't called, so make sure ->abort refreshes the blob too. +# +# 2. re-add an existing element, transaction passes. +# In this case, the commit hook isn't called because we don't have +# any changes to the set from transaction point of view. +# Transaction log can even be empty in this case. +# +# 3. create (F_EXCL) an existing element. +# Also triggers abort, but set sets ->abort callback isn't invoked +# as no element was added. + +$NFT -f - <