public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dp83640: don't recieve time stamps twice
@ 2017-04-18 19:14 Dan Carpenter
  2017-04-18 20:19 ` Richard Cochran
  2017-04-19  9:16 ` Sørensen, Stefan
  0 siblings, 2 replies; 9+ messages in thread
From: Dan Carpenter @ 2017-04-18 19:14 UTC (permalink / raw)
  To: Richard Cochran, Stefan Sørensen
  Cc: Andrew Lunn, Florian Fainelli, netdev, kernel-janitors

This patch is prompted by a static checker warning about a potential
use after free.  The concern is that netif_rx_ni() can free "skb" and we
call it twice.

When I look at the commit that added this, it looks like some stray
lines were added accidentally.  It doesn't make sense to me that we
would recieve the same data two times.  I asked the author but never
recieved a response.

I can't test this code, but I'm pretty sure my patch is correct.

Fixes: 4b063258ab93 ("dp83640: Delay scheduled work.")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/net/phy/dp83640.c b/drivers/net/phy/dp83640.c
index e2460a57e4b1..ed0d10f54f26 100644
--- a/drivers/net/phy/dp83640.c
+++ b/drivers/net/phy/dp83640.c
@@ -1438,8 +1438,6 @@ static bool dp83640_rxtstamp(struct phy_device *phydev,
 		skb_info->tmo = jiffies + SKB_TIMESTAMP_TIMEOUT;
 		skb_queue_tail(&dp83640->rx_queue, skb);
 		schedule_delayed_work(&dp83640->ts_work, SKB_TIMESTAMP_TIMEOUT);
-	} else {
-		netif_rx_ni(skb);
 	}
 
 	return true;

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] dp83640: don't recieve time stamps twice
  2017-04-18 19:14 [PATCH] dp83640: don't recieve time stamps twice Dan Carpenter
@ 2017-04-18 20:19 ` Richard Cochran
  2017-04-19  9:16 ` Sørensen, Stefan
  1 sibling, 0 replies; 9+ messages in thread
From: Richard Cochran @ 2017-04-18 20:19 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Stefan Sørensen, Andrew Lunn, Florian Fainelli, netdev,
	kernel-janitors

On Tue, Apr 18, 2017 at 10:14:26PM +0300, Dan Carpenter wrote:
> This patch is prompted by a static checker warning about a potential
> use after free.  The concern is that netif_rx_ni() can free "skb" and we
> call it twice.

Right, the code already calls netif_rx_ni() in the list_for_each_safe()
loop just above, in the case that the shhwtstamps pointer has been set.
 
> When I look at the commit that added this, it looks like some stray
> lines were added accidentally.  It doesn't make sense to me that we
> would recieve the same data two times.  I asked the author but never
> recieved a response.

Hm, maybe the intent was to move the call to netif_rx_ni() outside of
the spin_lock_irqsave() region (which how I had it before Stefan's
changes).

But calling netif_rx_ni() twice is clearly wrong.

