Bug 1805798

Summary: JSON parser fails with "prefix" inside "concat"
Product: Red Hat Enterprise Linux 8 Reporter: Eric Garver <egarver>
Component: nftablesAssignee: Phil Sutter <psutter>
Status: CLOSED ERRATA QA Contact: Jiri Peska <jpeska>
Severity: medium Docs Contact:
Priority: medium    
Version: 8.2CC: jmaxwell, jpeska, todoleza
Target Milestone: rc   
Target Release: 8.3   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: nftables-0.9.3-13.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-11-04 01:58:24 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1685256, 1807630    

Description Eric Garver 2020-02-21 15:03:21 UTC
When testing sets with intervals and concatenations (bug 1795224) it was found that the JSON parser fails when a "prefix" occurs within "concat".

[root@rhel8-test1 shell]# dnf info nftables
Name         : nftables
Epoch        : 1
Version      : 0.9.3
Release      : 11.el8
Architecture : x86_64
Size         : 792 k
Source       : nftables-0.9.3-11.el8.src.rpm

--->8---


[root@rhel8-test1 shell]# cat ./testcases/sets/0044json_prefix_in_concat_0
#!/bin/bash

# JSON parsing "prefix" inside "concat" for a set element

RULESET='{"nftables": [{"metainfo": {"json_schema_version": 1}},
         {"add": {"table": {"family": "inet", "name": "foobar_table"}}},
         {"add": {"set": {"family": "inet", "name": "foobar_set", "table": "foobar_table", "type": ["ipv4_addr", "inet_proto", "inet_service"]}}},
         {"add": {"element": {"elem": [{"concat": [{"prefix": {"addr": "10.10.10.0", "len": 24}}, "sctp", "1234"]}], "family": "inet", "name": "foobar_set", "table": "foobar_table"}}}]}'

set -e
$NFT -j -f - <<< "$RULESET"


[root@rhel8-test1 shell]#  ./run-tests.sh ./testcases/sets/0044json_prefix_in_concat_0
I: using nft binary ./../../src/nft

I: [OK]         ./testcases/sets/0044json_prefix_in_concat_0

I: results: [OK] 1 [FAILED] 0 [TOTAL] 1


[root@rhel8-test1 shell]# NFT=/usr/sbin/nft ./run-tests.sh ./testcases/sets/0044json_prefix_in_concat_0
I: using nft binary /usr/sbin/nft

W: [FAILED]     ./testcases/sets/0044json_prefix_in_concat_0: got 1
internal:0:0-0: Error: Expression type prefix not allowed in context (RHS, PRIMARY).

internal:0:0-0: Error: Parsing expr at index 0 failed.

internal:0:0-0: Error: Invalid set elem at index 0.

internal:0:0-0: Error: Invalid set.

internal:0:0-0: Error: Parsing command array at index 3 failed.

I: results: [OK] 0 [FAILED] 1 [TOTAL] 1

Comment 1 Phil Sutter 2020-05-19 21:37:20 UTC
Upstream commit to backport:

commit 9475ca305a993751b05cf26ef8e785a00de98b94
Author: Phil Sutter <phil>
Date:   Fri Mar 6 16:15:48 2020 +0100

    parser_json: Support ranges in concat expressions
    
    Duplicate commit 8ac2f3b2fca38's changes to bison parser into JSON
    parser by introducing a new context flag signalling we're parsing
    concatenated expressions.
    
    Fixes: 8ac2f3b2fca38 ("src: Add support for concatenated set ranges")
    Signed-off-by: Phil Sutter <phil>
    Acked-by: Eric Garver <eric>

Comment 7 errata-xmlrpc 2020-11-04 01:58:24 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (nftables bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2020:4535