Skip to content

Commit 853618d

Browse files
fengidridavem330
authored andcommitted
virtio_net: bugfix overflow inside xdp_linearize_page()
Here we copy the data from the original buf to the new page. But we not check that it may be overflow. As long as the size received(including vnethdr) is greater than 3840 (PAGE_SIZE -VIRTIO_XDP_HEADROOM). Then the memcpy will overflow. And this is completely possible, as long as the MTU is large, such as 4096. In our test environment, this will cause crash. Since crash is caused by the written memory, it is meaningless, so I do not include it. Fixes: 72979a6 ("virtio_net: xdp, add slowpath case for non contiguous buffers") Signed-off-by: Xuan Zhuo <[email protected]> Acked-by: Jason Wang <[email protected]> Acked-by: Michael S. Tsirkin <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3037933 commit 853618d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/net/virtio_net.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,16 +814,20 @@ static struct page *xdp_linearize_page(struct receive_queue *rq,
814814
int page_off,
815815
unsigned int *len)
816816
{
817-
struct page *page = alloc_page(GFP_ATOMIC);
817+
int tailroom = SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
818+
struct page *page;
819+
820+
if (page_off + *len + tailroom > PAGE_SIZE)
821+
return NULL;
818822

823+
page = alloc_page(GFP_ATOMIC);
819824
if (!page)
820825
return NULL;
821826

822827
memcpy(page_address(page) + page_off, page_address(p) + offset, *len);
823828
page_off += *len;
824829

825830
while (--*num_buf) {
826-
int tailroom = SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
827831
unsigned int buflen;
828832
void *buf;
829833
int off;

0 commit comments

Comments
 (0)