<figure><img src="image_1.png" /></figure>

HAL
open science

# Reasoning About Firewall Policies Through Refinement and Composition

Ultan Neville, Simon N. Foley

► To cite this version:

Ultan Neville, Simon N. Foley. Reasoning About Firewall Policies Through Refinement and Composition. 30th IFIP Annual Conference on Data and Applications Security and Privacy (DBSec), Jul 2016, Trento, Italy. pp.268-284, 10.1007/978-3-319-41483-6_19. hal-01633676

HAL Id: hal-01633676

https://inria.hal.science/hal-01633676

Submitted on 13 Nov 2017

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_2.png" /></figure>

Distributed under a Creative Commons Attribution 4.0 International License
Reasoning About Firewall Policies Through
Refinement and Composition

Ultan Neville and Simon N. Foley

Department of Computer Science,
University College Cork, Ireland

**Abstract.** An algebra is proposed for constructing and reasoning about anomaly-free firewall policies. Based on the notion of refinement as safe replacement, the algebra provides operators for sequential composition, union and intersection of policies. The algebra is used to specify and reason about iptables firewall policy configurations. A prototype policy management toolkit has been implemented.

**Keywords:** Firewalls · Algebra · iptables · Anomalies · Policy-composition

# 1 Introduction

Firewall configuration management is complex and error-prone, and a misconfigured policy may permit accesses that were intended to be denied or vice-versa. We regard the specification of a firewall policy as a process that evolves. Threats to, and access requirements for, resources behind a firewall do not usually remain static, and over time, a policy or distributed policy configuration may be updated on an ad-hoc basis, possibly by multiple specifiers/administrators. This can be problematic and may introduce anomalies; whereby the intended semantics of the specified access controls become ambiguous.

In this paper, we present a firewall policy algebra $FW_1$ for constructing and reasoning over anomaly-free policies. The algebra allows policies to be composed in such a way that the result upholds the access requirements of each policy involved; and permits one to reason as to whether some policy is a safe (secure) replacement for another policy in the sense of [11, 14]. The proposed algebra is used to reason about iptables firewall policy configurations. A partial mapping for the iptables filter table is given in the algebra. iptables is a command line utility used to define policies for the Linux kernel firewall Netfilter [1]. We focus on stateful firewall policies that are defined in terms of constraints on source/destination IP/port ranges, the TCP, UDP and ICMP protocols, and additional filter condition attributes.

The primary contribution of this paper is an algebra $FW_1$, that can be used to reason about firewall policies using refinement and composition operators. The effectiveness of the algebra is demonstrated by its application to anomaly detection, and standards compliance.
The paper is organised as follows. Section 2 introduces the notion of adjacency, which is at the heart of reasoning about/composing firewall rules that involve IP/port ranges. In Section 3 we define datatypes for firewall rule attributes, such as IP/port ranges. Section 4 defines the firewall policy algebra $FW_1$. In Section 5, we use $FW_1$ to reason about firewall policies in practice. Section 6 describes a prototype policy management toolkit for iptables and presents some preliminary results. Related work is outlined in Section 7 and Section 8 concludes the paper. The Z notation [19] is used to present the algebra and has been syntax- and type-checked using the fUZZ tool.

## 2 A Theory of Adjacency

A firewall policy is conventionally defined as a sequence of order-dependent rules. A rule is composed of filter conditions and a target action. Filter conditions usually consist of fields/attributes from IP, TCP/UDP headers; with the most commonly used attributes being source/destination IP/port, and network protocol. Target actions are usually *allow* or *deny* [3,8].

Range-based filter condition attributes (IPs/ports) have logical mappings to intervals of $\mathbb{N}$. For example, the port range that includes all ports from SSH up and including HTTP can be written as the interval $[22..80]$. Consider as part of a running example, a system that is capable of enforcing firewall rules where the filter condition attribute for the rules is destination port range. Then if we had a rule that allowed all ports from SSH to HTTP, it may look like: $(i, [22..80], allow)$, where $i$ is the index of the rule in the policy, $[22..80]$ is the required port range, and *allow* means that network traffic matching this pattern be permitted traversal of the firewall. Suppose we had a second rule, that specifies *allow* everything from Quote Of The Day (QOTD) up to and including FTP Control. Then $(j, [17..21], allow)$, specifies that for the rule at index $j$; the required port range $[17..21]$ is allowed. Intuitively, we can see that the port ranges for the rules at index $i$ and index $j$ are *adjacent*, and we may want to join rules $i$ and $j$ into a single rule that looks like $(k, [17..80], allow)$. This notion of adjacency becomes more complex when we consider comparing/composing firewall rules comprising $2..n$ filter condition attributes.

### 2.1 The Adjacency Specification

In this section we define the filter condition attribute relationships of *adjacency*, *disjointness* and *subsumption*. These relationships are at the heart of adjacency, and ultimately the $FW_1$ algebra.

Let $IV[\min, \max]$ be the set of all intervals on the natural numbers, from $\min$ up to and including $\max$. Intervals are defined by their corresponding sets.

$$IV[\min, \max] == \{S : \mathbb{P}\mathbb{N} | \exists \top, \top : S \bullet \forall x : S \bullet \min \le \top \le x \le \top \le \max\}$$

For example, $IV[1, 3]$ gives $\{[1..1], [1..2], [1..3], [2..2], [2..3], [3..3]\}$. For ease of exposition and when no ambiguity arises, we may write an interval as a pair
[⊥..⊤], rather than by the set it defines. Let IPv4 define the set of all possible IPv4 address ranges, and similarly, let Port define the set of all possible network port ranges, where IPv4 == IV[0, 2^32 - 1] ∧ Port == IV[0, 2^16 - 1].

**Adjacency** Two intervals are adjacent if their union defines a single interval. We generalize this to any attribute of type X, whereby for a, b ∈ X, if a ⊠_X b, then a and b are adjacent in the set X.

$$ \boxed{ \begin{array}{r@{\quad}l} \boxed{[X]} & \\ & \phantom{\boxed{[X]}} \boxed{- \mathcal{L}_{-} : \mathbb{P} X \leftrightarrow (X \leftrightarrow X)} \\ & \forall a, b : X \bullet \\ & \qquad a \mathcal{L}_{X} a \wedge (a \mathcal{L}_{X} b \Rightarrow b \mathcal{L}_{X} a) \end{array} } $$

