diff options
| author | Eric Dumazet <edumazet@google.com> | 2017-03-22 11:30:11 +0000 |
|---|---|---|
| committer | android-build-merger <android-build-merger@google.com> | 2017-03-22 11:30:11 +0000 |
| commit | 9cf061bb472f0c1c86143b769f5d8d3bdf5f3143 (patch) | |
| tree | e7ffb78e439fbb67e7ea5cb580b093e8c8f5c9b8 /net | |
| parent | 50aba0e7c5765bb954f7f5be6569c67f13783033 (diff) | |
| parent | ec4d8692b76e08a40221eb7c74775a390114f098 (diff) | |
net: fix socket refcounting in skb_complete_tx_timestamp()
am: ec4d8692b7
Change-Id: Idc05607ffe99175575d7f07e3138e2f4496a5110
Diffstat (limited to 'net')
| -rw-r--r-- | net/core/skbuff.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 370f4f86e2b5..73dfd7729bc9 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -3678,13 +3678,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); |
