Commit 19a8321c authored by Eric Dumazet's avatar Eric Dumazet Committed by Greg Kroah-Hartman

netlink: fix races after skb queueing

[ Upstream commit 4a7e7c2a ]

As soon as an skb is queued into socket receive_queue, another thread
can consume it, so we are not allowed to reference skb anymore, or risk
use after free.
Signed-off-by: default avatarEric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 589336f3
...@@ -830,12 +830,19 @@ int netlink_attachskb(struct sock *sk, struct sk_buff *skb, ...@@ -830,12 +830,19 @@ int netlink_attachskb(struct sock *sk, struct sk_buff *skb,
return 0; return 0;
} }
int netlink_sendskb(struct sock *sk, struct sk_buff *skb) static int __netlink_sendskb(struct sock *sk, struct sk_buff *skb)
{ {
int len = skb->len; int len = skb->len;
skb_queue_tail(&sk->sk_receive_queue, skb); skb_queue_tail(&sk->sk_receive_queue, skb);
sk->sk_data_ready(sk, len); sk->sk_data_ready(sk, len);
return len;
}
int netlink_sendskb(struct sock *sk, struct sk_buff *skb)
{
int len = __netlink_sendskb(sk, skb);
sock_put(sk); sock_put(sk);
return len; return len;
} }
...@@ -960,8 +967,7 @@ static inline int netlink_broadcast_deliver(struct sock *sk, ...@@ -960,8 +967,7 @@ static inline int netlink_broadcast_deliver(struct sock *sk,
if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf && if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf &&
!test_bit(0, &nlk->state)) { !test_bit(0, &nlk->state)) {
skb_set_owner_r(skb, sk); skb_set_owner_r(skb, sk);
skb_queue_tail(&sk->sk_receive_queue, skb); __netlink_sendskb(sk, skb);
sk->sk_data_ready(sk, skb->len);
return atomic_read(&sk->sk_rmem_alloc) > sk->sk_rcvbuf; return atomic_read(&sk->sk_rmem_alloc) > sk->sk_rcvbuf;
} }
return -1; return -1;
...@@ -1682,10 +1688,8 @@ static int netlink_dump(struct sock *sk) ...@@ -1682,10 +1688,8 @@ static int netlink_dump(struct sock *sk)
if (sk_filter(sk, skb)) if (sk_filter(sk, skb))
kfree_skb(skb); kfree_skb(skb);
else { else
skb_queue_tail(&sk->sk_receive_queue, skb); __netlink_sendskb(sk, skb);
sk->sk_data_ready(sk, skb->len);
}
return 0; return 0;
} }
...@@ -1697,10 +1701,8 @@ static int netlink_dump(struct sock *sk) ...@@ -1697,10 +1701,8 @@ static int netlink_dump(struct sock *sk)
if (sk_filter(sk, skb)) if (sk_filter(sk, skb))
kfree_skb(skb); kfree_skb(skb);
else { else
skb_queue_tail(&sk->sk_receive_queue, skb); __netlink_sendskb(sk, skb);
sk->sk_data_ready(sk, skb->len);
}
if (cb->done) if (cb->done)
cb->done(cb); cb->done(cb);
......
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