For example, interval [1..2] is adjacent to interval [3..3], thus [1..2] ⊠_IV[1,3] [3..3]. It follows for a, b ∈ N that a ⊠_N b ⇔ (a = b ∨ a + 1 = b ∨ b + 1 = a), and given S, T ∈ P X then S ⊠_P X T ⇔ true.

**Disjointness** Two intervals are disjoint if they don't intersect. Given a, b ∈ X, a ⊠_X b denotes a and b are disjoint in X.

$$ \boxed{ \begin{array}{r@{\quad}l} \boxed{[X]} & \\ & \phantom{\boxed{[X]}} \boxed{- \mathcal{L}_{-} : \mathbb{P} X \leftrightarrow (X \leftrightarrow X)} \\ & \forall a, b : X \bullet \\ & \qquad \neg (a |_X a) \wedge (a |_X b \Rightarrow b |_X a) \end{array} } $$

For example, [1..2] and [3..3] are disjoint, thus [1..2] ⊠_IV[1,3] [3..3]. It follows for a, b ∈ N that a ⊠_N b ⇔ a ≠ b, and given S, T ∈ P X then S ⊠_P X T ⇔ S ∩ T = ∅.

**Subsumption** An interval I subsumes (covers) an interval J, if J ⊆ I. For a, b ∈ X, if a ⊹_X b then b covers a in X. The properties of convexity, transitivity and antisymmetry define ⊹_X as a non-strict partial order over X [5].

$$ \boxed{ \begin{array}{r@{\quad}l} \boxed{[X]} & \\ & \phantom{\boxed{[X]}} \boxed{- \mathcal{L}_{-} : \mathbb{P} X \leftrightarrow (X \leftrightarrow X)} \\ & \forall a, b, c : X \bullet \\ & \qquad a \stackrel{X}{\rightleftharpoons} a \wedge (a \stackrel{X}{\rightleftharpoons} b \wedge b \stackrel{X}{\rightleftharpoons} c \Rightarrow a \stackrel{X}{\rightleftharpoons} c) \wedge (a \stackrel{X}{\rightleftharpoons} b \wedge b \stackrel{X}{\rightleftharpoons} a \Rightarrow a = b) \end{array} } $$

For example, [1..3] covers [3..3], thus [3..3] ⊠_IV[1,3] [1..3]. It follows for a, b ∈ N that a ⊹_N b ⇔ a = b, and given S, T ∈ P X, then S ⊠_P X T ⇔ S ⊆ T.

For a set X and S ∈ P X, the flattening function ⌈S⌋ gives the cover-set for the elements of S.