Thanks,
Richard




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] dp83640: don't recieve time stamps twice
  2017-04-18 19:14 [PATCH] dp83640: don't recieve time stamps twice Dan Carpenter
  2017-04-18 20:19 ` Richard Cochran
@ 2017-04-19  9:16 ` Sørensen, Stefan
  2017-04-19 10:31   ` Richard Cochran
  1 sibling, 1 reply; 9+ messages in thread
From: Sørensen, Stefan @ 2017-04-19  9:16 UTC (permalink / raw)
  To: dan.carpenter@oracle.com, richardcochran@gmail.com
  Cc: netdev@vger.kernel.org, f.fainelli@gmail.com, andrew@lunn.ch,
	kernel-janitors@vger.kernel.org

T24gVHVlLCAyMDE3LTA0LTE4IGF0IDIyOjE0ICswMzAwLCBEYW4gQ2FycGVudGVyIHdyb3RlOg0K
PiBUaGlzIHBhdGNoIGlzIHByb21wdGVkIGJ5IGEgc3RhdGljIGNoZWNrZXIgd2FybmluZyBhYm91
dCBhIHBvdGVudGlhbA0KPiB1c2UgYWZ0ZXIgZnJlZS7CoMKgVGhlIGNvbmNlcm4gaXMgdGhhdCBu
ZXRpZl9yeF9uaSgpIGNhbiBmcmVlICJza2IiIGFuZA0KPiB3ZQ0KPiBjYWxsIGl0IHR3aWNlLg0K
PiANCj4gV2hlbiBJIGxvb2sgYXQgdGhlIGNvbW1pdCB0aGF0IGFkZGVkIHRoaXMsIGl0IGxvb2tz
IGxpa2Ugc29tZSBzdHJheQ0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QCBzdGF0aWMg
Ym9vbCBkcDgzNjQwX3J4dHN0YW1wKHN0cnVjdCBwaHlfZGV2aWNlDQo+ICpwaHlkZXYsDQo+IMKg
CQlza2JfaW5mby0+dG1vID0gamlmZmllcyArIFNLQl9USU1FU1RBTVBfVElNRU9VVDsNCj4gwqAJ
CXNrYl9xdWV1ZV90YWlsKCZkcDgzNjQwLT5yeF9xdWV1ZSwgc2tiKTsNCj4gwqAJCXNjaGVkdWxl
X2RlbGF5ZWRfd29yaygmZHA4MzY0MC0+dHNfd29yaywNCj4gU0tCX1RJTUVTVEFNUF9USU1FT1VU
KTsNCj4gLQl9IGVsc2Ugew0KPiAtCQluZXRpZl9yeF9uaShza2IpOw0KPiDCoAl9DQo+IMKgDQo+
IMKgCXJldHVybiB0cnVlOw=

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] dp83640: don't recieve time stamps twice
  2017-04-19  9:16 ` Sørensen, Stefan
@ 2017-04-19 10:31   ` Richard Cochran
  2017-04-19 10:53     ` Dan Carpenter
                       ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Richard Cochran @ 2017-04-19 10:31 UTC (permalink / raw)
  To: Sørensen, Stefan
  Cc: dan.carpenter@oracle.com, netdev@vger.kernel.org,
	f.fainelli@gmail.com, andrew@lunn.ch,
	kernel-janitors@vger.kernel.org

On Wed, Apr 19, 2017 at 09:16:56AM +0000, Sørensen, Stefan wrote:
> You are correct that these lines was added accidentally.

Can we please fix this in another way?  There is no need to hold the
spin lock during the callback into the networking stack.  Instead, how
about the following diff, which also fixes the other call site...

Thanks,
Richard

---
diff --git a/drivers/net/phy/dp83640.c b/drivers/net/phy/dp83640.c
index e2460a5..593e533 100644
--- a/drivers/net/phy/dp83640.c
+++ b/drivers/net/phy/dp83640.c
@@ -874,14 +874,15 @@ static void decode_rxts(struct dp83640_private *dp83640,
 			shhwtstamps = skb_hwtstamps(skb);
 			memset(shhwtstamps, 0, sizeof(*shhwtstamps));
 			shhwtstamps->hwtstamp = ns_to_ktime(rxts->ns);
-			netif_rx_ni(skb);
 			list_add(&rxts->list, &dp83640->rxpool);
 			break;
 		}
 	}
 	spin_unlock(&dp83640->rx_queue.lock);
 
-	if (!shhwtstamps)
+	if (shhwtstamps)
+		netif_rx_ni(skb);
+	else
 		list_add_tail(&rxts->list, &dp83640->rxts);
 out:
 	spin_unlock_irqrestore(&dp83640->rx_lock, flags);
@@ -1425,7 +1426,6 @@ static bool dp83640_rxtstamp(struct phy_device *phydev,
 			shhwtstamps = skb_hwtstamps(skb);
 			memset(shhwtstamps, 0, sizeof(*shhwtstamps));
 			shhwtstamps->hwtstamp = ns_to_ktime(rxts->ns);
-			netif_rx_ni(skb);
 			list_del_init(&rxts->list);
 			list_add(&rxts->list, &dp83640->rxpool);
 			break;
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] dp83640: don't recieve time stamps twice
  2017-04-19 10:31   ` Richard Cochran
@ 2017-04-19 10:53     ` Dan Carpenter
  2017-04-19 11:28     ` Sørensen, Stefan
  2017-04-20 20:02     ` David Miller
  2 siblings, 0 replies; 9+ messages in thread
