linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] virtio-net: make copy len check in xdp_linearize_page
@ 2021-12-13  4:50 mengensun8801
  2021-12-13  7:48 ` Jason Wang
  0 siblings, 1 reply; 5+ messages in thread
From: mengensun8801 @ 2021-12-13  4:50 UTC (permalink / raw)
  To: jasowang
  Cc: davem, kuba, ast, daniel, hawk, john.fastabend, virtualization,
	netdev, linux-kernel, bpf, mengensun, MengLong Dong,
	ZhengXiong Jiang

From: mengensun <mengensun@tencent.com>

xdp_linearize_page asume ring elem size is smaller then page size
when copy the first ring elem, but, there may be a elem size bigger
then page size.

add_recvbuf_mergeable may add a hole to ring elem, the hole size is
not sure, according EWMA.

so, fix it by check copy len,if checked failed, just dropped the
whole frame, not make the memory dirty after the page.

Signed-off-by: mengensun <mengensun@tencent.com>
Reviewed-by: MengLong Dong <imagedong@tencent.com>
Reviewed-by: ZhengXiong Jiang <mungerjiang@tencent.com>
---
 drivers/net/virtio_net.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 36a4b7c195d5..844bdbd67ff7 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -662,8 +662,12 @@ static struct page *xdp_linearize_page(struct receive_queue *rq,
 				       int page_off,
 				       unsigned int *len)
 {
-	struct page *page = alloc_page(GFP_ATOMIC);
+	struct page *page;
 
+	if (*len > PAGE_SIZE - page_off)
+		return NULL;
+
+	page = alloc_page(GFP_ATOMIC);
 	if (!page)
 		return NULL;
 
-- 
2.27.0


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

end of thread, other threads:[~2021-12-14  6:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-13  4:50 [PATCH] virtio-net: make copy len check in xdp_linearize_page mengensun8801
2021-12-13  7:48 ` Jason Wang
2021-12-14  3:13   ` Jason Wang
2021-12-14  3:48     ` 孙蒙恩
2021-12-14  6:14       ` Jason Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).