Skip to content

Commit 0102eee

Browse files
andrea-parrikuba-moo
authored andcommitted
hv_netvsc: Allocate the recv_buf buffers after NVSP_MSG1_TYPE_SEND_RECV_BUF
The recv_buf buffers are allocated in netvsc_device_add(). Later in netvsc_init_buf() the response to NVSP_MSG1_TYPE_SEND_RECV_BUF allows the host to set up a recv_section_size that could be bigger than the (default) value used for that allocation. The host-controlled value could be used by a malicious host to bypass the check on the packet's length in netvsc_receive() and hence to overflow the recv_buf buffer. Move the allocation of the recv_buf buffers into netvsc_init_but(). Reported-by: Juan Vazquez <[email protected]> Signed-off-by: Andrea Parri (Microsoft) <[email protected]> Fixes: 0ba35fe ("hv_netvsc: Copy packets sent by Hyper-V out of the receive buffer") Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 6b4950d commit 0102eee

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

drivers/net/hyperv/netvsc.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ static int netvsc_init_buf(struct hv_device *device,
311311
struct nvsp_message *init_packet;
312312
unsigned int buf_size;
313313
size_t map_words;
314-
int ret = 0;
314+
int i, ret = 0;
315315

316316
/* Get receive buffer area. */
317317
buf_size = device_info->recv_sections * device_info->recv_section_size;
@@ -405,6 +405,16 @@ static int netvsc_init_buf(struct hv_device *device,
405405
goto cleanup;
406406
}
407407

408+
for (i = 0; i < VRSS_CHANNEL_MAX; i++) {
409+
struct netvsc_channel *nvchan = &net_device->chan_table[i];
410+
411+
nvchan->recv_buf = kzalloc(net_device->recv_section_size, GFP_KERNEL);
412+
if (nvchan->recv_buf == NULL) {
413+
ret = -ENOMEM;
414+
goto cleanup;
415+
}
416+
}
417+
408418
/* Setup receive completion ring.
409419
* Add 1 to the recv_section_cnt because at least one entry in a
410420
* ring buffer has to be empty.
@@ -1549,12 +1559,6 @@ struct netvsc_device *netvsc_device_add(struct hv_device *device,
15491559
for (i = 0; i < VRSS_CHANNEL_MAX; i++) {
15501560
struct netvsc_channel *nvchan = &net_device->chan_table[i];
15511561

1552-
nvchan->recv_buf = kzalloc(device_info->recv_section_size, GFP_KERNEL);
1553-
if (nvchan->recv_buf == NULL) {
1554-
ret = -ENOMEM;
1555-
goto cleanup2;
1556-
}
1557-
15581562
nvchan->channel = device->channel;
15591563
nvchan->net_device = net_device;
15601564
u64_stats_init(&nvchan->tx_stats.syncp);

0 commit comments

Comments
 (0)