From: Dan Carpenter @ 2017-04-19 10:53 UTC (permalink / raw)
  To: Richard Cochran
  Cc: Sørensen, Stefan, netdev@vger.kernel.org,
	f.fainelli@gmail.com, andrew@lunn.ch,
	kernel-janitors@vger.kernel.org

On Wed, Apr 19, 2017 at 12:31:35PM +0200, Richard Cochran wrote:
> On Wed, Apr 19, 2017 at 09:16:56AM +0000, Sørensen, Stefan wrote:
> > You are correct that these lines was added accidentally.
> 
> Can we please fix this in another way?  There is no need to hold the
> spin lock during the callback into the networking stack.  Instead, how
> about the following diff, which also fixes the other call site...
> 

I'm fine with this.  I hated my changelog, as well because it sounds
like guess work.  Could you send it with a:

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

regards,
dan carpenter


--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] dp83640: don't recieve time stamps twice
  2017-04-19 10:31   ` Richard Cochran
  2017-04-19 10:53     ` Dan Carpenter
@ 2017-04-19 11:28     ` Sørensen, Stefan
  2017-04-19 11:54       ` Richard Cochran
  2017-04-20 20:02     ` David Miller
  2 siblings, 1 reply; 9+ messages in thread
From: Sørensen, Stefan @ 2017-04-19 11:28 UTC (permalink / raw)
  To: richardcochran@gmail.com
  Cc: netdev@vger.kernel.org, dan.carpenter@oracle.com,
	f.fainelli@gmail.com, andrew@lunn.ch,
	kernel-janitors@vger.kernel.org

T24gV2VkLCAyMDE3LTA0LTE5IGF0IDEyOjMxICswMjAwLCBSaWNoYXJkIENvY2hyYW4gd3JvdGU6
DQo+IENhbiB3ZSBwbGVhc2UgZml4IHRoaXMgaW4gYW5vdGhlciB3YXk/wqDCoFRoZXJlIGlzIG5v
IG5lZWQgdG8gaG9sZCB0aGUNCj4gc3BpbiBsb2NrIGR1cmluZyB0aGUgY2FsbGJhY2sgaW50byB0
aGUgbmV0d29ya2luZyBzdGFjay7CoMKgSW5zdGVhZCwNCj4gaG93IGFib3V0IHRoZSBmb2xsb3dp
bmcgZGlmZiwgd2hpY2ggYWxzbyBmaXhlcyB0aGUgb3RoZXIgY2FsbCBzaXRlLi4uDQoNCg0KSSBh
Z3JlZSB0aGF0IHRoaXMgaXMgYSBiZXR0ZXIgd2F5IHRvIGZpeCBpdCAtIEkgdGhpbmsgdGhhdCB0
aGlzIHdhcyB0aGUNCnB1cnBvc2Ugb2YgdGhlIHBhdGNoIHRoYXQgZ290IGhhbGZ3YXkgbWl4ZWQg
aW4uDQoNCkBAIC04NzQsMTQgKzg3NCwxNSBAQCBzdGF0aWMgdm9pZCBkZWNvZGVfcnh0cyhzdHJ1
Y3QgZHA4MzY0MF9wcml2YXRlDQo+ICpkcDgzNjQwLA0KPiDCoAkJCXNoaHd0c3RhbXBzID0gc2ti
X2h3dHN0YW1wcyhza2IpOw0KPiDCoAkJCW1lbXNldChzaGh3dHN0YW1wcywgMCwNCj4gc2l6ZW9m
KCpzaGh3dHN0YW1wcykpOw0KPiDCoAkJCXNoaHd0c3RhbXBzLT5od3RzdGFtcCA9IG5zX3RvX2t0
aW1lKHJ4dHMtDQo+ID5ucyk7DQo+IC0JCQluZXRpZl9yeF9uaShza2IpOw0KPiDCoAkJCWxpc3Rf
YWRkKCZyeHRzLT5saXN0LCAmZHA4MzY0MC0+cnhwb29sKTsNCj4gwqAJCQlicmVhazsNCj4gwqAJ
CX0NCj4gwqAJfQ0KPiDCoAlzcGluX3VubG9jaygmZHA4MzY0MC0+cnhfcXVldWUubG9jayk7DQo+
IMKgDQo+IC0JaWYgKCFzaGh3dHN0YW1wcykNCj4gKwlpZiAoc2hod3RzdGFtcHMpDQo+ICsJCW5l
dGlmX3J4X25pKHNrYik7DQo+ICsJZWxzZQ0KPiDCoAkJbGlzdF9hZGRfdGFpbCgmcnh0cy0+bGlz
dCwgJmRwODM2NDAtPnJ4dHMpOw0KPiDCoG91dDoNCj4gwqAJc3Bpbl91bmxvY2tfaXJxcmVzdG9y
ZSgmZHA4MzY0MC0+cnhfbG9jaywgZmxhZ3MpOw0KDQpIZXJlIHdlIHN0aWxsIGhvbGQgcnhfbG9j
ayB3aGlsZSBkdXJpbmcgdGhlIGNhbGxiYWNrLCB3b3VsZG4ndCBpdCBiZQ0KYmVuZWZpY2lhbCB0
byByZWxlYXNlIHRoYXQgZmlyc3Q/DQoNClN0ZWZhbg0K

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] dp83640: don't recieve time stamps twice
  2017-04-19 11:28     ` Sørensen, Stefan