$$ \boxed{ \begin{array}{r@{\quad}l} \boxed{[X]} & \\ & \phantom{\boxed{[X]}} \boxed{[\mathcal{L}_{-}] : \mathbb{P} X \leftrightarrow \mathbb{P} X} \\ & \forall S : \mathbb{P} X \bullet \\ & \qquad [S] = S \setminus \{a, a' : S \mid a \stackrel{X}{\rightleftharpoons} a' \wedge a \neq a' \bullet a\} \end{array} } $$
**Adjacency Intersection** Under this ordering, the meet, or intersection $S \otimes T$ of $S$, $T \in \alpha[X]$ is defined using subsumption, as the cover-set for the generalized union of all Adjacency-sets, where each element of $(S \otimes T)$ is covered by an element in both $S$ and $T$. Intuitively, this means that the values of the meet are all non-empty intersections of each value in $S$ with each value in $T$. Under the ordering relation $\leq$, $\otimes$ provides a greatest lower bound (glb) operator, and $S \otimes T$ is covered by both $S$ and $T$, that is $(S \otimes T) \leq S$ and $(S \otimes T) \leq T$.

**Adjacency Union** The join of $S$, $T \in \alpha[X]$ is defined using subsumption, as the generalized intersection of all Adjacency-sets, where each element of $(S \oplus T)$ covers an element in either $S$ or $T$. Intuitively, this means that the values of the join are exactly a union of the elements from both $S$ and $T$. Given the definition of ordering using subsumption, it follows that the Adjacency join provides a lowest upper bound (lub) operator. Since $\oplus$ provides a lub operator we have $S \leq (S \oplus T)$ and $T \leq (S \oplus T)$.

**Proposition** The poset $(\alpha[X], \leq)$ forms a distributive lattice with complement operator **not**. This follows from the definition of $\leq$ as a subsumption ordering/an antisymmetric preorder, the properties of **not**, the intuitive definition of the meet of $S$, $T \in \alpha[X]$ as all non-empty intersections of each value in $S$ with each value in $T$, and the intuitive definition of the join operation as an exact union of the elements from both $S$ and $T$ [18].

Given the adjacency, disjointness and subsumption relations; then for $S$, $T \in \alpha[X]$, we define $S \llcorner_{\alpha[X]} T \Leftrightarrow \text{true} \wedge S \mid_{\alpha[X]} T \Leftrightarrow S \otimes T = \perp \wedge S \stackrel{\alpha[X]}{\Leftrightarrow} T \Leftrightarrow S \leq T$.

## 3.2 The Duplet Datatype

A duplet is an ordered pair, where the set of all duplets for types $X, Y$, is defined as $\delta[X, Y]$, where $\delta[X, Y] == X \times Y$. For example, $\delta[\mathcal{IV}[1, 1], \mathcal{IV}[1, 2]]$ gives $\{([1..1],[1..1]), ([1..1],[1..2]), ([1..1],[2..2])\}$, and $\delta[\alpha[IPv4], \alpha[Port]]$ gives the set of all duplets for adjacency-free IP/port-ranges.

Recall the earlier example of the firewall system that supports only destination port range filter conditions. Suppose we want to extend the expressiveness of the policy rules for this system to include a definition for destination IP range. Then $\alpha[\delta[\alpha[IPv4], \alpha[Port]]]$, is the set of all closed subsets of adjacency-free IP/port-range duplets, partitioned by adjacency. Consider two policy requirements, where network traffic is to be allowed to the IP range [1..3] on ports [1..3], and to the IP range [2..4] on ports [2..4]. Then modelling this using sets of adjacency-free duplets, we have $S, T \in \alpha[\delta[\alpha[IPv4], \alpha[Port]]]$, where $S == \{([1..3]), ([1..3])\}$ and $T == \{([2..4]), ([2..4])\}$.

**Duplet Disjointness** A pair of duplets are disjoint if the attributes in the first coordinate are disjoint, or the attributes in the second coordinate are disjoint. For $(a_1, b_1), (a_2, b_2) \in \delta[X, Y]$, then:

$$ (a_1, b_1) |_{\delta[X, Y]} (a_2, b_2) \Leftrightarrow (a_1 |_X a_2 \lor b_1 |_Y b_2) $$
For example, $\neg (S |_{\alpha[\delta[\alpha[IPv4],\alpha[Port]]]} T)$.

**Duplet Adjacency** A pair of duplets are adjacent if the attributes in the first coordinate are adjacent, and the attributes in the second coordinate are not disjoint. Thus, we have:

$$ (a_1, b_1) \lhd_{\delta[X, Y]} (a_2, b_2) \Leftrightarrow (a_1 \lhd_X a_2 \wedge \neg (b_1 |_Y b_2)) $$

For example, $S \lhd_{\alpha[\delta[\alpha[IPv4],\alpha[Port]]]} T$.

**Duplet Subsumption** A duplet is distinguished from a standard ordered pair, whereby we explicitly define orderings separately in each coordinate. For example, suppose we wanted to join adjacent policies S and T, then under a 'standard' Cartesian product ordering we have $S \oplus T = ({[1..4]}$, {[1..4]}). This obviously results in an overly permissive policy, conversely; an overly restrictive policy if we were composing deny rules. A duplet $(a_1, b_1)$ covers a duplet $(a_2, b_2)$ in $\delta[X, Y]$, if $a_1$ covers $a_2$ in X, and $b_2$ covers $b_1$ in Y. Thus:

$$ (a_2, b_2) \stackrel{\delta[X, Y]}{\leftarrow} (a_1, b_1) \Leftrightarrow (a_2 \stackrel{X}{\leftarrow} a_1 \wedge b_1 \stackrel{Y}{\leftarrow} b_2) $$

Then we have $S \oplus T = ({[1..4]}, {[2..3]}), ({[1..3]}, {[1..1]}), ({[2..4]}, {[4..4]}).$ Thus, the join, or union $(S \oplus T)$ of S and T, defines the adjacency-free coalescence of all duplets from S and T. For reasons of space, we do not give the implementation definition for this operation.

## 3.3 The Stateful/Protocol Datatype

In this section, we define the network protocols of interest for the model and encode a notion of state. The iptables command line utility allows the end-user to specify one (or all) of seven different protocols in a rule [1]. For reasons of space, we focus only on the TCP, UDP and ICMP protocols.

Let *Flags* be the set of TCP flags, where *Flags* ::= syn | ack | fin | psh | rst | urg. The TCP protocol is defined as the set of all sets of pairs of sets of *Flags*, whereby for each pair; the first set contains the flags that are to be examined in a packet-header, and the second set contains the flags that must be set (in a packet-header). In [1], these are referred to as the *comp* and *mask* values for a packet, respectively. Let *TCP* be the set of all sets of comp/mask pairs, where *TCP* == P(P *Flags* × P *Flags*). Let [*TypesCodes*] be the set of all valid ICMP Type/Code pairs. For simplicity and reasons of space, we do not consider how the values of *TypesCodes* may be constructed, other than to assume that the usual human-readable notation can be used, such as (8,0) and (17,0) ∈ *TypesCodes*. The iptables *conntrack* modules' *statelist* [1] may be defined as follows. Let *State* be the set of connection tracking states for a packet connection, where *State* ::= new | established | related | invalid | untracked.

Let *Protocol* define the set of all protocols, given as the set of all duplets over *TCP*, *UDP* ([0..1]), *ICMP* (P *TypesCodes*) and the set of all sets of connection tracking states (P *State*).

$$ \mathit{Protocol} == \delta[\mathit{TCP}, \delta[\{0, 1\}, \delta[\mathbb{P} \mathit{TypesCodes}, \mathbb{P} \mathit{State}]]] $$
*Proposition* The Protocol datatype forms a product-lattice structure. This follows from the definition of Protocol as the product of powerset/binary lattices [5].

# 4 The $FW_1$ Policy Algebra

In this section we define an algebra $FW_1$, for constructing and reasoning about anomaly-free firewall policies. We focus on stateful firewall policies that are defined in terms of constraints on source/destination IP/port ranges, the TCP, UDP and ICMP protocols.

A filter condition is a five-tuple $(s, sprt, d, dprt, p)$, representing network traffic originating from source IP range $s$, with source port range $sprit$, destined for destination IP range $d$, with destination port range $dprt$, using stateful-protocols $p$. Let FC define the set of all filter conditions, where:

$$FC == \delta[\alpha[IPv4], \delta[\alpha[Port], \delta[\alpha[IPv4], \delta[\alpha[Port], Protocol]]]]$$

A firewall policy defines the filter conditions that may be allowed or denied by a firewall. Let Policy define the set of all firewall policies, whereby:

$$Policy == \{A, D : \alpha[FC] | \forall a : A; d : D \bullet a |_{FC} d\}$$

A firewall policy $(A, D) \in Policy$ defines that a filter condition $f \in A$ should be allowed by the firewall, while a filter condition $f \in D$ should be denied. Given $(A, D) \in Policy$ then $A$ and $D$ are disjoint: this avoids any contradiction in deciding whether a filter condition should be allowed or denied. Given that $A$ and $D$ are also both adjacency-free; then Policy defines the set of anomaly-free firewall policies in the sense that they contain no redundancy, shadowing, or other anomalies [4].

Note that $(A, D) \in Policy$ need not partition $[FC]$; the allow and deny sets define the filter conditions to which the policy explicitly applies, and an implicit default decision is applied for those filter conditions in $[FC] \setminus \alpha[FC] (A \oplus D)$. For the purposes of modelling iptables firewalls it is sufficient to assume default deny, though we observe that $FW_1$ can also be used to reason about default allow firewall policies. The policy destructor functions allow and deny are analogous to functions first and second for ordered pairs:

$$\begin{array}{l} \text{allow, deny : Policy} \rightarrow \alpha[FC] \\ \forall A, D : \alpha[FC] \bullet \\ \qquad \text{allow}(A, D) = A \land \text{deny}(A, D) = D \end{array}$$

*Policy Refinement* An ordering can be defined over firewall policies, whereby given $P, Q \in Policy$ then $P \sqsubseteq Q$ means that $P$ is no less restrictive than $Q$, that is, any filter condition that is denied by $Q$ is denied by $P$. Intuitively, policy $P$ is considered to be a *safe replacement* for policy $Q$, in the sense of [11, 14] and any firewall that enforces policy $Q$ can be reconfigured to enforce policy $P$ without any loss of security. The set Policy forms a lattice under the safe replacement ordering and is defined as follows.
<figure><img src="image_3.png" /></figure>

Formally, $P \sqsubseteq Q$ iff every filter condition allowed by $P$ is allowed by $Q$ and that any filter conditions explicitly denied by $Q$ are also explicitly denied by $P$. Note that in this definition we distinguish between filter conditions explicitly denied in the policy versus those implicitly denied by default. This means that, everything else being equal, a policy that explicitly denies a filter condition is considered more restrictive than a policy that relies on the implicit default-deny for the same network traffic pattern. Safe replacement is defined as the Cartesian product of Adjacency orderings over allow and deny sets and it therefore follows that $(Policy, \sqsubseteq)$ is a poset.

$\perp$ and $\top$ define the most restrictive and least restrictive policies, that is, for any $P \in Policy$ we have $\perp \sqsubseteq P \sqsubseteq \top$. Thus, for example, any firewall enforcing a policy $P$ can be safely reconfigured to enforce the (not very useful) firewall policy $\perp$.

**Policy Intersection** Under this ordering, the meet $P \sqcap Q$, of two firewall policies $P$ and $Q$ is defined as the policy that denies any filter condition that is explicitly denied by either $P$ or $Q$, but allows filter conditions that are allowed by both $P$ and $Q$. Intuitively, this means that if a firewall is required to enforce both policies $P$ and $Q$, it can be configured to enforce the policy $(P \sqcap Q)$ since $P \sqcap Q$ is a safe replacement for both $P$ and $Q$, that is; $(P \sqcap Q) \sqsubseteq P$ and $(P \sqcap Q) \sqsubseteq Q$. Given the definition of safe replacement as a product of two Adjacency lattices, it follows that the policy meet provides the glb operator. Thus, $P \sqcap Q$ provides the 'best'/least restrictive safe replacement (under $\sqsubseteq$) for both $P$ and $Q$.

**Policy Union** The join of two firewall policies $P$ and $Q$ is defined as the policy that allows any filter condition allowed by either $P$ or $Q$, but denies filter conditions that are explicitly denied by both $P$ and $Q$. Intuitively, this means that a firewall that is required to enforce either policy $P$ or $Q$ can be safely configured to enforce the policy $(P \sqcup Q)$. Since $\sqcup$ provides a lub operator we have $P \sqsubseteq (P \sqcup Q)$ and $Q \sqsubseteq (P \sqcup Q)$.

**Proposition** The set of all policies *Policy* forms a lattice under safe replacement. This follows from the definition of $\sqsubseteq$ as a Cartesian product of two Adjacency lattice orderings.
## 4.1 Constructing Firewall Policies

The lattice of policies $FW_1$ provides us with an algebra for constructing and interpreting firewall policies. The following constructor functions are used to build primitive policies. Given a set of adjacency-free filter conditions $A$, then (Allow $A$) is a policy that allows filter conditions in $A$, and (Deny $D$) is a policy that explicitly denies filter conditions in $D$.

$$ \left| \begin{array}{l} \text{Allow,} \\ \text{Deny} : \alpha[FC] \to \text{Policy} \\ \forall S : \alpha[FC] \bullet \\ \qquad \text{Allow } S = (S, \emptyset) \land \text{Deny } S = (\emptyset, S) \end{array} \right. $$

This provides what we refer to as a *weak* interpretation of allow and deny. Network traffic patterns that are not explicitly mentioned in parameter $S$ are default-deny and therefore are not specified in the deny set of the policy. The following provides us with a *strong* interpretation for these constructors:

$$ \left| \begin{array}{l} \text{Allow}^{+}, \\ \text{Deny}^{+} : \alpha[FC] \to \text{Policy} \\ \forall S : \alpha[FC] \bullet \\ \qquad \text{Allow}^{+} S = (S, \mathbf{not } S) \land \text{Deny}^{+} S = (\mathbf{not } S, S) \end{array} \right. $$

In this case (Allow$^+$ $A$) allows filter conditions specified in $A$, while explicitly denying all other filter conditions, and (Deny$^+$ $D$) denies filter conditions specified in $D$ while allowing all other filter conditions.

**Proposition** A firewall policy $P \in \text{Policy}$ can be decomposed into its corresponding allow and deny sets, and re-constructed using the algebra; for any $(A, D) \in \text{Policy}$, since $A$ and $D$ are disjoint then:

$$ \begin{align*} (\text{Allow}^+ A) \sqcup (\text{Deny } D) &= (A, [FC] \setminus_{\alpha[FC]} A) \sqcup (\emptyset, D) \\ &= (A, D) \\ &= (\text{Allow } A) \sqcap (\text{Deny}^+ D) \end{align*} $$

# 5 Reasoning About Policies in Practice

**Sequential Composition** A firewall policy is conventionally constructed as a sequence of rules, whereby for a given network packet, the decision to allow or deny that packet is checked against each policy rule, starting from the first, in sequence, and the first rule that matches gives the result that is returned. The algebra $FW_1$ can be extended to include a similar form of sequential composition of policies. The policy constructions above can be regarded as representing the individual rules of a conventional firewall policy.

Let (Allow $A$) $\otimes$ $Q$ denote a sequential composition of an allow rule (Allow $A$) with policy $Q$ with the interpretation that a given network packet matched in
A is allowed; if it does not match in A then policy Q is enforced. The resulting policy either: allows filter conditions in A (and denies all other filter conditions), or allows/denies filter conditions in accordance with policy Q. We define:

$$ 
\begin{align*}
(\text{Allow } A) \flat Q &= (\text{Allow}^+ A) \sqcup Q \\
&= ((A \oplus \text{allow}(Q)), ((\lceil FC \rceil \setminus \alpha_{[FC]} A) \otimes \text{deny}(Q))) \\
&= ((A \oplus \text{allow}(Q)), (\text{deny}(Q) \setminus \alpha_{[FC]} A))
\end{align*}
$$

which is as expected. A similar definition can be provided for the sequential composition $(\text{Deny } D) \flat Q$, whereby a given network packet that is matched in $D$ is denied; if it does not match in $D$ then policy $Q$ is enforced. We define:

$$ 
\begin{align*}
(\text{Deny } D) \flat Q &= (\text{Deny}^+ D) \sqcap Q \\
&= (\text{allow}(Q) \setminus \alpha_{[FC]} D, \text{deny}(Q) \oplus D)
\end{align*}
$$

While in practice its usual to write a firewall policy in terms of many constructions of allow and deny rules, in principle, any firewall policy $P \in \mathcal{P}$ can be defined in terms of one allow policy $(\text{Allow } \text{allow}(P))$ and one deny policy $(\text{Deny } \text{deny}(P))$ and since the allow and deny sets of $P$ are disjoint we have $P \flat Q = (\text{Deny } \text{deny}(P)) \flat (\text{Allow } \text{allow}(P)) \flat Q$. We define this as:

$$ 
\left| 
\begin{array}{l}
\neg_{\flat} : \mathcal{P} \times \mathcal{P} \to \mathcal{P} \\
\forall \mathcal{F}W_1; P, Q : \mathcal{P} \bullet \\
P \flat Q = (Q \sqcup (\text{Allow}^+(\text{allow}(P)))) \sqcap (\text{Deny}^+(\text{deny}(P)))
\end{array}
\right| 
$$

Let Rule define the set of all firewall rules, where Rule ::= **allow** $\langle\langle FC \rangle\rangle$ | **deny** $\langle\langle FC \rangle\rangle$. We define a rule interpretation function as:

$$ 
\left| 
\begin{array}{l}
\mathcal{I} : \mathcal{R}ule \to \mathcal{P}olicy \\
\forall f : \mathcal{F}W_1; P : \mathcal{P}olicy \bullet \\
\mathcal{I}(\mathcal{A}llow f) = \mathcal{A}llow(\{f\}) \wedge \mathcal{I}(\mathcal{D}eny f) = \mathcal{D}eny(\{f\})
\end{array}
\right| 
$$

A firewall policy is defined as a sequence of rules $\langle r_1, r_2, \dots, r_n \rangle$, for $r_i \in \mathcal{R}ule$, and is encoded in the policy algebra as $\mathcal{I}(r_1) \flat \mathcal{I}(r_2) \flat \dots \flat \mathcal{I}(r_n)$.

**Policy Negation** The policy negation of $P \in \mathcal{P}$ allows filter conditions explicitly denied by $P$ and explicitly denies filter conditions allowed by $P$. We define:

$$ 
\left| 
\begin{array}{l}
\mathbf{not} : \mathcal{P}olicy \to \mathcal{P}olicy \\
\forall \mathcal{F}W_1; P : \mathcal{P}olicy \bullet \\
\mathbf{not} P = (\text{Allow}^+(\text{deny}(P))) \sqcup (\text{Deny}(\text{allow}(P)))
\end{array}
\right| 
$$

From this definition it follows that **not** $P$ is simply $(\text{deny}(P), \text{allow}(P))$ and thus **not** $(\text{Deny } D) = (\text{Allow } D)$ and **not** $(\text{Allow } A) = (\text{Deny } A)$. Note however, that in general policy negation does not define a complement operator in the algebra $\mathcal{F}W_1$, that is, it not necessarily the case that $(P \sqcup \mathbf{not} P) = \top$ and $(P \sqcap \mathbf{not} P) = \bot$.
## 5.1 Anomaly Analysis

A firewall policy is conventionally constructed as a sequence of order-dependent rules, and when a network packet matches with two or more policy rules, the policy is anomalous [3,4,8]. By definition, the adjacency-free allow and deny sets of some $P \in \mathit{Policy}$ are disjoint, therefore P is anomaly-free by construction. We can however define anomalies using the algebra; by considering how a policy changes when composed with other policies.

**Redundancy** A policy P is redundant given policy Q if their composition results in no difference between the resulting policy and Q, in particular, if $P \triangleleft Q = Q$.

**Shadowing** Some part of policy Q is shadowed by the entire policy P in the composition $P \triangleleft Q$ if the filter condition constraints that are specified by P contradict the constraints that are specified by Q, in particular, if $(\mathbf{not} P) \triangleleft Q = Q$. This is a very general definition for shadowing. Perhaps a more familiar interpretation of this definition is one where the policy P is a specific allow/deny rule that shadows a part or all of the policy with which it is composed. Recall that $(\mathbf{not}(\mathit{Allow} A)) = (\mathit{Deny} A)$ and, for example, in $(\mathit{Allow} A) \triangleleft Q$ all or part of policy Q is shadowed by the rule/primitive policy $(\mathit{Allow} A)$ if Q denies the filter conditions specified in A, that is, $(\mathit{Deny} A) \triangleleft Q = Q$. Similarly, in $(\mathit{Deny} D) \triangleleft Q$ part or all of policy Q is shadowed by the rule/primitive policy $(\mathit{Deny} D)$ if $(\mathbf{not} (\mathit{Deny} D)) \triangleleft Q = Q$. Further definitions for shadowing may be constructed using the algebra. For example, an initial interpretation of the generalisation anomaly [3] in the composition $P \triangleleft Q$; is where Q is generalised by P if all of P shadows (specifically) part of Q. We are currently investigating how this and other anomalies can be reasoned about within the algebra.

**Inter-policy Anomalies** Anomalies can also occur between the different policies of distributed firewall configurations [4]. In the following, assume that P is a policy on an *upstream* firewall and Q is a policy on a *downstream* firewall.

An inter-redundancy anomaly exists between policies P and Q if some part of Q is redundant to some part of P, whereby the target action of the redundant filter conditions is *deny*. Given some set of filter conditions A denied by P, and some set of filter conditions B denied by Q, if $(\mathit{Deny} A) \triangleleft (\mathit{Deny} B) = (\mathit{Deny} A)$ then there exists an inter-redundancy between P and Q.

An inter-shadowing anomaly exists between policies P and Q if some part of Q's allows are shadowed by some part of P's denies. Given some set of filter conditions A denied by P, and some set of filter conditions B allowed by Q, if $(\mathit{Deny} A) \triangleleft (\mathit{Allow} B) = (\mathit{Deny} A)$, then there is an inter-shadowing anomaly between P and Q.

An inter-spuriousness anomaly exists between policies P and Q if some part of Q's denies are shadowed by some part of P's allows. Again, given some set of filter conditions A allowed by P, and some set of filter conditions B denied by Q, if $(\mathit{Allow} A) \triangleleft (\mathit{Deny} B) = (\mathit{Allow} A)$, then there exists an inter-spuriousness anomaly between P and Q.
## 5.2 Standards Compliance

RFC 5735 [7], details fifteen IPv4 address blocks/ranges that have been assigned by the Internet Assigned Numbers Authority (IANA) for specialized/global purposes. Some of these address spaces may appear on the Internet, and may be used legitimately outside a single administrative domain, however, while the assigned values of the ranges do not directly raise security issues; unexpected use may indicate an attack [7]. For example, packets with a source IP address from the private address space 172.16.0.0/12, arriving on the Wide Area Network interface of a network router, may be considered spoofed, and may be part of a Denial of Service (DoS), or Distributed DoS attack.

*RFC 5735 Compliance* An IP spoof-mitigation compliance policy RFC5735 is defined. Best practice recommendations are implemented for each of the fifteen specialized IP ranges in [7], resulting in one hundred and twenty iptables *deny* rules. In [10], we defined this *deny* ruleset for a firewall management tool, we do not give the definition here for reasons of space. The compliance policy terminates with a final iptables rule that specifies all other traffic be permitted. To model these iptables rules in the algebra, we define some additional filter condition attributes and provide a more formal definition of RFC5735.

*An Extended Firewall Policy* An attribute for the iptables filter table chains may be defined as *Chain* ::= *input* | *output* | *forward*. Direction-based filtering may be given as *Dir* ::= *ingress* | *egress*, and the set of all sets of interfaces on a machine may be given as *P Iface*, where for simplicity, we assume elements of *Iface* resemble *eth0*, *wlan0*, *tun0*, etc. Let *AdditionalFC* be the set of all duplets for additional filter condition attributes of interest for this paper, whereby:

$$AdditionalFC == \delta[\mathbb{P} \mathit{Chain}, \delta[\mathbb{P} \mathit{Dir}, \mathbb{P} \mathit{Iface}]]$$

A revised definition for the set of all filter conditions $FC_I$ is given as:

$$FC_I == \delta[\alpha[\mathit{IPv4}], \delta[\alpha[\mathit{Port}]], \delta[\alpha[\mathit{IPv4}]], \delta[\alpha[\mathit{Port}]], \delta[\mathit{Protocol}, AdditionalFC]]]]$$

