Skip to content

Commit d01b608

Browse files
Jon Maxwellberoid
Jon Maxwell
authored andcommitted
dccp/tcp: fix routing redirect race
commit 45caeaa5ac0b4b11784ac6f932c0ad4c6b67cda0 upstream. As Eric Dumazet pointed out this also needs to be fixed in IPv6. v2: Contains the IPv6 tcp/Ipv6 dccp patches as well. We have seen a few incidents lately where a dst_enty has been freed with a dangling TCP socket reference (sk->sk_dst_cache) pointing to that dst_entry. If the conditions/timings are right a crash then ensues when the freed dst_entry is referenced later on. A Common crashing back trace is: CyanogenMod#8 [] page_fault at ffffffff8163e648 [exception RIP: __tcp_ack_snd_check+74] . . CyanogenMod#9 [] tcp_rcv_established at ffffffff81580b64 CyanogenMod#10 [] tcp_v4_do_rcv at ffffffff8158b54a CyanogenMod#11 [] tcp_v4_rcv at ffffffff8158cd02 CyanogenMod#12 [] ip_local_deliver_finish at ffffffff815668f4 CyanogenMod#13 [] ip_local_deliver at ffffffff81566bd9 CyanogenMod#14 [] ip_rcv_finish at ffffffff8156656d CyanogenMod#15 [] ip_rcv at ffffffff81566f06 CyanogenMod#16 [] __netif_receive_skb_core at ffffffff8152b3a2 CyanogenMod#17 [] __netif_receive_skb at ffffffff8152b608 CyanogenMod#18 [] netif_receive_skb at ffffffff8152b690 CyanogenMod#19 [] vmxnet3_rq_rx_complete at ffffffffa015eeaf [vmxnet3] #20 [] vmxnet3_poll_rx_only at ffffffffa015f32a [vmxnet3] #21 [] net_rx_action at ffffffff8152bac2 #22 [] __do_softirq at ffffffff81084b4f #23 [] call_softirq at ffffffff8164845c #24 [] do_softirq at ffffffff81016fc5 #25 [] irq_exit at ffffffff81084ee5 #26 [] do_IRQ at ffffffff81648ff8 Of course it may happen with other NIC drivers as well. It's found the freed dst_entry here: 224 static bool tcp_in_quickack_mode(struct sock *sk)â�© 225 {â�© 226 â�¹ const struct inet_connection_sock *icsk = inet_csk(sk);â�© 227 â�¹ const struct dst_entry *dst = __sk_dst_get(sk);â�© 228 â�© 229 â�¹ return (dst && dst_metric(dst, RTAX_QUICKACK)) ||â�© 230 â�¹ â�¹ (icsk->icsk_ack.quick && !icsk->icsk_ack.pingpong);â�© 231 }â�© But there are other backtraces attributed to the same freed dst_entry in netfilter code as well. All the vmcores showed 2 significant clues: - Remote hosts behind the default gateway had always been redirected to a different gateway. A rtable/dst_entry will be added for that host. Making more dst_entrys with lower reference counts. Making this more probable. - All vmcores showed a postitive LockDroppedIcmps value, e.g: LockDroppedIcmps 267 A closer look at the tcp_v4_err() handler revealed that do_redirect() will run regardless of whether user space has the socket locked. This can result in a race condition where the same dst_entry cached in sk->sk_dst_entry can be decremented twice for the same socket via: do_redirect()->__sk_dst_check()-> dst_release(). Which leads to the dst_entry being prematurely freed with another socket pointing to it via sk->sk_dst_cache and a subsequent crash. To fix this skip do_redirect() if usespace has the socket locked. Instead let the redirect take place later when user space does not have the socket locked. The dccp/IPv6 code is very similar in this respect, so fixing it there too. As Eric Garver pointed out the following commit now invalidates routes. Which can set the dst->obsolete flag so that ipv4_dst_check() returns null and triggers the dst_release(). Fixes: ceb3320 ("ipv4: Kill routes during PMTU/redirect updates.") Cc: Eric Garver <[email protected]> Cc: Hannes Sowa <[email protected]> Signed-off-by: Jon Maxwell <[email protected]> Signed-off-by: David S. Miller <[email protected]> Signed-off-by: Willy Tarreau <[email protected]>
1 parent 854b0e1 commit d01b608

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

net/dccp/ipv4.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ static void dccp_v4_err(struct sk_buff *skb, u32 info)
263263

264264
switch (type) {
265265
case ICMP_REDIRECT:
266-
dccp_do_redirect(skb, sk);
266+
if (!sock_owned_by_user(sk))
267+
dccp_do_redirect(skb, sk);
267268
goto out;
268269
case ICMP_SOURCE_QUENCH:
269270
/* Just silently ignore these. */

net/dccp/ipv6.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,12 @@ static void dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
132132
np = inet6_sk(sk);
133133

134134
if (type == NDISC_REDIRECT) {
135-
struct dst_entry *dst = __sk_dst_check(sk, np->dst_cookie);
135+
if (!sock_owned_by_user(sk)) {
136+
struct dst_entry *dst = __sk_dst_check(sk, np->dst_cookie);
136137

137-
if (dst)
138-
dst->ops->redirect(dst, sk, skb);
138+
if (dst)
139+
dst->ops->redirect(dst, sk, skb);
140+
}
139141
goto out;
140142
}
141143

net/ipv4/tcp_ipv4.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,8 @@ void tcp_v4_err(struct sk_buff *icmp_skb, u32 info)
389389

390390
switch (type) {
391391
case ICMP_REDIRECT:
392-
do_redirect(icmp_skb, sk);
392+
if (!sock_owned_by_user(sk))
393+
do_redirect(icmp_skb, sk);
393394
goto out;
394395
case ICMP_SOURCE_QUENCH:
395396
/* Just silently ignore these. */

net/ipv6/tcp_ipv6.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,12 @@ static void tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
385385
np = inet6_sk(sk);
386386

387387
if (type == NDISC_REDIRECT) {
388-
struct dst_entry *dst = __sk_dst_check(sk, np->dst_cookie);
388+
if (!sock_owned_by_user(sk)) {
389+
struct dst_entry *dst = __sk_dst_check(sk, np->dst_cookie);
389390

390-
if (dst)
391-
dst->ops->redirect(dst, sk, skb);
391+
if (dst)
392+
dst->ops->redirect(dst, sk, skb);
393+
}
392394
goto out;
393395
}
394396

0 commit comments

Comments
 (0)