Closed diekmann closed 8 years ago
Another example:
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:CHAIN - [0:0]
-A FORWARD -j CHAIN
-A CHAIN -p tcp -m tcp --sport 22 -j RETURN
-A CHAIN -p udp -m udp --dport 80 -j RETURN
-A CHAIN -j DROP
COMMIT
The simple firewall overapproximation gives:
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
But we see that we can do better. All the DROP
s for protocols can be preserved because the negated protocols apply due to the primitive protocol in the port:
(! -p tcp ! -p udp, -j DROP)
(! -p udp ! -p tcp, -j DROP)
(! -p tcp -m udp --dpts [0:79], -j DROP)
(! -p tcp -m udp --dpts [81:65535], -j DROP)
(! -p udp -m tcp --spts [0:21], -j DROP)
(! -p udp -m tcp --spts [23:65535], -j DROP)
(-m udp --dpts [0:79] -m tcp --spts [0:21], -j DROP)
(-m udp --dpts [81:65535] -m tcp --spts [0:21], -j DROP)
(-m udp --dpts [0:79] -m tcp --spts [23:65535], -j DROP)
(-m udp --dpts [81:65535] -m tcp --spts [23:65535], -j DROP)
(, -j ACCEPT)
Protocols_Normalize.thy
should contain everything that is necessary.
Fixed in 2eea5dcc4f1b8c33546c72d1673a5c52d93463e5
Once the ports have been normalized, new matches on negated protocols may be introduced. We just need an additional round of protocol optimization to remove impossible matches.
Example:
Output:
Do you see the impossible
tcp
and nottcp
match. This rule needs to be gone.This may be an ideal example to get started ;-) Be warned, you will need to push a lot of invariants through a lot of theorems and functions!
The simple firewall just removes the match on negated protocols and the first rule will match all
tcp
packets. This is a sound overapproximation but we can do way better (by just removing this rule).This is a real-world example: http://serverfault.com/questions/793631/iptables-multiport-and-negation/795234
THIS HAS BEEN FIXED, remaining issue below