@ 2017-04-19 11:54       ` Richard Cochran
  0 siblings, 0 replies; 9+ messages in thread
From: Richard Cochran @ 2017-04-19 11:54 UTC (permalink / raw)
  To: Sørensen, Stefan
  Cc: netdev@vger.kernel.org, dan.carpenter@oracle.com,
	f.fainelli@gmail.com, andrew@lunn.ch,
	kernel-janitors@vger.kernel.org

On Wed, Apr 19, 2017 at 11:28:34AM +0000, Sørensen, Stefan wrote:
> Here we still hold rx_lock while during the callback, wouldn't it be
> beneficial to release that first?

Yes, your are right.

Do you want to post a fix?  If not, I will, but later on this week.

Thanks,
Richard
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] dp83640: don't recieve time stamps twice
  2017-04-19 10:31   ` Richard Cochran
  2017-04-19 10:53     ` Dan Carpenter
  2017-04-19 11:28     ` Sørensen, Stefan
@ 2017-04-20 20:02     ` David Miller
  2017-04-20 21:30       ` Richard Cochran
  2 siblings, 1 reply; 9+ messages in thread
From: David Miller @ 2017-04-20 20:02 UTC (permalink / raw)
  To: richardcochran
  Cc: Stefan.Sorensen, dan.carpenter, netdev, f.fainelli, andrew,
	kernel-janitors

From: Richard Cochran <richardcochran@gmail.com>
Date: Wed, 19 Apr 2017 12:31:35 +0200

> On Wed, Apr 19, 2017 at 09:16:56AM +0000, Sørensen, Stefan wrote:
>> You are correct that these lines was added accidentally.
> 
> Can we please fix this in another way?  There is no need to hold the
> spin lock during the callback into the networking stack.  Instead, how
> about the following diff, which also fixes the other call site...

Oops, I read this too late.

I already applied and pushed out Dan's fix.
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] dp83640: don't recieve time stamps twice
  2017-04-20 20:02     ` David Miller
@ 2017-04-20 21:30       ` Richard Cochran
  0 siblings, 0 replies; 9+ messages in thread
From: Richard Cochran @ 2017-04-20 21:30 UTC (permalink / raw)
  To: David Miller
  Cc: Stefan.Sorensen, dan.carpenter, netdev, f.fainelli, andrew,
	kernel-janitors

On Thu, Apr 20, 2017 at 04:02:27PM -0400, David Miller wrote:
> Oops, I read this too late.
> 
> I already applied and pushed out Dan's fix.

No problem, i'll submit a patch on top of that to move the netif calls
out of the spin-locked regions.

Thanks,
Richard

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-04-20 21:30 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-18 19:14 [PATCH] dp83640: don't recieve time stamps twice Dan Carpenter
2017-04-18 20:19 ` Richard Cochran
2017-04-19  9:16 ` Sørensen, Stefan
2017-04-19 10:31   ` Richard Cochran
2017-04-19 10:53     ` Dan Carpenter
2017-04-19 11:28     ` Sørensen, Stefan
2017-04-19 11:54       ` Richard Cochran
2017-04-20 20:02     ` David Miller
2017-04-20 21:30       ` Richard Cochran

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox