virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] virtio_net: bugfix overflow inside xdp_linearize_page()
@ 2023-04-13 12:19 Xuan Zhuo
  2023-04-14  5:40 ` Jason Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Xuan Zhuo @ 2023-04-13 12:19 UTC (permalink / raw)
  To: netdev
  Cc: Jesper Dangaard Brouer, Daniel Borkmann, Michael S. Tsirkin,
	John Fastabend, Alexei Starovoitov, virtualization, Eric Dumazet,
	Jakub Kicinski, bpf, Paolo Abeni, David S. Miller

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.

Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
---
 drivers/net/virtio_net.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 2396c28c0122..ea1bd4bb326d 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -814,8 +814,13 @@ static struct page *xdp_linearize_page(struct receive_queue *rq,
 				       int page_off,
 				       unsigned int *len)
 {
-	struct page *page = alloc_page(GFP_ATOMIC);
+	int tailroom = SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
+	struct page *page;
+
+	if (page_off + *len + tailroom > PAGE_SIZE)
+		return NULL;
 
+	page = alloc_page(GFP_ATOMIC);
 	if (!page)
 		return NULL;
 
@@ -823,7 +828,6 @@ static struct page *xdp_linearize_page(struct receive_queue *rq,
 	page_off += *len;
 
 	while (--*num_buf) {
-		int tailroom = SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
 		unsigned int buflen;
 		void *buf;
 		int off;
-- 
2.32.0.3.g01195cf9f

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

* Re: [PATCH net] virtio_net: bugfix overflow inside xdp_linearize_page()
  2023-04-13 12:19 [PATCH net] virtio_net: bugfix overflow inside xdp_linearize_page() Xuan Zhuo
@ 2023-04-14  5:40 ` Jason Wang
  2023-04-14  5:59   ` Xuan Zhuo
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Wang @ 2023-04-14  5:40 UTC (permalink / raw)
  To: Xuan Zhuo
  Cc: Jesper Dangaard Brouer, Daniel Borkmann, Michael S. Tsirkin,
	netdev, John Fastabend, Alexei Starovoitov, virtualization,
	Eric Dumazet, Jakub Kicinski, bpf, Paolo Abeni, David S. Miller

On Thu, Apr 13, 2023 at 8:19 PM Xuan Zhuo <xuanzhuo@linux.alibaba.com> wrote:
>
> 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.
>
> Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>

Missing fixes tag?

Other than this,

Acked-by: Jason Wang <jasowang@redhat.com>

Thanks

> ---
>  drivers/net/virtio_net.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 2396c28c0122..ea1bd4bb326d 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -814,8 +814,13 @@ static struct page *xdp_linearize_page(struct receive_queue *rq,
>                                        int page_off,
>                                        unsigned int *len)
>  {
> -       struct page *page = alloc_page(GFP_ATOMIC);
> +       int tailroom = SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
> +       struct page *page;
> +
> +       if (page_off + *len + tailroom > PAGE_SIZE)
> +               return NULL;
>
> +       page = alloc_page(GFP_ATOMIC);
>         if (!page)
>                 return NULL;
>
> @@ -823,7 +828,6 @@ static struct page *xdp_linearize_page(struct receive_queue *rq,
>         page_off += *len;
>
>         while (--*num_buf) {
> -               int tailroom = SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
>                 unsigned int buflen;
>                 void *buf;
>                 int off;
> --
> 2.32.0.3.g01195cf9f
>

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

* Re: [PATCH net] virtio_net: bugfix overflow inside xdp_linearize_page()
  2023-04-14  5:40 ` Jason Wang
@ 2023-04-14  5:59   ` Xuan Zhuo
  0 siblings, 0 replies; 3+ messages in thread
From: Xuan Zhuo @ 2023-04-14  5:59 UTC (permalink / raw)
  To: Jason Wang
  Cc: Jesper Dangaard Brouer, Daniel Borkmann, Michael S. Tsirkin,
	netdev, John Fastabend, Alexei Starovoitov, virtualization,
	Eric Dumazet, Jakub Kicinski, bpf, Paolo Abeni, David S. Miller

On Fri, 14 Apr 2023 13:40:32 +0800, Jason Wang <jasowang@redhat.com> wrote:
> On Thu, Apr 13, 2023 at 8:19 PM Xuan Zhuo <xuanzhuo@linux.alibaba.com> wrote:
> >
> > 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.
> >
> > Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
>
> Missing fixes tag?
>
> Other than this,
>
> Acked-by: Jason Wang <jasowang@redhat.com>

Sorry, miss this.

Thanks.



>
> Thanks
>
> > ---
> >  drivers/net/virtio_net.c | 8 ++++++--
> >  1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> > index 2396c28c0122..ea1bd4bb326d 100644
> > --- a/drivers/net/virtio_net.c
> > +++ b/drivers/net/virtio_net.c
> > @@ -814,8 +814,13 @@ static struct page *xdp_linearize_page(struct receive_queue *rq,
> >                                        int page_off,
> >                                        unsigned int *len)
> >  {
> > -       struct page *page = alloc_page(GFP_ATOMIC);
> > +       int tailroom = SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
> > +       struct page *page;
> > +
> > +       if (page_off + *len + tailroom > PAGE_SIZE)
> > +               return NULL;
> >
> > +       page = alloc_page(GFP_ATOMIC);
> >         if (!page)
> >                 return NULL;
> >
> > @@ -823,7 +828,6 @@ static struct page *xdp_linearize_page(struct receive_queue *rq,
> >         page_off += *len;
> >
> >         while (--*num_buf) {
> > -               int tailroom = SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
> >                 unsigned int buflen;
> >                 void *buf;
> >                 int off;
> > --
> > 2.32.0.3.g01195cf9f
> >
>
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

end of thread, other threads:[~2023-04-14  5:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-13 12:19 [PATCH net] virtio_net: bugfix overflow inside xdp_linearize_page() Xuan Zhuo
2023-04-14  5:40 ` Jason Wang
2023-04-14  5:59   ` Xuan Zhuo

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).