Commit fd6a8a15 authored by Eric Dumazet's avatar Eric Dumazet Committed by Luis Henriques

udp: fix dst races with multicast early demux

commit 10e2eb87 upstream.

Multicast dst are not cached. They carry DST_NOCACHE.

As mentioned in commit f8864972 ("ipv4: fix dst race in
sk_dst_get()"), these dst need special care before caching them
into a socket.

Caching them is allowed only if their refcnt was not 0, ie we
must use atomic_inc_not_zero()

Also, we must use READ_ONCE() to fetch sk->sk_rx_dst, as mentioned
in commit d0c294c5 ("tcp: prevent fetching dst twice in early demux
code")

Fixes: 421b3885 ("udp: ipv4: Add udp early demux")
Tested-by: default avatarGregory Hoggarth <Gregory.Hoggarth@alliedtelesis.co.nz>
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Reported-by: default avatarGregory Hoggarth <Gregory.Hoggarth@alliedtelesis.co.nz>
Reported-by: default avatarAlex Gartrell <agartrell@fb.com>
Cc: Michal Kubeček <mkubecek@suse.cz>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
[ luis: backported to 3.16: used davem's backport to 3.14 ]
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent a7fc16ef
...@@ -1988,12 +1988,19 @@ void udp_v4_early_demux(struct sk_buff *skb) ...@@ -1988,12 +1988,19 @@ void udp_v4_early_demux(struct sk_buff *skb)
skb->sk = sk; skb->sk = sk;
skb->destructor = sock_edemux; skb->destructor = sock_edemux;
dst = sk->sk_rx_dst; dst = ACCESS_ONCE(sk->sk_rx_dst);
if (dst) if (dst)
dst = dst_check(dst, 0); dst = dst_check(dst, 0);
if (dst) if (dst) {
skb_dst_set_noref(skb, dst); /* DST_NOCACHE can not be used without taking a reference */
if (dst->flags & DST_NOCACHE) {
if (likely(atomic_inc_not_zero(&dst->__refcnt)))
skb_dst_set(skb, dst);
} else {
skb_dst_set_noref(skb, dst);
}
}
} }
int udp_rcv(struct sk_buff *skb) int udp_rcv(struct sk_buff *skb)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment