Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1421278

Summary: Inconsistent ordering of rules in INPUT_ZONE_SOURCE in firewalld of RHEL 7.3
Product: Red Hat Enterprise Linux 7 Reporter: Akhil John <ajohn>
Component: firewalldAssignee: Thomas Woerner <twoerner>
Status: CLOSED DUPLICATE QA Contact: qe-baseos-daemons
Severity: high Docs Contact:
Priority: high    
Version: 7.3CC: todoleza
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-03-27 16:08:45 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: 1420851    

Description Akhil John 2017-02-10 20:42:12 UTC
Description of problem:
Unexpected behaviour of INPU_SOURCE_ZONE chain in RHEL 7.3 on adding permanent rule.


Version-Release number of selected component (if applicable):
RHEL 7.3
# firewall-cmd --version 
0.4.3.2


RHEL 7.2
firewall-cmd --version 
0.3.9

How reproducible:
Everytime

Steps to Reproduce:
1. Create 3 custom zone in firewalld, say A, AR, B
# firewall-cmd --new-zone=A --permanent
# firewall-cmd --new-zone=AR --permanent
# firewall-cmd --new-zone=B --permanent
# firewall-cmd --reload

2. Add source address to the three zones. Add larger to small network range.
# firewall-cmd --zone=B --add-source=192.20.31.55/32 --permanent
# firewall-cmd --zone=A --add-source=192.20.0.0/16 --permanent
# firewall-cmd --zone=AR --add-source=192.20.31.0/24 --permanent
# firewall-cmd --reload

# iptables -nvL

----- snip ------
Chain INPUT_ZONES_SOURCE (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 IN_A       all  --  *      *       192.20.0.0/16         0.0.0.0/0           [goto] 
    0     0 IN_B       all  --  *      *       192.20.31.55          0.0.0.0/0           [goto] 
    0     0 IN_AR      all  --  *      *       192.20.31.0/24        0.0.0.0/0           [goto] 

----- snip ------

Here the zones are added in the same order they were added.


3. Now create zones and source address in the same order that was used in above steps in RHEL 7.2 

# iptables -nvL
----- snip ------
Chain INPUT_ZONES_SOURCE (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 IN_A       all  --  *      *       192.20.0.0/16         0.0.0.0/0           [goto] 
    0     0 IN_AR      all  --  *      *       192.20.31.0/24        0.0.0.0/0           [goto] 
    0     0 IN_B       all  --  *      *       192.20.31.55          0.0.0.0/0           [goto] 
----- snip ------

Actual results:
In RHEL 7.3 the order of INPUT_ZONE_SOURCE is inconsistent.

Expected results:
In RHEL 7.2 the custom zone was added in the alphabetic order.

Additional info:

Comment 2 Akhil John 2017-02-13 12:39:38 UTC
 # cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 7.3 (Maipo)
 
 # firewall-cmd --version
0.4.3.2
--------------------------

I have created two zones named A and B as shown:

-----------------------
A
  interfaces: 
  sources: 
  services: 
  ports: 
  masquerade: no
  forward-ports: 
  icmp-blocks: 
  rich rules: 
	
B
  interfaces: 
  sources: 
  services: 
  ports: 
  masquerade: no
  forward-ports: 
  icmp-blocks: 
  rich rules: 
-----------------------

Now, I have just tried to add the source addresses as well as service in the following order:

---------------------
# firewall-cmd --add-source=192.74.133.0/24 --zone=B --permanent
success

# firewall-cmd --add-source=192.74.133.193/32 --zone=A --permanent
success

# firewall-cmd --add-service=ssh --zone=A
success

 # firewall-cmd --list-all --zone=A
A
  interfaces: 
  sources: 192.74.133.193/32
  services: ssh
  ports: 
  masquerade: no
  forward-ports: 
  icmp-blocks: 
  rich rules: 
	
 # firewall-cmd --list-all --zone=B
B
  interfaces: 
  sources: 10.74.133.0/24
  services: 
  ports: 
  masquerade: no
  forward-ports: 
  icmp-blocks: 
  rich rules: 
--------------------------------------------------	

[NOTE - None of my other zone is having ssh service apart from zone A]

Now, here what would be the status if we try to ssh from 192.74.133.193/32 ?

 --> If firewall is checking in alphabetic order then zone A should be preferred and ssh would be accepted.

 --> If it is checking in an order like which is the zone that is best matching with the IP address, then also it should select zone A and we should get the ssh access.

But here ssh is denied:

 # ssh root.140.11
ssh: connect to host 192.74.140.11 port 22: No route to host


I have also tried to reproduce the same in RHEL 7.1 to check whether this a behaviour particularly with RHEL 7.3, but in RHEL 7.1 also I am getting the same output.

----------------
# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 7.1 (Maipo)

# firewall-cmd --version
0.3.9
----------------

Comment 4 Thomas Woerner 2017-03-27 16:08:45 UTC

*** This bug has been marked as a duplicate of bug 1421222 ***