A revised definition for the set of all policies *Policy* is given as:

$$Policy_I == \{A, D : \alpha[FC_I] | \forall a : A; d : D \bullet a |_{FC_I} d\}$$

The compliance policy RFC5735 ∈ *Policy* defines the minimum requirement for what it means for some perimeter network firewall policy to mitigate the threat of IP spoofing for all traffic, in accordance with RFC 5735. Thus, we have for all *P* ∈ *Policy*, if *P* ⊆ RFC5735, then *P* complies with the best practice recommendations outlined in [7] for IP spoof-mitigation.

## 6 Encoding and Evaluating iptables Policies

A prototype policy management toolkit has been implemented in Python for iptables. We reason over *Policy* policies using (§, ⊕, ⊖); time-based performance-analysis tests were conducted. The test-bed for the experiments was a 64-Bit
Ubuntu 14.04 LTS OS, running on a Dell Latitude E6430, with a quad-core Intel i5-3320M processor and 4GB of RAM. Every experiment was conducted three times; the median result chosen for inclusion in this paper. Overall, the results are promising.

*Evaluating Sequential Policy Composition* Two datasets were generated for experimentation. Each dataset consists of iptables policies of size 2⁴ .. 2¹¹. One dataset contains policies where no rule is adjacent to any other rule (other than itself), and the other dataset consists of policies where every new rule is adjacent to the previous rule; to ensure the maximum number of possible rules are generated as a result of composition. The rules all have a target action of *allow*. The implementation parses the system's currently enforced iptables ruleset $\langle r_1, r_2 .. r_n \rangle$ by chain, and then normalizes each rule to a primitive/singleton policy $\langle \mathcal{I}(r_1), \mathcal{I}(r_2) .. \mathcal{I}(r_n) \rangle$. The overall policy for the chain is evaluated as $\mathcal{I}(r_1) \oplus \mathcal{I}(r_2) \oplus .. \oplus \mathcal{I}(r_n)$. For reasons of space, we give the results for the sequential composition experiments as lists of tuples $(\mathcal{P}, \mathcal{T}(\mathcal{P}))$, where $\mathcal{P}$ is the policy named by the number of iptables rules it was constructed from for the experiment, and $\mathcal{T}(\mathcal{P})$ is the time taken in seconds for the evaluation of the sequential composition of the rules in $\mathcal{P}$. For the adjacent dataset we have [(2⁴, 0.80), (2⁵, 2.02), (2⁶, 5.13), (2⁷, 15.32), (2⁸, 51.18), (2⁹, 183.42), (2¹⁰, 707.15), (2¹¹, 2792.81)]. We observe that the evaluation time for the sequential composition of 2⁹ rules is around three minutes, and $\mathcal{T}(2¹¹)$ is approximately forty six minutes. For the non-adjacent dataset, we have [(2⁴, 0.07), (2⁵, 0.13), (2⁶, 0.29), (2⁷, 0.67), (2⁸, 1.73), (2⁹, 4.98), (2¹⁰, 16.09), (2¹¹, 57.81)], and we see that for the largest ruleset, 2¹¹, $\mathcal{T}(2¹¹)$ is approximately one minute.

