Skip to content

Commit

Permalink
netfilter: nf_flow_table: add missing condition for TCP state check
Browse files Browse the repository at this point in the history
Avoid looking at unrelated fields in UDP packets

Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
  • Loading branch information
Felix Fietkau authored and Pablo Neira Ayuso committed Apr 24, 2018
1 parent b6f27d3 commit 33894c3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions net/netfilter/nf_flow_table_ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
#include <linux/tcp.h>
#include <linux/udp.h>

static int nf_flow_tcp_state_check(struct flow_offload *flow,
struct sk_buff *skb, unsigned int thoff)
static int nf_flow_state_check(struct flow_offload *flow, int proto,
struct sk_buff *skb, unsigned int thoff)
{
struct tcphdr *tcph;

if (proto != IPPROTO_TCP)
return 0;

if (!pskb_may_pull(skb, thoff + sizeof(*tcph)))
return -1;

Expand Down Expand Up @@ -248,7 +251,7 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,
return NF_DROP;

thoff = ip_hdr(skb)->ihl * 4;
if (nf_flow_tcp_state_check(flow, skb, thoff))
if (nf_flow_state_check(flow, ip_hdr(skb)->protocol, skb, thoff))
return NF_ACCEPT;

if (flow->flags & (FLOW_OFFLOAD_SNAT | FLOW_OFFLOAD_DNAT) &&
Expand Down Expand Up @@ -460,7 +463,8 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,
if (unlikely(nf_flow_exceeds_mtu(skb, flow->tuplehash[dir].tuple.mtu)))
return NF_ACCEPT;

if (nf_flow_tcp_state_check(flow, skb, sizeof(*ip6h)))
if (nf_flow_state_check(flow, ipv6_hdr(skb)->nexthdr, skb,
sizeof(*ip6h)))
return NF_ACCEPT;

if (skb_try_make_writable(skb, sizeof(*ip6h)))
Expand Down

0 comments on commit 33894c3

Please sign in to comment.