Skip to content

Commit

Permalink
ip_vti/ip6_vti: Preserve skb->mark after rcv_cb call
Browse files Browse the repository at this point in the history
The vti6_rcv_cb and vti_rcv_cb calls were leaving the skb->mark modified
after completing the function.  This resulted in the original skb->mark
value being lost.  Since we only need skb->mark to be set for
xfrm_policy_check we can pull the assignment into the rcv_cb calls and then
just restore the original mark after xfrm_policy_check has been completed.

Signed-off-by: Alexander Duyck <[email protected]>
Signed-off-by: Steffen Klassert <[email protected]>
  • Loading branch information
Alexander Duyck authored and klassert committed May 28, 2015
1 parent 049f8e2 commit d55c670
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions net/ipv4/ip_vti.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ static int vti_input(struct sk_buff *skb, int nexthdr, __be32 spi,
goto drop;

XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip4 = tunnel;
skb->mark = be32_to_cpu(tunnel->parms.i_key);

return xfrm_input(skb, nexthdr, spi, encap_type);
}
Expand All @@ -91,6 +90,8 @@ static int vti_rcv_cb(struct sk_buff *skb, int err)
struct pcpu_sw_netstats *tstats;
struct xfrm_state *x;
struct ip_tunnel *tunnel = XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip4;
u32 orig_mark = skb->mark;
int ret;

if (!tunnel)
return 1;
Expand All @@ -107,7 +108,11 @@ static int vti_rcv_cb(struct sk_buff *skb, int err)
x = xfrm_input_state(skb);
family = x->inner_mode->afinfo->family;

if (!xfrm_policy_check(NULL, XFRM_POLICY_IN, skb, family))
skb->mark = be32_to_cpu(tunnel->parms.i_key);
ret = xfrm_policy_check(NULL, XFRM_POLICY_IN, skb, family);
skb->mark = orig_mark;

if (!ret)
return -EPERM;

skb_scrub_packet(skb, !net_eq(tunnel->net, dev_net(skb->dev)));
Expand Down
9 changes: 7 additions & 2 deletions net/ipv6/ip6_vti.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ static int vti6_rcv(struct sk_buff *skb)
}

XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip6 = t;
skb->mark = be32_to_cpu(t->parms.i_key);

rcu_read_unlock();

Expand All @@ -342,6 +341,8 @@ static int vti6_rcv_cb(struct sk_buff *skb, int err)
struct pcpu_sw_netstats *tstats;
struct xfrm_state *x;
struct ip6_tnl *t = XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip6;
u32 orig_mark = skb->mark;
int ret;

if (!t)
return 1;
Expand All @@ -358,7 +359,11 @@ static int vti6_rcv_cb(struct sk_buff *skb, int err)
x = xfrm_input_state(skb);
family = x->inner_mode->afinfo->family;

if (!xfrm_policy_check(NULL, XFRM_POLICY_IN, skb, family))
skb->mark = be32_to_cpu(t->parms.i_key);
ret = xfrm_policy_check(NULL, XFRM_POLICY_IN, skb, family);
skb->mark = orig_mark;

if (!ret)
return -EPERM;

skb_scrub_packet(skb, !net_eq(t->net, dev_net(skb->dev)));
Expand Down

0 comments on commit d55c670

Please sign in to comment.