Skip to contentSkip to conversation

segtree: fix get element command with open intervals

PATCH In review Pablo Neira Ayuso 2 participants 6 messages Jul 2 – Jul 7 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/2 segtree: fix get element command with open intervals

Skip the closing end element in case this is an open interval. Otherwise, a bogus end element max(type) + 1 is provided, eg. in inet_service, this results as a 0x10000 with end interval flag which is interpreted by the kernel as a matching closing element.

Fixes a43cc8d53096 ("src: support for get element command")
---
 src/segtree.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
src/segtree.c +7 -1
index a12820bcf1ec..e877814505f4 100644
@@ -73,12 +73,13 @@ static void set_elem_expr_add(const struct set *set, struct expr *init,
 struct expr *get_set_intervals(const struct set *set, const struct expr *init)
 {
 	enum byteorder byteorder = get_key_byteorder(set->key);
+	mpz_t low, high, mask;
 	struct expr *new_init;
-	mpz_t low, high;
 	struct expr *i;
 
 	mpz_init2(low, set->key->len);
 	mpz_init2(high, set->key->len);
+	mpz_init2(mask, set->key->len);
 
 	new_init = set_expr_alloc(&internal_location, NULL);
 
@@ -105,6 +106,10 @@ struct expr *get_set_intervals(const struct set *set, const struct expr *init)
 			range_expr_value_low(low, i->key);
 			set_elem_expr_add(set, new_init, low, 0, byteorder);
 			range_expr_value_high(high, i->key);
+			mpz_bitmask(mask, i->len);
+			if (!mpz_cmp(mask, high))
+				break;
+
 			mpz_add_ui(high, high, 1);
 			set_elem_expr_add(set, new_init, high,
 					  EXPR_F_INTERVAL_END, byteorder);
@@ -115,6 +120,7 @@ struct expr *get_set_intervals(const struct set *set, const struct expr *init)
 		}
 	}
 
+	mpz_clear(mask);
 	mpz_clear(low);
 	mpz_clear(high);
 
Signature · 1 line
2.47.3
author maintainer
#1 lore raw

PATCH 2/2 tests: shell: expand get command test with open intervals

Extend the existing test to cover get commands with open internals.

---
 tests/shell/testcases/sets/0034get_element_0         | 12 +++++++++++-
 .../testcases/sets/dumps/0034get_element_0.json-nft  |  6 ++++++
 .../shell/testcases/sets/dumps/0034get_element_0.nft |  2 +-
 3 files changed, 18 insertions(+), 2 deletions(-)
tests/shell/testcases/sets/0034get_element_0 +11 -1
index 32375b9f50c2..a25769604685 100755
@@ -16,7 +16,7 @@ check() { # (set, elems, expected)
 
 RULESET="add table ip t
 add set ip t s { type inet_service; flags interval; }
-add element ip t s { 10, 20-30, 40, 50-60 }
+add element ip t s { 10, 20-30, 40, 50-60, 60000-65535 }
 add set ip t ips { type ipv4_addr; flags interval; }
 add element ip t ips { 10.0.0.1, 10.0.0.5-10.0.0.8 }
 add element ip t ips { 10.0.0.128/25, 10.0.1.0/24, 10.0.2.3-10.0.2.12 }
@@ -36,6 +36,16 @@ check s 15-18 ""
 # multiple single elements, ranges smaller than present
 check s "10, 40" "10, 40"
 check s "22-24, 26-28" "20-30, 20-30"
+check s "60000-65535" "60000-65535"
+check s "60000-65534" "60000-65535"
+check s "60001-65535" "60000-65535"
+check s "60001-65534" "60000-65535"
+check s "22-24, 60000-65535" "20-30, 60000-65535"
+check s "22-24, 60000-65534" "20-30, 60000-65535"
+check s "22-24, 60001-65535" "20-30, 60000-65535"
+check s "22-24, 60001-65534" "20-30, 60000-65535"
+check s "60001-65534, 10" "60000-65535, 10"
+check s "20, 60001-65535, 10" "20-30, 60000-65535, 10"
 check s 21-29 20-30
 
 # mixed single elements and ranges
tests/shell/testcases/sets/dumps/0034get_element_0.json-nft +6 -0
index bfc0e4a0f588..64c7dc0c6555 100644
@@ -38,6 +38,12 @@
               50,
               60
             ]
