virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Paolo Abeni <pabeni@redhat.com>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	John Fastabend <john.fastabend@gmail.com>,
	Alexei Starovoitov <ast@kernel.org>,
	linux-kernel@vger.kernel.org, Eric Dumazet <edumazet@google.com>,
	elena.reshetova@intel.com, Jakub Kicinski <kuba@kernel.org>,
	virtualization@lists.linux-foundation.org,
	"David S . Miller" <davem@davemloft.net>,
	kirill.shutemov@linux.intel.com
Subject: Re: [PATCH v1 5/6] virtio_net: Guard against buffer length overflow in xdp_linearize_page()
Date: Fri, 20 Jan 2023 08:09:51 -0500	[thread overview]
Message-ID: <20230120080256-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20230119135721.83345-6-alexander.shishkin@linux.intel.com>

On Thu, Jan 19, 2023 at 03:57:20PM +0200, Alexander Shishkin wrote:
> When reassembling incoming buffers to an xdp_page, there is a potential
> integer overflow in the buffer size test and trigger and out of bounds
> memcpy().
> 
> Fix this by reordering the test so that both sides are of the same
> signedness.
> 
> Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Alexei Starovoitov <ast@kernel.org>
> Cc: Daniel Borkmann <daniel@iogearbox.net>
> Cc: Jesper Dangaard Brouer <hawk@kernel.org>
> Cc: John Fastabend <john.fastabend@gmail.com>
> Cc: David S. Miller <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> ---
>  drivers/net/virtio_net.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 7723b2a49d8e..dfa51dd95f63 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -751,8 +751,10 @@ static struct page *xdp_linearize_page(struct receive_queue *rq,
>  
>  		/* guard against a misconfigured or uncooperative backend that
>  		 * is sending packet larger than the MTU.
> +		 * At the same time, make sure that an especially uncooperative
> +		 * backend can't overflow the test by supplying a large buflen.
>  		 */
> -		if ((page_off + buflen + tailroom) > PAGE_SIZE) {
> +		if (buflen > PAGE_SIZE - page_off - tailroom) {
>  			put_page(p);
>  			goto err_buf;
>  		}

I feel the issue should be addressed in virtqueue_get_buf.
In fact, when using DMA API, we already keep track of the
length in vring_desc_extra.

So, isn't this just the question of passing the length and
validating it e.g. in vring_unmap_one_split?
We can also use the index_nospec trick since otherwise
there could be speculation concerns.

> -- 
> 2.39.0

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

      parent reply	other threads:[~2023-01-20 13:10 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20230119135721.83345-1-alexander.shishkin@linux.intel.com>
     [not found] ` <20230119135721.83345-5-alexander.shishkin@linux.intel.com>
2023-01-19 15:22   ` [PATCH v1 4/6] virtio console: Harden control message handling Greg Kroah-Hartman
2023-01-20 12:45     ` Michael S. Tsirkin
     [not found]       ` <87y1pxp39k.fsf@ubik.fi.intel.com>
2023-01-27 10:58         ` Michael S. Tsirkin
2023-01-20 11:55 ` [PATCH v1 0/6] Harden a few virtio bits Michael S. Tsirkin
     [not found]   ` <877cxhqtdi.fsf@ubik.fi.intel.com>
2023-01-20 12:40     ` Michael S. Tsirkin
     [not found] ` <20230119135721.83345-4-alexander.shishkin@linux.intel.com>
2023-01-20 12:54   ` [PATCH v1 3/6] virtio 9p: Fix an overflow Michael S. Tsirkin
     [not found] ` <20230119135721.83345-7-alexander.shishkin@linux.intel.com>
2023-01-20 12:56   ` [PATCH v1 6/6] virtio_ring: Prevent bounds check bypass on descriptor index Michael S. Tsirkin
     [not found] ` <20230119135721.83345-3-alexander.shishkin@linux.intel.com>
2023-01-19 15:20   ` [PATCH v1 2/6] virtio console: Harden port adding Greg Kroah-Hartman
     [not found]     ` <87ilh2quto.fsf@ubik.fi.intel.com>
2023-01-19 18:57       ` Greg Kroah-Hartman
     [not found]         ` <87a62eqo4h.fsf@ubik.fi.intel.com>
2023-01-20  7:15           ` Greg Kroah-Hartman
2023-01-27 11:02           ` Michael S. Tsirkin
     [not found]             ` <87k018p4xs.fsf@ubik.fi.intel.com>
2023-01-27 12:12               ` Michael S. Tsirkin
     [not found]                 ` <87edrgp2is.fsf@ubik.fi.intel.com>
2023-01-27 13:31                   ` Greg Kroah-Hartman
     [not found]                     ` <87bkmkoyd1.fsf@ubik.fi.intel.com>
2023-01-27 14:37                       ` Greg Kroah-Hartman
2023-01-27 14:46                       ` Michael S. Tsirkin
2023-01-27 13:52                   ` Michael S. Tsirkin
2023-01-20 12:59   ` Michael S. Tsirkin
     [not found] ` <20230119135721.83345-2-alexander.shishkin@linux.intel.com>
2023-01-19 15:17   ` [PATCH v1 1/6] virtio console: Harden multiport against invalid host input Greg Kroah-Hartman
     [not found]     ` <87fsc6qrvx.fsf@ubik.fi.intel.com>
2023-01-19 19:18       ` Greg Kroah-Hartman
2023-01-20 13:01   ` Michael S. Tsirkin
     [not found] ` <20230119135721.83345-6-alexander.shishkin@linux.intel.com>
2023-01-20 13:09   ` Michael S. Tsirkin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230120080256-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=elena.reshetova@intel.com \
    --cc=hawk@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).