From nobody Sat Nov 30 00:34:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1620900208; cv=none; d=zohomail.com; s=zohoarc; b=JU5TtsVyi2MB9LMAyn0auHb9Fu5STFRpAc2d27+MVLsSihDzTukoYpWo7+0ND9bCtp42E0FuYZAIvf7Mz555UxBHi2HhW2B9ogDRfXAVP8UvDyOEf+c2Sn1l7yZnvxwrTVtOenfaqSiGI372uluPhpu0/nn9kTKr89Ic/g28Hk8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620900208; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=g+1fyoENkOuy7Zh/t/9f7BoPHxXHhIGX5kJfVKmIRpA=; b=TNyS6R22RvtA+tbJTNKcZKu5IZlIti6LATqi7hgjJPGPcH3HFsIGKbzZ7FKwE9OZyDSrMlPysiypR4w5vtOmXPucbhmM3842R6Vo0XfpWYC50KtLmNuNH+QUlpfe9jbSGIypCOom/KVMdJ9Q6ta0HXEMgoqqhckpIyRZoy3xZVg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1620900208589388.73788645769446; Thu, 13 May 2021 03:03:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.126806.238285 (Exim 4.92) (envelope-from ) id 1lh8BS-0004CR-A3; Thu, 13 May 2021 10:03:10 +0000 Received: by outflank-mailman (output) from mailman id 126806.238285; Thu, 13 May 2021 10:03:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lh8BS-0004CK-5n; Thu, 13 May 2021 10:03:10 +0000 Received: by outflank-mailman (input) for mailman id 126806; Thu, 13 May 2021 10:03:08 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lh8BQ-0003vw-Nm for xen-devel@lists.xenproject.org; Thu, 13 May 2021 10:03:08 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5e7d7ef8-c3c2-48a1-a0e8-26c163d772ed; Thu, 13 May 2021 10:03:07 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 9FC13B05D; Thu, 13 May 2021 10:03:06 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5e7d7ef8-c3c2-48a1-a0e8-26c163d772ed X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1620900186; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=g+1fyoENkOuy7Zh/t/9f7BoPHxXHhIGX5kJfVKmIRpA=; b=g/KYhXDBmr+jGf2DUNwYpTYmyFb5iID0n+JwQIYx5JoW7VIHybKPbSnGj1UPKNEw9rGj7B MiaQabJO4iSCO/G/rIVuX8Zf026zsfTmGZsYXeuDjGQ5Idoe7g910FX9BfA6fL9/j32Q2m vig7EKf4L+OCtklY3VcDg8L1QLco2XY= From: Juergen Gross To: xen-devel@lists.xenproject.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Boris Ostrovsky , Stefano Stabellini , "David S. Miller" , Jakub Kicinski Subject: [PATCH 6/8] xen/netfront: don't read data from request on the ring page Date: Thu, 13 May 2021 12:03:00 +0200 Message-Id: <20210513100302.22027-7-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210513100302.22027-1-jgross@suse.com> References: <20210513100302.22027-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" In order to avoid a malicious backend being able to influence the local processing of a request build the request locally first and then copy it to the ring page. Any reading from the request needs to be done on the local instance. Signed-off-by: Juergen Gross --- drivers/net/xen-netfront.c | 75 ++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c index f91e41ece554..261c35be0147 100644 --- a/drivers/net/xen-netfront.c +++ b/drivers/net/xen-netfront.c @@ -435,7 +435,8 @@ struct xennet_gnttab_make_txreq { struct netfront_queue *queue; struct sk_buff *skb; struct page *page; - struct xen_netif_tx_request *tx; /* Last request */ + struct xen_netif_tx_request *tx; /* Last request on ring page */ + struct xen_netif_tx_request tx_local; /* Last request local copy*/ unsigned int size; }; =20 @@ -463,30 +464,27 @@ static void xennet_tx_setup_grant(unsigned long gfn, = unsigned int offset, queue->grant_tx_page[id] =3D page; queue->grant_tx_ref[id] =3D ref; =20 - tx->id =3D id; - tx->gref =3D ref; - tx->offset =3D offset; - tx->size =3D len; - tx->flags =3D 0; + info->tx_local.id =3D id; + info->tx_local.gref =3D ref; + info->tx_local.offset =3D offset; + info->tx_local.size =3D len; + info->tx_local.flags =3D 0; + + *tx =3D info->tx_local; =20 info->tx =3D tx; - info->size +=3D tx->size; + info->size +=3D info->tx_local.size; } =20 static struct xen_netif_tx_request *xennet_make_first_txreq( - struct netfront_queue *queue, struct sk_buff *skb, - struct page *page, unsigned int offset, unsigned int len) + struct xennet_gnttab_make_txreq *info, + unsigned int offset, unsigned int len) { - struct xennet_gnttab_make_txreq info =3D { - .queue =3D queue, - .skb =3D skb, - .page =3D page, - .size =3D 0, - }; + info->size =3D 0; =20 - gnttab_for_one_grant(page, offset, len, xennet_tx_setup_grant, &info); + gnttab_for_one_grant(info->page, offset, len, xennet_tx_setup_grant, info= ); =20 - return info.tx; + return info->tx; } =20 static void xennet_make_one_txreq(unsigned long gfn, unsigned int offset, @@ -499,35 +497,27 @@ static void xennet_make_one_txreq(unsigned long gfn, = unsigned int offset, xennet_tx_setup_grant(gfn, offset, len, data); } =20 -static struct xen_netif_tx_request *xennet_make_txreqs( - struct netfront_queue *queue, struct xen_netif_tx_request *tx, - struct sk_buff *skb, struct page *page, +static void xennet_make_txreqs( + struct xennet_gnttab_make_txreq *info, + struct page *page, unsigned int offset, unsigned int len) { - struct xennet_gnttab_make_txreq info =3D { - .queue =3D queue, - .skb =3D skb, - .tx =3D tx, - }; - /* Skip unused frames from start of page */ page +=3D offset >> PAGE_SHIFT; offset &=3D ~PAGE_MASK; =20 while (len) { - info.page =3D page; - info.size =3D 0; + info->page =3D page; + info->size =3D 0; =20 gnttab_foreach_grant_in_range(page, offset, len, xennet_make_one_txreq, - &info); + info); =20 page++; offset =3D 0; - len -=3D info.size; + len -=3D info->size; } - - return info.tx; } =20 /* @@ -580,10 +570,14 @@ static int xennet_xdp_xmit_one(struct net_device *dev, { struct netfront_info *np =3D netdev_priv(dev); struct netfront_stats *tx_stats =3D this_cpu_ptr(np->tx_stats); + struct xennet_gnttab_make_txreq info =3D { + .queue =3D queue, + .skb =3D NULL, + .page =3D virt_to_page(xdpf->data), + }; int notify; =20 - xennet_make_first_txreq(queue, NULL, - virt_to_page(xdpf->data), + xennet_make_first_txreq(&info, offset_in_page(xdpf->data), xdpf->len); =20 @@ -647,6 +641,7 @@ static netdev_tx_t xennet_start_xmit(struct sk_buff *sk= b, struct net_device *dev unsigned int len; unsigned long flags; struct netfront_queue *queue =3D NULL; + struct xennet_gnttab_make_txreq info =3D { }; unsigned int num_queues =3D dev->real_num_tx_queues; u16 queue_index; struct sk_buff *nskb; @@ -704,14 +699,16 @@ static netdev_tx_t xennet_start_xmit(struct sk_buff *= skb, struct net_device *dev } =20 /* First request for the linear area. */ - first_tx =3D tx =3D xennet_make_first_txreq(queue, skb, - page, offset, len); + info.queue =3D queue; + info.skb =3D skb; + info.page =3D page; + first_tx =3D tx =3D xennet_make_first_txreq(&info, offset, len); offset +=3D tx->size; if (offset =3D=3D PAGE_SIZE) { page++; offset =3D 0; } - len -=3D tx->size; + len -=3D info.tx_local.size; =20 if (skb->ip_summed =3D=3D CHECKSUM_PARTIAL) /* local packet? */ @@ -741,12 +738,12 @@ static netdev_tx_t xennet_start_xmit(struct sk_buff *= skb, struct net_device *dev } =20 /* Requests for the rest of the linear area. */ - tx =3D xennet_make_txreqs(queue, tx, skb, page, offset, len); + xennet_make_txreqs(&info, page, offset, len); =20 /* Requests for all the frags. */ for (i =3D 0; i < skb_shinfo(skb)->nr_frags; i++) { skb_frag_t *frag =3D &skb_shinfo(skb)->frags[i]; - tx =3D xennet_make_txreqs(queue, tx, skb, skb_frag_page(frag), + xennet_make_txreqs(&info, skb_frag_page(frag), skb_frag_off(frag), skb_frag_size(frag)); } --=20 2.26.2