]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
netlink: don't crash if prefix for < byte is requested
authorFlorian Westphal <fw@strlen.de>
Thu, 14 Dec 2023 14:39:27 +0000 (15:39 +0100)
committerFlorian Westphal <fw@strlen.de>
Thu, 14 Dec 2023 16:53:43 +0000 (17:53 +0100)
If prefix is used with a datatype that has less than 8 bits an
assertion is triggered:

src/netlink.c:243: netlink_gen_raw_data: Assertion `len > 0' failed.

This is esoteric, the alternative would be to restrict prefixes
to ipv4/ipv6 addresses.

Simpler fix is to use round_up instead of divide.

Signed-off-by: Florian Westphal <fw@strlen.de>
src/netlink_linearize.c
tests/py/ip/ip.t
tests/py/ip/ip.t.json
tests/py/ip/ip.t.payload
tests/py/ip/ip.t.payload.bridge
tests/py/ip/ip.t.payload.inet
tests/py/ip/ip.t.payload.netdev

index 61828eb9f295abee6c8738b70b30da5f859e2cbf..d8b41a0889482c2eb53935604ff78f7d71e3f32a 100644 (file)
@@ -460,7 +460,8 @@ static struct expr *netlink_gen_prefix(struct netlink_linearize_ctx *ctx,
        mpz_init(mask);
        mpz_prefixmask(mask, expr->right->len, expr->right->prefix_len);
        netlink_gen_raw_data(mask, expr->right->byteorder,
-                            expr->right->len / BITS_PER_BYTE, &nld);
+                            div_round_up(expr->right->len, BITS_PER_BYTE),
+                            &nld);
        mpz_clear(mask);
 
        zero.len = nld.len;
index 720d9ae92b60da74d5b4dfd546632eac7b1e30a4..e6999c29478b7ffaf11d09876405e54066b9a2ed 100644 (file)
@@ -133,3 +133,5 @@ ip saddr . ip daddr vmap { 192.168.5.1-192.168.5.128 . 192.168.6.1-192.168.6.128
 
 ip saddr 1.2.3.4 ip daddr 3.4.5.6;ok
 ip saddr 1.2.3.4 counter ip daddr 3.4.5.6;ok
+
+ip dscp 1/6;ok;ip dscp & 0x3f == lephb
index 882c94eb4e15d7b63d40d4a6780b36d158c324fc..a170e5c159651bd2dffaced05146166647316b10 100644 (file)
         }
     }
 ]
+
+# ip dscp 1/6
+[
+    {
+        "match": {
+            "left": {
+                "&": [
+                    {
+                        "payload": {
+                            "field": "dscp",
+                            "protocol": "ip"
+                        }
+                    },
+                    63
+                ]
+            },
+            "op": "==",
+            "right": "lephb"
+        }
+    }
+]
index 43605a361a7a778fb5fe2ccf02bcfdc5aa4e9c90..d7ddf7be0c3b486a5379fa2cc8291a7ae8d4ea32 100644 (file)
@@ -556,3 +556,11 @@ ip test-ip4 input
   [ counter pkts 0 bytes 0 ]
   [ payload load 4b @ network header + 16 => reg 1 ]
   [ cmp eq reg 1 0x06050403 ]
+
+# ip dscp 1/6
+ip test-ip4 input
+  [ payload load 1b @ network header + 1 => reg 1 ]
+  [ bitwise reg 1 = ( reg 1 & 0x000000fc ) ^ 0x00000000 ]
+  [ bitwise reg 1 = ( reg 1 >> 0x00000002 ) ]
+  [ bitwise reg 1 = ( reg 1 & 0x0000003f ) ^ 0x00000000 ]
+  [ cmp eq reg 1 0x00000001 ]
index e506f300c947d93912a67559fe070a1b9a171455..53f881d336df48b870d0c4c2eaeaadecb2f21e86 100644 (file)
@@ -726,3 +726,13 @@ bridge test-bridge input
   [ counter pkts 0 bytes 0 ]
   [ payload load 4b @ network header + 16 => reg 1 ]
   [ cmp eq reg 1 0x06050403 ]
+
+# ip dscp 1/6
+bridge test-bridge input
+  [ meta load protocol => reg 1 ]
+  [ cmp eq reg 1 0x00000008 ]
+  [ payload load 1b @ network header + 1 => reg 1 ]
+  [ bitwise reg 1 = ( reg 1 & 0x000000fc ) ^ 0x00000000 ]
+  [ bitwise reg 1 = ( reg 1 >> 0x00000002 ) ]
+  [ bitwise reg 1 = ( reg 1 & 0x0000003f ) ^ 0x00000000 ]
+  [ cmp eq reg 1 0x00000001 ]
index a7fa0faffba31b3396ade0b1e87d8aef845eab59..08674c98e022e023a0e13966cbdf5609a38b8109 100644 (file)
@@ -726,3 +726,13 @@ inet test-inet input
   [ counter pkts 0 bytes 0 ]
   [ payload load 4b @ network header + 16 => reg 1 ]
   [ cmp eq reg 1 0x06050403 ]
+
+# ip dscp 1/6
+inet test-inet input
+  [ meta load nfproto => reg 1 ]
+  [ cmp eq reg 1 0x00000002 ]
+  [ payload load 1b @ network header + 1 => reg 1 ]
+  [ bitwise reg 1 = ( reg 1 & 0x000000fc ) ^ 0x00000000 ]
+  [ bitwise reg 1 = ( reg 1 >> 0x00000002 ) ]
+  [ bitwise reg 1 = ( reg 1 & 0x0000003f ) ^ 0x00000000 ]
+  [ cmp eq reg 1 0x00000001 ]
index aebd9d64c8e31876959024f516de618fcacf4a09..8220b05d11c15926d4172c97a3b0320a7c809b37 100644 (file)
@@ -726,3 +726,13 @@ netdev test-netdev ingress
   [ counter pkts 0 bytes 0 ]
   [ payload load 4b @ network header + 16 => reg 1 ]
   [ cmp eq reg 1 0x06050403 ]
+
+# ip dscp 1/6
+netdev test-netdev ingress
+  [ meta load protocol => reg 1 ]
+  [ cmp eq reg 1 0x00000008 ]
+  [ payload load 1b @ network header + 1 => reg 1 ]
+  [ bitwise reg 1 = ( reg 1 & 0x000000fc ) ^ 0x00000000 ]
+  [ bitwise reg 1 = ( reg 1 >> 0x00000002 ) ]
+  [ bitwise reg 1 = ( reg 1 & 0x0000003f ) ^ 0x00000000 ]
+  [ cmp eq reg 1 0x00000001 ]