*Evaluating Policy Union* Experiments were conducted to test policy lub, whereby each policy in the adjacent dataset was split into two policies, where the first policy contains the odd (index) rules from the original policy, and the second policy contains the even (index) rules from the original policy. Then for each $P, Q \in \text{Policy}_I$ in this split dataset, the time taken for the operation $P \sqcup Q$ is encoded in the matrix in Table 1. The times taken for composition of policies of equal size are approximately the same as (slightly less than) those for the results given in the adjacent sequential composition dataset. This is highlighted through the diagonal in the matrix, and is as expected; given that we used all *allow* rules.

*Evaluating Policy Compliance* A further dataset consisting of iptables policies of size 2⁴ .. 2¹¹ was generated to test policy compliance. Each policy in this dataset was RFC 5735 compliant by construction. Results are again given as a list of tuples $(\mathcal{P}, \mathcal{T}(\mathcal{P}))$, where $\mathcal{P}$ is the policy named by the number of iptables rules it was constructed from for the experiment, and $\mathcal{T}(\mathcal{P})$ is the time taken in seconds for the evaluation of $\mathcal{P} \subseteq \text{RFC5735}$. We have [(2⁴, 1.07 × 10⁻³), (2⁵, 1.62 × 10⁻³), (2⁶, 2.23 × 10⁻³), (2⁷, 3.50 × 10⁻³), (2⁸, 5.24 × 10⁻³), (2⁹, 1.03 × 10⁻²), (2¹⁰, 2.76 × 10⁻²), (2¹¹, 4.95 × 10⁻²)], and we see that for each $\mathcal{P} \in \text{Policy}_I$ in this compliance-dataset $\mathcal{T}(\mathcal{P})$ is negligible.
<table><caption>**Table 1.** Time taken to compute $P \sqcup Q$ (in seconds)</caption><thead><tr><th>P</th><th>2<sup>3</sup></th><th>2<sup>4</sup></th><th>2<sup>5</sup></th><th>2<sup>6</sup></th><th>2<sup>7</sup></th><th>2<sup>8</sup></th><th>2<sup>9</sup></th><th>2<sup>10</sup></th></tr></thead><tbody><tr><td>2<sup>3</sup></td><td>0.65</td><td>0.79</td><td>0.81</td><td>0.99</td><td>1.40</td><td>2.51</td><td>5.73</td><td>16.93</td></tr><tr><td>2<sup>4</sup></td><td>0.79</td><td>1.86</td><td>2.09</td><td>2.32</td><td>2.91</td><td>4.50</td><td>8.83</td><td>22.19</td></tr><tr><td>2<sup>5</sup></td><td>0.81</td><td>2.09</td><td>4.97</td><td>5.45</td><td>6.78</td><td>9.17</td><td>15.50</td><td>32.89</td></tr><tr><td>2<sup>6</sup></td><td>0.99</td><td>2.32</td><td>5.45</td><td>14.70</td><td>17.01</td><td>21.93</td><td>32.29</td><td>57.47</td></tr><tr><td>2<sup>7</sup></td><td>1.40</td><td>2.91</td><td>6.78</td><td>17.01</td><td>48.85</td><td>58.44</td><td>76.94</td><td>119.28</td></tr><tr><td>2<sup>8</sup></td><td>2.51</td><td>4.50</td><td>9.17</td><td>21.93</td><td>58.44</td><td>179.87</td><td>217.34</td><td>294.56</td></tr><tr><td>2<sup>9</sup></td><td>5.73</td><td>8.83</td><td>15.50</td><td>32.29</td><td>76.94</td><td>217.34</td><td>699.11</td><td>839.49</td></tr><tr><td>2<sup>10</sup></td><td>16.93</td><td>22.19</td><td>32.89</td><td>57.47</td><td>119.28</td><td>294.56</td><td>839.49</td><td>2722.63</td></tr></tbody></table>

