aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2017-03-07 14:06:15 -0800
committerDavid S. Miller <davem@davemloft.net>2017-03-07 14:06:15 -0800
commitfa4c7fb2ad2ea5dae57eb875915d0efb1e068543 (patch)
tree411965f359568a7dfd8c23d68fbb0d68e43c356e
parentrxrpc: Call state should be read with READ_ONCE() under some circumstances (diff)
parentnet: fix socket refcounting in skb_complete_tx_timestamp() (diff)
downloadlinux-dev-fa4c7fb2ad2ea5dae57eb875915d0efb1e068543.tar.xz
linux-dev-fa4c7fb2ad2ea5dae57eb875915d0efb1e068543.zip
Merge branch 'sock_hold-misuses'
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 <davem@davemloft.net>
-rw-r--r--net/core/skbuff.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index f3557958e9bf..cd4ba8c6b609 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -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);
@@ -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;
@@ -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);