Skip to content

Commit

Permalink
Merge branch 'sock_hold-misuses'
Browse files Browse the repository at this point in the history
Eric Dumazet says:

====================
net: fix possible sock_hold() misuses

skb_complete_wifi_ack() and skb_complete_tx_timestamp() currently
call sock_hold() on sockets that might have transitioned their sk_refcnt
to zero already.
====================

Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
davem330 committed Mar 7, 2017
2 parents 146d8fe + 9ac25fc commit fa4c7fb
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions net/core/skbuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -3828,13 +3828,14 @@ void skb_complete_tx_timestamp(struct sk_buff *skb,
if (!skb_may_tx_timestamp(sk, false))
return;

/* take a reference to prevent skb_orphan() from freeing the socket */
sock_hold(sk);

*skb_hwtstamps(skb) = *hwtstamps;
__skb_complete_tx_timestamp(skb, sk, SCM_TSTAMP_SND);

sock_put(sk);
/* Take a reference to prevent skb_orphan() from freeing the socket,
* but only if the socket refcount is not zero.
*/
if (likely(atomic_inc_not_zero(&sk->sk_refcnt))) {
*skb_hwtstamps(skb) = *hwtstamps;
__skb_complete_tx_timestamp(skb, sk, SCM_TSTAMP_SND);
sock_put(sk);
}
}
EXPORT_SYMBOL_GPL(skb_complete_tx_timestamp);

Expand Down Expand Up @@ -3893,7 +3894,7 @@ void skb_complete_wifi_ack(struct sk_buff *skb, bool acked)
{
struct sock *sk = skb->sk;
struct sock_exterr_skb *serr;
int err;
int err = 1;

skb->wifi_acked_valid = 1;
skb->wifi_acked = acked;
Expand All @@ -3903,14 +3904,15 @@ void skb_complete_wifi_ack(struct sk_buff *skb, bool acked)
serr->ee.ee_errno = ENOMSG;
serr->ee.ee_origin = SO_EE_ORIGIN_TXSTATUS;

/* take a reference to prevent skb_orphan() from freeing the socket */
sock_hold(sk);

err = sock_queue_err_skb(sk, skb);
/* Take a reference to prevent skb_orphan() from freeing the socket,
* but only if the socket refcount is not zero.
*/
if (likely(atomic_inc_not_zero(&sk->sk_refcnt))) {
err = sock_queue_err_skb(sk, skb);
sock_put(sk);
}
if (err)
kfree_skb(skb);

sock_put(sk);
}
EXPORT_SYMBOL_GPL(skb_complete_wifi_ack);

Expand Down

0 comments on commit fa4c7fb

Please sign in to comment.