# 7 Related Work

In [3], a firewall policy is modelled as a single rooted tree, relations between rules are defined on a pairwise basis, and definitions for firewall configuration anomalies are provided. In [4], the work is extended to distributed firewall policies. In [8], a firewall policy is modelled as a linked-list, and in [13] rule relations within a policy are modelled in a directed graph. In [20] Binary Decision Diagrams are used to model firewall rulesets. We model a firewall policy as an ordered pair of disjoint adjacency-free sets, where the set of policies *Policy* forms a lattice under $\sqsubseteq$, and each $P \in Policy$ is anomaly-free by construction. In [3, 4, 8, 13, 20] an algorithmic approach is taken to detect/resolve anomalies. We follow an algebraic (as opposed to algorithmic) approach towards modelling anomalies in a single policy, and across a distributed policy configuration through policy composition. In earlier work [12], we developed the algebra $FW_0$, and used it to reason over host-based and network access controls in OpenStack. In the $FW_0$ algebra, we focused on stateless firewall policies that are defined in terms of constraints on individual IPs, ports and protocols. In this paper, the algebra $FW_1$ is defined over stateful firewall policies constructed in terms of constraints on source/destination IP/port ranges, the TCP, UDP and ICMP protocols, and additional filter condition attributes. We argue that $FW_1$ gives a more expressive means for reasoning over OpenStack security group and perimeter firewall configurations. In [16], *cloud calculus* is used to capture the topology of cloud computing systems and the global firewall policy for a given configuration. This paper could extend the work in [16], given that $FW_1$ may be used in conjunction with cloud calculus to guarantee anomaly-free dynamic firewall policy reconfiguration, where the ordering relation $\sqsubseteq$ may give a viable alternative for the given equivalence relation defined over ‘cloud’ terms for the formal verification of firewall policy preservation after a live migration. In [21], a firewall policy algebra is proposed. However, the authors note that an anomaly-free composition is not guaranteed as a result of using their algebraic operators. Our work differs, in that policy composition under the $\sqcap, \sqcup$ and $\sqsupset$ operators defined in this paper all
result in anomaly-free policies. In [2], an abstract model for Netfilter is proposed, and a language to specify firewall configurations is introduced that is similar to the XML-based access control language supported by Or-BAC presented in [9]. In [17], a formal model of Netfilter is defined, and the properties of reachabil- ity and cyclicity within firewall policy configurations are investigated. In [6], a theorem-proving approach is used to reason about firewall policies. The pro- posed algebra $FW_1$ is used to reason about and compose anomaly-free policies and therefore we do not have to worry about dealing with conflicts that may arise. Anomaly conflicts are dealt with in composition by computing anomaly- free policies, rather than using techniques such as [15] to resolve conflicts in policy decisions. Encoding a definition for Network Address Translation in $FW_1$ is a topic for future research.

