Skip to content

Commit b0e214d

Browse files
Madhu KoriginjaFlorian Westphal
authored andcommitted
netfilter: keep conntrack reference until IPsecv6 policy checks are done
Keep the conntrack reference until policy checks have been performed for IPsec V6 NAT support, just like ipv4. The reference needs to be dropped before a packet is queued to avoid having the conntrack module unloadable. Fixes: 58a317f ("netfilter: ipv6: add IPv6 NAT support") Signed-off-by: Madhu Koriginja <[email protected]> Signed-off-by: Florian Westphal <[email protected]>
1 parent 36ce998 commit b0e214d

File tree

5 files changed

+13
-11
lines changed

5 files changed

+13
-11
lines changed

net/dccp/ipv6.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,7 @@ static int dccp_v6_rcv(struct sk_buff *skb)
784784

785785
if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb))
786786
goto discard_and_relse;
787+
nf_reset_ct(skb);
787788

788789
return __sk_receive_skb(sk, skb, 1, dh->dccph_doff * 4,
789790
refcounted) ? -1 : 0;

net/ipv6/ip6_input.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -404,10 +404,6 @@ void ip6_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int nexthdr,
404404
/* Only do this once for first final protocol */
405405
have_final = true;
406406

407-
/* Free reference early: we don't need it any more,
408-
and it may hold ip_conntrack module loaded
409-
indefinitely. */
410-
nf_reset_ct(skb);
411407

412408
skb_postpull_rcsum(skb, skb_network_header(skb),
413409
skb_network_header_len(skb));
@@ -430,10 +426,12 @@ void ip6_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int nexthdr,
430426
goto discard;
431427
}
432428
}
433-
if (!(ipprot->flags & INET6_PROTO_NOPOLICY) &&
434-
!xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb)) {
435-
SKB_DR_SET(reason, XFRM_POLICY);
436-
goto discard;
429+
if (!(ipprot->flags & INET6_PROTO_NOPOLICY)) {
430+
if (!xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb)) {
431+
SKB_DR_SET(reason, XFRM_POLICY);
432+
goto discard;
433+
}
434+
nf_reset_ct(skb);
437435
}
438436

439437
ret = INDIRECT_CALL_2(ipprot->handler, tcp_v6_rcv, udpv6_rcv,

net/ipv6/raw.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,8 @@ static bool ipv6_raw_deliver(struct sk_buff *skb, int nexthdr)
194194
struct sk_buff *clone = skb_clone(skb, GFP_ATOMIC);
195195

196196
/* Not releasing hash table! */
197-
if (clone) {
198-
nf_reset_ct(clone);
197+
if (clone)
199198
rawv6_rcv(sk, clone);
200-
}
201199
}
202200
}
203201
rcu_read_unlock();
@@ -391,6 +389,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
391389
kfree_skb_reason(skb, SKB_DROP_REASON_XFRM_POLICY);
392390
return NET_RX_DROP;
393391
}
392+
nf_reset_ct(skb);
394393

395394
if (!rp->checksum)
396395
skb->ip_summed = CHECKSUM_UNNECESSARY;

net/ipv6/tcp_ipv6.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,6 +1723,8 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
17231723
if (drop_reason)
17241724
goto discard_and_relse;
17251725

1726+
nf_reset_ct(skb);
1727+
17261728
if (tcp_filter(sk, skb)) {
17271729
drop_reason = SKB_DROP_REASON_SOCKET_FILTER;
17281730
goto discard_and_relse;

net/ipv6/udp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ static int udpv6_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb)
704704
drop_reason = SKB_DROP_REASON_XFRM_POLICY;
705705
goto drop;
706706
}
707+
nf_reset_ct(skb);
707708

708709
if (static_branch_unlikely(&udpv6_encap_needed_key) && up->encap_type) {
709710
int (*encap_rcv)(struct sock *sk, struct sk_buff *skb);
@@ -1027,6 +1028,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
10271028

10281029
if (!xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb))
10291030
goto discard;
1031+
nf_reset_ct(skb);
10301032

10311033
if (udp_lib_checksum_complete(skb))
10321034
goto csum_error;

0 commit comments

Comments
 (0)