lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230131074032.GD34480@h68b04307.sqa.eu95>
Date:   Tue, 31 Jan 2023 15:40:32 +0800
From:   Heng Qi <hengqi@...ux.alibaba.com>
To:     "Michael S. Tsirkin" <mst@...hat.com>
Cc:     netdev@...r.kernel.org, bpf@...r.kernel.org,
        Jason Wang <jasowang@...hat.com>,
        Paolo Abeni <pabeni@...hat.com>,
        Jakub Kicinski <kuba@...nel.org>,
        John Fastabend <john.fastabend@...il.com>,
        "David S . Miller" <davem@...emloft.net>,
        Daniel Borkmann <daniel@...earbox.net>,
        Alexei Starovoitov <ast@...nel.org>,
        Eric Dumazet <edumazet@...gle.com>,
        Xuan Zhuo <xuanzhuo@...ux.alibaba.com>
Subject: Re: [PATCH net-next] virtio-net: fix possible unsigned integer
 overflow

On Tue, Jan 31, 2023 at 02:20:49AM -0500, Michael S. Tsirkin wrote:
> On Tue, Jan 31, 2023 at 11:43:37AM +0800, Heng Qi wrote:
> > When the single-buffer xdp is loaded and after xdp_linearize_page()
> > is called, *num_buf becomes 0 and (*num_buf - 1) may overflow into
> > a large integer in virtnet_build_xdp_buff_mrg(), resulting in
> > unexpected packet dropping.
> > 
> > Fixes: ef75cb51f139 ("virtio-net: build xdp_buff with multi buffers")
> > Signed-off-by: Heng Qi <hengqi@...ux.alibaba.com>
> > Reviewed-by: Xuan Zhuo <xuanzhuo@...ux.alibaba.com>
> 
> Given the confusion, just make num_buf an int?

In the structure virtio_net_hdr_mrg_rxbuf, \field{num_buffers} is unsigned int,
which matches each other. And num_buf is used in many different places, it seems
to be a lot of work to modify it to int.

> 
> > ---
> >  drivers/net/virtio_net.c | 7 +++++--
> >  1 file changed, 5 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> > index aaa6fe9b214a..a8e9462903fa 100644
> > --- a/drivers/net/virtio_net.c
> > +++ b/drivers/net/virtio_net.c
> > @@ -1007,6 +1007,9 @@ static int virtnet_build_xdp_buff_mrg(struct net_device *dev,
> >  	xdp_prepare_buff(xdp, buf - VIRTIO_XDP_HEADROOM,
> >  			 VIRTIO_XDP_HEADROOM + vi->hdr_len, len - vi->hdr_len, true);
> >  
> > +	if (!*num_buf)
> > +		return 0;
> > +
> >  	if (*num_buf > 1) {
> >  		/* If we want to build multi-buffer xdp, we need
> >  		 * to specify that the flags of xdp_buff have the
> 
> 
> This means truesize won't be set.

Do you mean xdp_frags_truesize please? If yes, the answer is yes, this fix
is only for single-buffer xdp, which doesn't need xdp_frags_truesize, and
already set it to 0 in its wrapper receive_mergeable().

> 
> > @@ -1020,10 +1023,10 @@ static int virtnet_build_xdp_buff_mrg(struct net_device *dev,
> >  		shinfo->xdp_frags_size = 0;
> >  	}
> >  
> > -	if ((*num_buf - 1) > MAX_SKB_FRAGS)
> > +	if (*num_buf > MAX_SKB_FRAGS + 1)
> >  		return -EINVAL;
> 
> Admittedly this is cleaner.
> 
> >  
> > -	while ((--*num_buf) >= 1) {
> > +	while (--*num_buf) {
> 
> A bit more fragile, > 0 would be better.

Sure.

Thanks.

> 
> >  		buf = virtqueue_get_buf_ctx(rq->vq, &len, &ctx);
> >  		if (unlikely(!buf)) {
> >  			pr_debug("%s: rx error: %d buffers out of %d missing\n",
> > -- 
> > 2.19.1.6.gb485710b

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