Bug 1749700 - iptables-restore fails if comment contains '-' and 't'
Summary: iptables-restore fails if comment contains '-' and 't'
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: iptables
Version: 7.7
Hardware: Unspecified
OS: Unspecified
high
high
Target Milestone: rc
: ---
Assignee: Phil Sutter
QA Contact: Jiri Peska
URL:
Whiteboard:
Depends On: 1749698
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-09-06 09:17 UTC by Phil Sutter
Modified: 2020-03-31 20:09 UTC (History)
10 users (show)

Fixed In Version: iptables-1.4.21-34.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of: 1749698
Environment:
Last Closed: 2020-03-31 20:09:39 UTC
Target Upstream Version:


Attachments (Terms of Use)


Links
System ID Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2020:1174 None None None 2020-03-31 20:09:42 UTC

Description Phil Sutter 2019-09-06 09:17:11 UTC
+++ This bug was initially created as a clone of Bug #1749698 +++

Seems like iptables-restore parser is buggy:

# iptables -A FORWARD -m comment --comment "-t foo bar" -j ACCEPT
# iptables-save >/tmp/ipt.dump
# grep -v '^#' /tmp/ipt.dump
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A FORWARD -m comment --comment "-t foo bar" -j ACCEPT
COMMIT
# iptables-restore </tmp/ipt.dump
iptables-nft-restore v1.8.3 (nf_tables): The -t option (seen in line 7) cannot be used in iptables-nft-restore.

Error occurred at line: 7
Try `iptables-nft-restore -h' or 'iptables-nft-restore --help' for more information.

The Problem is consistent with upstream and happens with legacy as well as nft
variant. RHEL7 iptables-1.4.21-28.el7.x86_64 is reported to work correctly, so
this is a regression.

Comment 2 Phil Sutter 2019-09-20 15:54:43 UTC
Correction: The actual bug (and regression) is rejecting of comments starting
with dash and having a 't' somewhere, not '-t' itself (this was never allowed).

A testcase for this is:

| *filter
| -A FORWARD -m comment --comment "- allow this" -j ACCEPT
| COMMIT

Fix sent upstream: https://lore.kernel.org/netfilter-devel/20190920154920.7927-1-phil@nwl.cc/T/#u

Comment 3 Jun Wang 2019-10-02 17:17:34 UTC
Any plan and timeline to release the fix in RHEL/CentOS 7.7 updates?

Comment 4 Phil Sutter 2019-10-04 09:44:40 UTC
Hi Jun Wang,

(In reply to Jun Wang from comment #3)
> Any plan and timeline to release the fix in RHEL/CentOS 7.7 updates?

Sorry, no. Upstream hasn't accepted the patch yet, so I can't make any estimate regarding downstream.

Cheers, Phil

Comment 5 Phil Sutter 2019-10-21 17:18:29 UTC
Upstream commit to backport:

commit 3dc433b55bbfaf9df3ee408aaa6282742f377864
Author: Phil Sutter <phil@nwl.cc>
Date:   Fri Sep 20 17:31:58 2019 +0200

    xtables-restore: Fix --table parameter check
    
    Xtables-restore tries to reject rule commands in input which contain a
    --table parameter (since it is adding this itself based on the previous
    table line). The manual check was not perfect though as it caught any
    parameter starting with a dash and containing a 't' somewhere, even in
    rule comments:
    
    | *filter
    | -A FORWARD -m comment --comment "- allow this one" -j ACCEPT
    | COMMIT
    
    Instead of error-prone manual checking, go a much simpler route: All
    do_command callbacks are passed a boolean indicating they're called from
    *tables-restore. React upon this when handling a table parameter and
    error out if it's not the first one.
    
    Fixes: f8e5ebc5986bf ("iptables: Fix crash on malformed iptables-restore")
    Signed-off-by: Phil Sutter <phil@nwl.cc>
    Acked-by: Florian Westphal <fw@strlen.de>

Comment 9 Francisco Peralta 2019-11-29 08:34:47 UTC
Dear all,
 is there any proceedings about this one since last month?

Thanks in advance,
 Cisco.

Comment 10 Phil Sutter 2019-11-29 10:42:33 UTC
Hi Francisco,

(In reply to Francisco Peralta from comment #9)
> Dear all,
>  is there any proceedings about this one since last month?

No, there is no progress since last month, but that is expected. The fix will be shipped along with RHEL7.8.

Cheers, Phil

Comment 12 errata-xmlrpc 2020-03-31 20:09:39 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, 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/RHBA-2020:1174


Note You need to log in before you can comment on or make changes to this bug.