+          },
+          {
+            "range": [
+              60000,
+              65535
+            ]
           }
         ]
       }
tests/shell/testcases/sets/dumps/0034get_element_0.nft +1 -1
index 1c1dd9779a8a..889640389cd9 100644
@@ -2,7 +2,7 @@ table ip t {
 	set s {
 		type inet_service
 		flags interval
-		elements = { 10, 20-30, 40, 50-60 }
+		elements = { 10, 20-30, 40, 50-60, 60000-65535 }
 	}
 
 	set ips {
Signature · 1 line
2.47.3
reviewer
#2 lore raw

Re: [PATCH nft 2/2] tests: shell: expand get command test with open intervals

Hi Pablo,

Quoted 1 line · Pablo Neira Ayuso

Extend the existing test to cover get commands with open internals.

This test fails on a Big Endian testing machine running Fedora Rawhide running 7.2.0-0.rc2.21.fc45. Does this perhaps test a recent kernel fix or something?

Here's the test output for reference:

| W: [FAILED]     1/1 testcases/sets/0034get_element_0
| Command: testcases/sets/0034get_element_0 
| Error: Could not process rule: No such file or directory
| get element ip t s { 11 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
| Error: Could not process rule: No such file or directory
| get element ip t s { 15-18 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Error: Could not process rule: Too many open files
| get element ip t s { 60000-65534 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ERROR: asked for '60000-65534' in set s, expecting '60000-65535' but got
| ''
| Error: Could not process rule: Too many open files
| get element ip t s { 60001-65534 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ERROR: asked for '60001-65534' in set s, expecting '60000-65535' but got
| ''
| Error: Could not process rule: Too many open files
| get element ip t s { 22-24, 60000-65534 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ERROR: asked for '22-24, 60000-65534' in set s, expecting '20-30,
| 60000-65535' but got ''
| Error: Could not process rule: Too many open files
| get element ip t s { 22-24, 60001-65534 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ERROR: asked for '22-24, 60001-65534' in set s, expecting '20-30,
| 60000-65535' but got ''
| Error: Could not process rule: Too many open files
| get element ip t s { 60001-65534, 10 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ERROR: asked for '60001-65534, 10' in set s, expecting '60000-65535, 10'
| but got ''
| Error: Could not process rule: No such file or directory
| get element ip t s { 10-40 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Error: Could not process rule: No such file or directory
| get element ip t s { 10-20 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Error: Could not process rule: No such file or directory
| get element ip t s { 10-25 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Error: Could not process rule: No such file or directory
| get element ip t s { 25-55 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Error: Could not process rule: No such file or directory
| get element ip t ips { 10.0.0.2 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Error: Could not process rule: No such file or directory
| get element ip t cs { 10.0.0.1 . 23 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Error: Could not process rule: No such file or directory
| get element ip t cs { 10.0.0.2 . 22 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Cheers, Phil

author maintainer
#3 lore raw

Re: [PATCH nft 2/2] tests: shell: expand get command test with open intervals

Hi Phil,

Quoted 7 lines · Phil Sutter

Hi Pablo,

Quoted 1 line · Pablo Neira Ayuso

Extend the existing test to cover get commands with open internals.

This test fails on a Big Endian testing machine running Fedora Rawhide running 7.2.0-0.rc2.21.fc45. Does this perhaps test a recent kernel fix or something?

Does this kernel contain this kernel fix?

https://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git/commit/?id=d63611cbe8af99dd61b118ee6e5b5e3e518250b2

as well as this userspace fix:

https://git.netfilter.org/nftables/commit/?id=4eafc1a2a9ef5a827b1b4e58cb3b2832d2eb1650

Quoted 58 lines

Here's the test output for reference:

| W: [FAILED]     1/1 testcases/sets/0034get_element_0
| Command: testcases/sets/0034get_element_0 
| Error: Could not process rule: No such file or directory
| get element ip t s { 11 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
| Error: Could not process rule: No such file or directory
| get element ip t s { 15-18 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Error: Could not process rule: Too many open files
| get element ip t s { 60000-65534 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ERROR: asked for '60000-65534' in set s, expecting '60000-65535' but got
| ''
| Error: Could not process rule: Too many open files
| get element ip t s { 60001-65534 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ERROR: asked for '60001-65534' in set s, expecting '60000-65535' but got
| ''
| Error: Could not process rule: Too many open files
| get element ip t s { 22-24, 60000-65534 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ERROR: asked for '22-24, 60000-65534' in set s, expecting '20-30,
| 60000-65535' but got ''
| Error: Could not process rule: Too many open files
| get element ip t s { 22-24, 60001-65534 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ERROR: asked for '22-24, 60001-65534' in set s, expecting '20-30,
| 60000-65535' but got ''
| Error: Could not process rule: Too many open files
| get element ip t s { 60001-65534, 10 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ERROR: asked for '60001-65534, 10' in set s, expecting '60000-65535, 10'
| but got ''
| Error: Could not process rule: No such file or directory
| get element ip t s { 10-40 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Error: Could not process rule: No such file or directory
| get element ip t s { 10-20 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Error: Could not process rule: No such file or directory
| get element ip t s { 10-25 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Error: Could not process rule: No such file or directory
| get element ip t s { 25-55 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Error: Could not process rule: No such file or directory
| get element ip t ips { 10.0.0.2 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Error: Could not process rule: No such file or directory
| get element ip t cs { 10.0.0.1 . 23 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Error: Could not process rule: No such file or directory
| get element ip t cs { 10.0.0.2 . 22 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Cheers, Phil

reviewer
#4 lore raw

Re: [PATCH nft 2/2] tests: shell: expand get command test with open intervals

Quoted 7 lines · Pablo Neira Ayuso

Hi Phil,

Quoted 4 lines · Phil Sutter

Hi Pablo,

Quoted 1 line · Pablo Neira Ayuso

Extend the existing test to cover get commands with open internals.

Quoted 7 lines
Quoted 3 lines

This test fails on a Big Endian testing machine running Fedora Rawhide running 7.2.0-0.rc2.21.fc45. Does this perhaps test a recent kernel fix or something?

Does this kernel contain this kernel fix?

https://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git/commit/?id=d63611cbe8af99dd61b118ee6e5b5e3e518250b2

Ah, thanks for the pointer. Rawhide kernels are "best effort" by early rebase vs. excessive backporting, so a fix in nf.git must be rather critical to hit it before linus.git.

Quoted 3 lines

as well as this userspace fix:

https://git.netfilter.org/nftables/commit/?id=4eafc1a2a9ef5a827b1b4e58cb3b2832d2eb1650

Yes, this is present. To give you a bit of context: I have a script which builds current upstream HEAD of iptables, nftables and dependencies on a fresh Rawhide for running the test suites. I reserve a RH-internal Big Endian machine (s390x VM) for it. The goal is to detect Big Endian breakers early.

Thanks for clarifying!

Cheers, Phil

author maintainer
#5 lore raw

Re: [PATCH nft 2/2] tests: shell: expand get command test with open intervals

Quoted 22 lines · Phil Sutter
Quoted 7 lines · Pablo Neira Ayuso

Hi Phil,

Quoted 4 lines · Phil Sutter

Hi Pablo,

Quoted 1 line · Pablo Neira Ayuso

Extend the existing test to cover get commands with open internals.

Quoted 7 lines
Quoted 3 lines

This test fails on a Big Endian testing machine running Fedora Rawhide running 7.2.0-0.rc2.21.fc45. Does this perhaps test a recent kernel fix or something?

Does this kernel contain this kernel fix?

https://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git/commit/?id=d63611cbe8af99dd61b118ee6e5b5e3e518250b2

Ah, thanks for the pointer. Rawhide kernels are "best effort" by early rebase vs. excessive backporting, so a fix in nf.git must be rather critical to hit it before linus.git.

Quoted 2 lines

as well as this userspace fix:

Quoted 7 lines
Quoted 1 line

https://git.netfilter.org/nftables/commit/?id=4eafc1a2a9ef5a827b1b4e58cb3b2832d2eb1650

Yes, this is present. To give you a bit of context: I have a script which builds current upstream HEAD of iptables, nftables and dependencies on a fresh Rawhide for running the test suites. I reserve a RH-internal Big Endian machine (s390x VM) for it. The goal is to detect Big Endian breakers early.

Thanks for explaining.

Quoted 1 line

Thanks for clarifying!

OK, then, all good, it is a matter of waiting for the kernel fix to propagate to the rawhide kernel tree.

Ping back if problem persists by then, thanks.