aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Cochran <richardcochran@gmail.com>2011-10-20 20:49:15 -0400
committerHerton Ronaldo Krzesinski <herton.krzesinski@canonical.com>2011-11-21 12:54:58 -0500
commit181463ea2c23f67bbe5a9ae4f644524313b2e24f (patch)
tree77a3141d2dab147a15ece3b58ac1b7c1ccee283a
parent7f5217913acc81afcb8b7c6039d933958a8591d6 (diff)
net: hold sock reference while processing tx timestamps
BugLink: http://bugs.launchpad.net/bugs/890952 commit da92b194cc36b5dc1fbd85206aeeffd80bee0c39 upstream. The pair of functions, * skb_clone_tx_timestamp() * skb_complete_tx_timestamp() were designed to allow timestamping in PHY devices. The first function, called during the MAC driver's hard_xmit method, identifies PTP protocol packets, clones them, and gives them to the PHY device driver. The PHY driver may hold onto the packet and deliver it at a later time using the second function, which adds the packet to the socket's error queue. As pointed out by Johannes, nothing prevents the socket from disappearing while the cloned packet is sitting in the PHY driver awaiting a timestamp. This patch fixes the issue by taking a reference on the socket for each such packet. In addition, the comments regarding the usage of these function are expanded to highlight the rule that PHY drivers must use skb_complete_tx_timestamp() to release the packet, in order to release the socket reference, too. These functions first appeared in v2.6.36. Reported-by: Johannes Berg <johannes@sipsolutions.net> Signed-off-by: Richard Cochran <richard.cochran@omicron.at> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Reviewed-by: Johannes Berg <johannes@sipsolutions.net> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
-rw-r--r--include/linux/phy.h2
-rw-r--r--include/linux/skbuff.h7
-rw-r--r--net/core/timestamping.c12
3 files changed, 17 insertions, 4 deletions
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 7da5fa84595..4d3f63ac242 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -418,7 +418,7 @@ struct phy_driver {
418 418
419 /* 419 /*
420 * Requests a Tx timestamp for 'skb'. The phy driver promises 420 * Requests a Tx timestamp for 'skb'. The phy driver promises
421 * to deliver it to the socket's error queue as soon as a 421 * to deliver it using skb_complete_tx_timestamp() as soon as a
422 * timestamp becomes available. One of the PTP_CLASS_ values 422 * timestamp becomes available. One of the PTP_CLASS_ values
423 * is passed in 'type'. 423 * is passed in 'type'.
424 */ 424 */
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index c0a4f3ab0cc..b920a72a7a9 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -1996,8 +1996,13 @@ static inline bool skb_defer_rx_timestamp(struct sk_buff *skb)
1996/** 1996/**
1997 * skb_complete_tx_timestamp() - deliver cloned skb with tx timestamps 1997 * skb_complete_tx_timestamp() - deliver cloned skb with tx timestamps
1998 * 1998 *
1999 * PHY drivers may accept clones of transmitted packets for
2000 * timestamping via their phy_driver.txtstamp method. These drivers
2001 * must call this function to return the skb back to the stack, with
2002 * or without a timestamp.
2003 *
1999 * @skb: clone of the the original outgoing packet 2004 * @skb: clone of the the original outgoing packet
2000 * @hwtstamps: hardware time stamps 2005 * @hwtstamps: hardware time stamps, may be NULL if not available
2001 * 2006 *
2002 */ 2007 */
2003void skb_complete_tx_timestamp(struct sk_buff *skb, 2008void skb_complete_tx_timestamp(struct sk_buff *skb,
diff --git a/net/core/timestamping.c b/net/core/timestamping.c
index 7e7ca375d43..97d036a6b89 100644
--- a/net/core/timestamping.c
+++ b/net/core/timestamping.c
@@ -57,9 +57,13 @@ void skb_clone_tx_timestamp(struct sk_buff *skb)
57 case PTP_CLASS_V2_VLAN: 57 case PTP_CLASS_V2_VLAN:
58 phydev = skb->dev->phydev; 58 phydev = skb->dev->phydev;
59 if (likely(phydev->drv->txtstamp)) { 59 if (likely(phydev->drv->txtstamp)) {
60 if (!atomic_inc_not_zero(&sk->sk_refcnt))
61 return;
60 clone = skb_clone(skb, GFP_ATOMIC); 62 clone = skb_clone(skb, GFP_ATOMIC);
61 if (!clone) 63 if (!clone) {
64 sock_put(sk);
62 return; 65 return;
66 }
63 clone->sk = sk; 67 clone->sk = sk;
64 phydev->drv->txtstamp(phydev, clone, type); 68 phydev->drv->txtstamp(phydev, clone, type);
65 } 69 }
@@ -76,8 +80,11 @@ void skb_complete_tx_timestamp(struct sk_buff *skb,
76 struct sock_exterr_skb *serr; 80 struct sock_exterr_skb *serr;
77 int err; 81 int err;
78 82
79 if (!hwtstamps) 83 if (!hwtstamps) {
84 sock_put(sk);
85 kfree_skb(skb);
80 return; 86 return;
87 }
81 88
82 *skb_hwtstamps(skb) = *hwtstamps; 89 *skb_hwtstamps(skb) = *hwtstamps;
83 serr = SKB_EXT_ERR(skb); 90 serr = SKB_EXT_ERR(skb);
@@ -86,6 +93,7 @@ void skb_complete_tx_timestamp(struct sk_buff *skb,
86 serr->ee.ee_origin = SO_EE_ORIGIN_TIMESTAMPING; 93 serr->ee.ee_origin = SO_EE_ORIGIN_TIMESTAMPING;
87 skb->sk = NULL; 94 skb->sk = NULL;
88 err = sock_queue_err_skb(sk, skb); 95 err = sock_queue_err_skb(sk, skb);
96 sock_put(sk);
89 if (err) 97 if (err)
90 kfree_skb(skb); 98 kfree_skb(skb);
91} 99}