Skip to content

Commit f1ea3cd

Browse files
haiyangzdavem330
authored andcommitted
hyperv: Fix RNDIS send_completion code path
In some cases, the VM_PKT_COMP message can arrive later than RNDIS completion message, which will free the packet memory. This may cause panic due to access to freed memory in netvsc_send_completion(). This patch fixes this problem by removing rndis_filter_send_request_completion() from the code path. The function was a no-op. Reported-by: Long Li <longli@microsoft.com> Tested-by: Long Li <longli@microsoft.com> Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com> Reviewed-by: K. Y. Srinivasan <kys@microsoft.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent fd5c07a commit f1ea3cd

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

drivers/net/hyperv/netvsc.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,10 @@ static void netvsc_send_completion(struct hv_device *device,
470470
packet->trans_id;
471471

472472
/* Notify the layer above us */
473-
nvsc_packet->completion.send.send_completion(
474-
nvsc_packet->completion.send.send_completion_ctx);
473+
if (nvsc_packet)
474+
nvsc_packet->completion.send.send_completion(
475+
nvsc_packet->completion.send.
476+
send_completion_ctx);
475477

476478
num_outstanding_sends =
477479
atomic_dec_return(&net_device->num_outstanding_sends);
@@ -498,6 +500,7 @@ int netvsc_send(struct hv_device *device,
498500
int ret = 0;
499501
struct nvsp_message sendMessage;
500502
struct net_device *ndev;
503+
u64 req_id;
501504

502505
net_device = get_outbound_net_device(device);
503506
if (!net_device)
@@ -518,20 +521,24 @@ int netvsc_send(struct hv_device *device,
518521
0xFFFFFFFF;
519522
sendMessage.msg.v1_msg.send_rndis_pkt.send_buf_section_size = 0;
520523

524+
if (packet->completion.send.send_completion)
525+
req_id = (u64)packet;
526+
else
527+
req_id = 0;
528+
521529
if (packet->page_buf_cnt) {
522530
ret = vmbus_sendpacket_pagebuffer(device->channel,
523531
packet->page_buf,
524532
packet->page_buf_cnt,
525533
&sendMessage,
526534
sizeof(struct nvsp_message),
527-
(unsigned long)packet);
535+
req_id);
528536
} else {
529537
ret = vmbus_sendpacket(device->channel, &sendMessage,
530538
sizeof(struct nvsp_message),
531-
(unsigned long)packet,
539+
req_id,
532540
VM_PKT_DATA_INBAND,
533541
VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
534-
535542
}
536543

537544
if (ret == 0) {

drivers/net/hyperv/rndis_filter.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ struct rndis_request {
6161

6262
static void rndis_filter_send_completion(void *ctx);
6363

64-
static void rndis_filter_send_request_completion(void *ctx);
65-
66-
6764

6865
static struct rndis_device *get_rndis_device(void)
6966
{
@@ -241,10 +238,7 @@ static int rndis_filter_send_request(struct rndis_device *dev,
241238
packet->page_buf[0].len;
242239
}
243240

244-
packet->completion.send.send_completion_ctx = req;/* packet; */
245-
packet->completion.send.send_completion =
246-
rndis_filter_send_request_completion;
247-
packet->completion.send.send_completion_tid = (unsigned long)dev;
241+
packet->completion.send.send_completion = NULL;
248242

249243
ret = netvsc_send(dev->net_dev->dev, packet);
250244
return ret;
@@ -999,9 +993,3 @@ static void rndis_filter_send_completion(void *ctx)
999993
/* Pass it back to the original handler */
1000994
filter_pkt->completion(filter_pkt->completion_ctx);
1001995
}
1002-
1003-
1004-
static void rndis_filter_send_request_completion(void *ctx)
1005-
{
1006-
/* Noop */
1007-
}

0 commit comments

Comments
 (0)