## 8 Conclusion

A policy algebra $FW_1$ is defined in which firewall policies can be specified and reasoned about. At the heart of this algebra is the notion of safe replacement, that is, whether it is secure to replace one firewall policy by another. The set of policies form a lattice under safe replacement and this enables consistent opera- tors for safe composition to be defined. Policies in this lattice are anomaly-free by construction, and thus, composition under glb and lub operators preserves anomaly-freedom. A policy sequential composition operator is also proposed that can be used to interpret firewall policies defined more conventionally as sequences of rules. The algebra can be used to characterize anomalies, such as shadowing and redundancy, that arise from sequential composition. Best practice policy compliance may be defined using $\sqsubseteq$. The algebra $FW_1$ provides a formal inter- pretation of the network access controls for a partial mapping to the iptables filter table. $FW_1$ is a generic algebra and can also be used to model other fire- wall systems. The results in this paper are described in terms of the algebra $FW_1$, for stateful firewall policies that are defined in terms of constraints on source/destination IP/port ranges, the TCP, UDP and ICMP protocols, and additional filter condition attributes.

*Acknowledgement* This work was supported, in part, by Science Foundation Ireland under grant SFI 10/CE/I1853 and Irish Research Council/Chist-ERA.

## References

1. Linux iptables - CLI for configuring the Linux kernel firewall, Netfilter. http://www.netfilter.org/projects/iptables/index.html.

