* [PATCH net-next-2.6] l2tp: fix l2tp_ip_sendmsg() route handling
@ 2011-06-12 8:27 Eric Dumazet
2011-06-13 21:31 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Eric Dumazet @ 2011-06-12 8:27 UTC (permalink / raw)
To: David Miller; +Cc: netdev, James Chapman
l2tp_ip_sendmsg() in non connected mode incorrectly calls
sk_setup_caps(). Subsequent send() calls send data to wrong destination.
We can also avoid changing dst refcount in connected mode, using
appropriate rcu locking. Once output route lookups can also be done
under rcu, sendto() calls wont change dst refcounts too.
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
CC: James Chapman <jchapman@katalix.com>
---
diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
index b6466e7..d21e7eb 100644
--- a/net/l2tp/l2tp_ip.c
+++ b/net/l2tp/l2tp_ip.c
@@ -480,18 +480,16 @@ static int l2tp_ip_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
if (connected)
rt = (struct rtable *) __sk_dst_check(sk, 0);
+ rcu_read_lock();
if (rt == NULL) {
- struct ip_options_rcu *inet_opt;
+ const struct ip_options_rcu *inet_opt;
- rcu_read_lock();
inet_opt = rcu_dereference(inet->inet_opt);
/* Use correct destination address if we have options. */
if (inet_opt && inet_opt->opt.srr)
daddr = inet_opt->opt.faddr;
- rcu_read_unlock();
-
/* If this fails, retransmit mechanism of transport layer will
* keep trying until route appears or the connection times
* itself out.
@@ -503,12 +501,20 @@ static int l2tp_ip_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
sk->sk_bound_dev_if);
if (IS_ERR(rt))
goto no_route;
- sk_setup_caps(sk, &rt->dst);
+ if (connected)
+ sk_setup_caps(sk, &rt->dst);
+ else
+ dst_release(&rt->dst); /* safe since we hold rcu_read_lock */
}
- skb_dst_set(skb, dst_clone(&rt->dst));
+
+ /* We dont need to clone dst here, it is guaranteed to not disappear.
+ * __dev_xmit_skb() might force a refcount if needed.
+ */
+ skb_dst_set_noref(skb, &rt->dst);
/* Queue the packet to IP for output */
rc = ip_queue_xmit(skb, &inet->cork.fl);
+ rcu_read_unlock();
error:
/* Update stats */
@@ -525,6 +531,7 @@ out:
return rc;
no_route:
+ rcu_read_unlock();
IP_INC_STATS(sock_net(sk), IPSTATS_MIB_OUTNOROUTES);
kfree_skb(skb);
rc = -EHOSTUNREACH;
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next-2.6] l2tp: fix l2tp_ip_sendmsg() route handling
2011-06-12 8:27 [PATCH net-next-2.6] l2tp: fix l2tp_ip_sendmsg() route handling Eric Dumazet
@ 2011-06-13 21:31 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2011-06-13 21:31 UTC (permalink / raw)
To: eric.dumazet; +Cc: netdev, jchapman
From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Sun, 12 Jun 2011 10:27:09 +0200
> l2tp_ip_sendmsg() in non connected mode incorrectly calls
> sk_setup_caps(). Subsequent send() calls send data to wrong destination.
>
> We can also avoid changing dst refcount in connected mode, using
> appropriate rcu locking. Once output route lookups can also be done
> under rcu, sendto() calls wont change dst refcounts too.
>
> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
> CC: James Chapman <jchapman@katalix.com>
Applied, thanks Eric.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-06-13 21:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-12 8:27 [PATCH net-next-2.6] l2tp: fix l2tp_ip_sendmsg() route handling Eric Dumazet
2011-06-13 21:31 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox