Skip to contentSkip to conversation

hv_netvsc: Fix a bug in netvsc_start_xmit()

PATCH Superseded K. Y. Srinivasan 4 participants 6 messages Apr 27, 2015 – Apr 28, 2015

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hv_netvsc: Fix a bug in netvsc_start_xmit()

Commit commit b08cc79155fc26d0d112b1470d1ece5034651a4b eliminated memory allocation in the packet send path. This commit introduced a bug since it did not account for the case if the skb was cloned. Fix this bug by using the pre-reserved head room only if the skb is not cloned.

---
 drivers/net/hyperv/netvsc_drv.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/hyperv/netvsc_drv.c +1 -1
index a3a9d38..7eb0251 100644
@@ -421,7 +421,7 @@ check_size:
 
 	pkt_sz = sizeof(struct hv_netvsc_packet) + RNDIS_AND_PPI_SIZE;
 
-	if (head_room < pkt_sz) {
+	if (skb->cloned ||  head_room < pkt_sz) {
 		packet = kmalloc(pkt_sz, GFP_ATOMIC);
 		if (!packet) {
 			/* out of memory, drop packet */
Signature · 1 line
1.7.4.1
maintainer
#1 lore raw

From: "K. Y. Srinivasan" <[email protected]>
Date: Mon, 27 Apr 2015 18:14:50 -0700

Quoted 6 lines

Commit commit b08cc79155fc26d0d112b1470d1ece5034651a4b eliminated memory allocation in the packet send path. This commit introduced a bug since it did not account for the case if the skb was cloned. Fix this bug by using the pre-reserved head room only if the skb is not cloned.

We have generic infrastructure to do this, please try instead:

	err = skb_cow_head(skb, pkt_sz);

this will take care of everything for you and you can get rid of all of this dynamic memory allocation etc. in this code path.

#2 lore raw
Quoted 22 lines

-----Original Message-----
From: David Miller [mailto:[email protected]]
Sent: Monday, April 27, 2015 7:57 PM
To: KY Srinivasan
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net 1/1] hv_netvsc: Fix a bug in netvsc_start_xmit()

From: "K. Y. Srinivasan" <[email protected]>
Date: Mon, 27 Apr 2015 18:14:50 -0700

Quoted 1 line

Commit commit b08cc79155fc26d0d112b1470d1ece5034651a4b eliminated

memory

Quoted 5 lines

allocation in the packet send path. This commit introduced a bug since it did not account for the case if the skb was cloned. Fix this bug by using the pre-reserved head room only if the skb is not cloned.

Quoted 7 lines

We have generic infrastructure to do this, please try instead:

	err = skb_cow_head(skb, pkt_sz);

this will take care of everything for you and you can get rid of all of this dynamic memory allocation etc. in this code path.

Thanks David; I will resubmit this patch.

Regards,

K. Y

maintainer Tested-by on v1 1/1
#3 lore raw
In reply to K. Y. Srinivasan
Quoted 26 lines

-----Original Message-----
From: devel [mailto:[email protected]] On Behalf Of K. Y. Srinivasan
Sent: Tuesday, April 28, 2015 9:15
To: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH net 1/1] hv_netvsc: Fix a bug in netvsc_start_xmit()

Commit commit b08cc79155fc26d0d112b1470d1ece5034651a4b eliminated memory
allocation in the packet send path. This commit introduced a bug since it did not account for the case if the skb was cloned. Fix this bug by using the pre-reserved head room only if the skb is not cloned.

---
 drivers/net/hyperv/netvsc_drv.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/hyperv/netvsc_drv.c +0 -0
index a3a9d38..7eb0251 100644

drivers/net/hyperv/netvsc_drv.c check_size:

Quoted 9 lines
drivers/net/hyperv/netvsc_drv.c +1 -2
@@ -421,7 +421,7 @@ check_size:
 
 	pkt_sz = sizeof(struct hv_netvsc_packet) + RNDIS_AND_PPI_SIZE;
 
-	if (head_room < pkt_sz) {
+	if (skb->cloned ||  head_room < pkt_sz) {
 		packet = kmalloc(pkt_sz, GFP_ATOMIC);
 		if (!packet) {
 			/* out of memory, drop packet */
--

Without the patch, the guest can panic due to memory corruption.

I confirm the patch can fix the panic I saw.

Thanks,
-- Dexuan

#4 lore raw
In reply to K. Y. Srinivasan

Hello.

Quoted 1 line · K. Y. Srinivasan

Commit commit b08cc79155fc26d0d112b1470d1ece5034651a4b eliminated memory

One "commit" is enough. :-)
And please also specify that commit's summary in parens.

Quoted 5 lines

allocation in the packet send path. This commit introduced a bug since it did not account for the case if the skb was cloned. Fix this bug by using the pre-reserved head room only if the skb is not cloned.

[...]

WBR, Sergei

#5 lore raw
Quoted 24 lines

-----Original Message-----
From: Sergei Shtylyov [mailto:[email protected]]
Sent: Tuesday, April 28, 2015 11:27 AM
To: KY Srinivasan; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH net 1/1] hv_netvsc: Fix a bug in netvsc_start_xmit()

Hello.

Quoted 1 line · K. Y. Srinivasan

Commit commit b08cc79155fc26d0d112b1470d1ece5034651a4b eliminated

memory

One "commit" is enough. :-)
And please also specify that commit's summary in parens.

Quoted 3 lines

allocation in the packet send path. This commit introduced a bug since it did not account for the case if the skb was cloned. Fix this bug by using the pre-reserved head room only if the skb is not cloned.

Quoted 5 lines
Quoted 1 line

[...]

WBR, Sergei

Will do; thanks.

K. Y