2. P. Adão, C. Bozzato, G. Dei Rossi, R. Focardi, and F. L. Luccio. Mignis: A semantic based tool for firewall configuration. In *Proceedings of the 2014 IEEE 27th Computer Security Foundations Symposium*, pages 351–365. IEEE, 2014.

3. E. Al-Shaer and H. Hamed. Firewall policy advisor for anomaly discovery and rule editing. In *Integrated Network Management*, volume 246 of *IFIP Conference Proceedings*, pages 17–30. Kluwer, 2003.
4. E. Al-Shaer, H. Hamed, R. Boutaba, and M. Hasan. Conflict classification and analysis of distributed firewall policies. *IEEE Journal on Selected Areas in Communications*, 23(10):2069–2084, 2005.

5. G. Birkhoff. *Lattice Theory. Volume XXV of American Mathematical Society Colloquium Publications*. American Mathematical Society, 3rd edition, 1967.

6. A. D. Brucker, L. Brügger, and B. Wolff. Formal firewall conformance testing: An application of test and proof techniques. *Softw. Test. Verif. Reliab.*, 25(1):34–71, January 2015.

7. M. Cotton and L. Vegoda. Special Use IPv4 Addresses. RFC 5735, January 2010.

8. F. Cuppens, N. Cuppens-Boulahia, and J. García-Alfaro. Detection and removal of firewall misconfiguration. In *Proceedings of the 2005 IASTED International Conference on Communication, Network and Information Security*, volume 1, pages 154–162, 2005.

9. F. Cuppens, N. Cuppens-Boulahia, T. Sans, and A. Miège. A formal approach to specify and deploy a network security policy. In *Formal Aspects in Security and Trust*, pages 203–218. Springer US, 2005.

10. W. M. Fitzgerald, U. Neville, and S. N. Foley. MASON: Mobile autonomic security for network access controls. *Journal of Information Security and Applications*, (JISA), 18(1):14–29, 2013.

11. S. N. Foley. The specification and implementation of commercial security requirements including dynamic segregation of duties. In *ACM Conference on Computer and Communications Security*, pages 125–134, 1997.

12. S. N. Foley and U. Neville. A firewall algebra for openstack. In *2015 IEEE Conference on Communications and Network Security, CNS 2015, Florence, Italy, September 28-30, 2015*, pages 541–549, 2015.

13. A. Hari, S. Suri, and G. Parulkar. Detecting and resolving packet filter conflicts. In *INFOCOM 2000. Nineteenth Annual Joint Conference of the IEEE Computer and Communications Societies. Proceedings. IEEE*, volume 3, pages 1203–1212. IEEE, 2000.

14. J. L. Jacob. The varieties of refinement. In J. M. Morris and R. C. Shaw, editors, *Proceedings of the 4th Refinement Workshop*, pages 441–455. Springer-Verlag, 1991.

15. S. Jajodia, P. Samarati, M. L. Sapino, and V. S. Subrahmanian. Flexible support for multiple access control policies. *ACM Trans. Database Syst.*, 26(2):214–260, 2001.

16. Y. Jarraya, A. Eghtesadi, M. Debbabi, Y. Zhang, and M. Pourzandi. Cloud calculus: Security verification in elastic cloud computing platform. In *Collaboration Technologies and Systems (CTS), 2012 International Conference on*, pages 447–454. IEEE, 2012.

17. A. Jeffrey and T. Samak. Model checking firewall policy configurations. In *Policies for Distributed Systems and Networks, 2009. POLICY 2009. IEEE International Symposium on*, pages 60–67. IEEE, 2009.

18. L. Levine. (Lemma 3, Example 6.) Algebraic Combinatorics, Lecture 8, Retrieved: http://www.math.cornell.edu/~levine/18.312/alg-comb-lecture-8.pdf, March 2011.

19. J. M. Spivey. *The Z Notation: A Reference Manual*. Series in Computer Science. Prentice Hall International, 2nd edition, 1992.

20. L. Yuan, H. Chen, J. Mai, C. Chuah, Z. Su, and P. Mohapatra. Fireman: A toolkit for firewall modeling and analysis. In *Security and Privacy, 2006 IEEE Symposium on*, pages 15 pp. – 213. IEEE, 2006.

21. H. Zhao and S. M. Bellovin. Policy algebras for hybrid firewalls. Technical Report CUCS-017-07, Department of Computer Science, Columbia University, March 2007.