All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Juergen Gross <jgross@suse.com>,
	Jan Beulich <jbeulich@suse.com>,
	"David S. Miller" <davem@davemloft.net>
Subject: [PATCH 4.19 66/69] xen/netfront: dont read data from request on the ring page
Date: Mon, 29 Nov 2021 19:18:48 +0100	[thread overview]
Message-ID: <20211129181705.791385322@linuxfoundation.org> (raw)
In-Reply-To: <20211129181703.670197996@linuxfoundation.org>

From: Juergen Gross <jgross@suse.com>

commit 162081ec33c2686afa29d91bf8d302824aa846c7 upstream.

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 influencing the
processing in the frontend needs to be done on the local instance.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/net/xen-netfront.c |   80 ++++++++++++++++++++-------------------------
 1 file changed, 37 insertions(+), 43 deletions(-)

--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -425,7 +425,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;
 };
 
@@ -453,30 +454,27 @@ static void xennet_tx_setup_grant(unsign
 	queue->grant_tx_page[id] = page;
 	queue->grant_tx_ref[id] = ref;
 
-	tx->id = id;
-	tx->gref = ref;
-	tx->offset = offset;
-	tx->size = len;
-	tx->flags = 0;
+	info->tx_local.id = id;
+	info->tx_local.gref = ref;
+	info->tx_local.offset = offset;
+	info->tx_local.size = len;
+	info->tx_local.flags = 0;
+
+	*tx = info->tx_local;
 
 	info->tx = tx;
-	info->size += tx->size;
+	info->size += info->tx_local.size;
 }
 
 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 = {
-		.queue = queue,
-		.skb = skb,
-		.page = page,
-		.size = 0,
-	};
+	info->size = 0;
 
-	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);
 
-	return info.tx;
+	return info->tx;
 }
 
 static void xennet_make_one_txreq(unsigned long gfn, unsigned int offset,
@@ -489,35 +487,27 @@ static void xennet_make_one_txreq(unsign
 	xennet_tx_setup_grant(gfn, offset, len, data);
 }
 
-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 = {
-		.queue = queue,
-		.skb = skb,
-		.tx = tx,
-	};
-
 	/* Skip unused frames from start of page */
 	page += offset >> PAGE_SHIFT;
 	offset &= ~PAGE_MASK;
 
 	while (len) {
-		info.page = page;
-		info.size = 0;
+		info->page = page;
+		info->size = 0;
 
 		gnttab_foreach_grant_in_range(page, offset, len,
 					      xennet_make_one_txreq,
-					      &info);
+					      info);
 
 		page++;
 		offset = 0;
-		len -= info.size;
+		len -= info->size;
 	}
-
-	return info.tx;
 }
 
 /*
@@ -571,7 +561,7 @@ static netdev_tx_t xennet_start_xmit(str
 {
 	struct netfront_info *np = netdev_priv(dev);
 	struct netfront_stats *tx_stats = this_cpu_ptr(np->tx_stats);
-	struct xen_netif_tx_request *tx, *first_tx;
+	struct xen_netif_tx_request *first_tx;
 	unsigned int i;
 	int notify;
 	int slots;
@@ -580,6 +570,7 @@ static netdev_tx_t xennet_start_xmit(str
 	unsigned int len;
 	unsigned long flags;
 	struct netfront_queue *queue = NULL;
+	struct xennet_gnttab_make_txreq info = { };
 	unsigned int num_queues = dev->real_num_tx_queues;
 	u16 queue_index;
 	struct sk_buff *nskb;
@@ -637,21 +628,24 @@ static netdev_tx_t xennet_start_xmit(str
 	}
 
 	/* First request for the linear area. */
-	first_tx = tx = xennet_make_first_txreq(queue, skb,
-						page, offset, len);
-	offset += tx->size;
+	info.queue = queue;
+	info.skb = skb;
+	info.page = page;
+	first_tx = xennet_make_first_txreq(&info, offset, len);
+	offset += info.tx_local.size;
 	if (offset == PAGE_SIZE) {
 		page++;
 		offset = 0;
 	}
-	len -= tx->size;
+	len -= info.tx_local.size;
 
 	if (skb->ip_summed == CHECKSUM_PARTIAL)
 		/* local packet? */
-		tx->flags |= XEN_NETTXF_csum_blank | XEN_NETTXF_data_validated;
+		first_tx->flags |= XEN_NETTXF_csum_blank |
+				   XEN_NETTXF_data_validated;
 	else if (skb->ip_summed == CHECKSUM_UNNECESSARY)
 		/* remote but checksummed. */
-		tx->flags |= XEN_NETTXF_data_validated;
+		first_tx->flags |= XEN_NETTXF_data_validated;
 
 	/* Optional extra info after the first request. */
 	if (skb_shinfo(skb)->gso_size) {
@@ -660,7 +654,7 @@ static netdev_tx_t xennet_start_xmit(str
 		gso = (struct xen_netif_extra_info *)
 			RING_GET_REQUEST(&queue->tx, queue->tx.req_prod_pvt++);
 
-		tx->flags |= XEN_NETTXF_extra_info;
+		first_tx->flags |= XEN_NETTXF_extra_info;
 
 		gso->u.gso.size = skb_shinfo(skb)->gso_size;
 		gso->u.gso.type = (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) ?
@@ -674,13 +668,13 @@ static netdev_tx_t xennet_start_xmit(str
 	}
 
 	/* Requests for the rest of the linear area. */
-	tx = xennet_make_txreqs(queue, tx, skb, page, offset, len);
+	xennet_make_txreqs(&info, page, offset, len);
 
 	/* Requests for all the frags. */
 	for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
 		skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
-		tx = xennet_make_txreqs(queue, tx, skb,
-					skb_frag_page(frag), frag->page_offset,
+		xennet_make_txreqs(&info, skb_frag_page(frag),
+					frag->page_offset,
 					skb_frag_size(frag));
 	}
 



  parent reply	other threads:[~2021-11-29 22:15 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-29 18:17 [PATCH 4.19 00/69] 4.19.219-rc1 review Greg Kroah-Hartman
2021-11-29 18:17 ` [PATCH 4.19 01/69] USB: serial: option: add Telit LE910S1 0x9200 composition Greg Kroah-Hartman
2021-11-29 18:17 ` [PATCH 4.19 02/69] USB: serial: option: add Fibocom FM101-GL variants Greg Kroah-Hartman
2021-11-29 18:17 ` [PATCH 4.19 03/69] usb: dwc2: hcd_queue: Fix use of floating point literal Greg Kroah-Hartman
2021-11-29 18:17 ` [PATCH 4.19 04/69] usb: hub: Fix usb enumeration issue due to address0 race Greg Kroah-Hartman
2021-11-29 18:17 ` [PATCH 4.19 05/69] usb: hub: Fix locking issues with address0_mutex Greg Kroah-Hartman
2021-11-29 18:17 ` [PATCH 4.19 06/69] binder: fix test regression due to sender_euid change Greg Kroah-Hartman
2021-11-29 18:17 ` [PATCH 4.19 07/69] ALSA: ctxfi: Fix out-of-range access Greg Kroah-Hartman
2021-11-29 18:17 ` [PATCH 4.19 08/69] media: cec: copy sequence field for the reply Greg Kroah-Hartman
2021-11-29 18:17 ` [PATCH 4.19 09/69] HID: wacom: Use "Confidence" flag to prevent reporting invalid contacts Greg Kroah-Hartman
2021-11-29 18:17 ` [PATCH 4.19 10/69] staging: rtl8192e: Fix use after free in _rtl92e_pci_disconnect() Greg Kroah-Hartman
2021-11-29 18:17 ` [PATCH 4.19 11/69] fuse: fix page stealing Greg Kroah-Hartman
2021-11-29 18:17 ` [PATCH 4.19 12/69] xen: dont continue xenstore initialization in case of errors Greg Kroah-Hartman
2021-11-29 18:17 ` [PATCH 4.19 13/69] xen: detect uninitialized xenbus in xenbus_init Greg Kroah-Hartman
2021-11-29 18:17 ` [PATCH 4.19 14/69] tracing: Fix pid filtering when triggers are attached Greg Kroah-Hartman
2021-11-29 18:17 ` [PATCH 4.19 15/69] xtensa: use CONFIG_USE_OF instead of CONFIG_OF Greg Kroah-Hartman
2021-11-29 18:17 ` [PATCH 4.19 16/69] proc/vmcore: fix clearing user buffer by properly using clear_user() Greg Kroah-Hartman
2021-11-29 18:17 ` [PATCH 4.19 17/69] PCI: aardvark: Fix a leaked reference by adding missing of_node_put() Greg Kroah-Hartman
2021-11-29 18:17   ` Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 18/69] PCI: aardvark: Wait for endpoint to be ready before training link Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 19/69] PCI: aardvark: Train link immediately after enabling training Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 20/69] PCI: aardvark: Improve link training Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 21/69] PCI: aardvark: Issue PERST via GPIO Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 22/69] PCI: aardvark: Replace custom macros by standard linux/pci_regs.h macros Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 23/69] PCI: aardvark: Indicate error in val when config read fails Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 24/69] PCI: aardvark: Dont touch PCIe registers if no card connected Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 25/69] PCI: aardvark: Fix compilation on s390 Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 26/69] PCI: aardvark: Move PCIe reset card code to advk_pcie_train_link() Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 27/69] PCI: aardvark: Update comment about disabling link training Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 28/69] PCI: aardvark: Configure PCIe resources from ranges DT property Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 29/69] PCI: aardvark: Fix PCIe Max Payload Size setting Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 30/69] PCI: aardvark: Fix link training Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 31/69] PCI: aardvark: Fix checking for link up via LTSSM state Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 32/69] pinctrl: armada-37xx: Correct mpp definitions Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 33/69] pinctrl: armada-37xx: add missing pin: PCIe1 Wakeup Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 34/69] pinctrl: armada-37xx: Correct PWM pins definitions Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 35/69] arm64: dts: marvell: armada-37xx: declare PCIe reset pin Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 36/69] arm64: dts: marvell: armada-37xx: Set pcie_reset_pin to gpio function Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 37/69] netfilter: ipvs: Fix reuse connection if RS weight is 0 Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 38/69] ARM: dts: BCM5301X: Fix I2C controller interrupt Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 39/69] ARM: dts: BCM5301X: Add interrupt properties to GPIO node Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 40/69] ASoC: qdsp6: q6routing: Conditionally reset FrontEnd Mixer Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 41/69] ASoC: topology: Add missing rwsem around snd_ctl_remove() calls Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 42/69] net: ieee802154: handle iftypes as u32 Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 43/69] firmware: arm_scmi: pm: Propagate return value to caller Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 44/69] NFSv42: Dont fail clone() unless the OP_CLONE operation failed Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 45/69] ARM: socfpga: Fix crash with CONFIG_FORTIRY_SOURCE Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 46/69] scsi: mpt3sas: Fix kernel panic during drive powercycle test Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 47/69] drm/vc4: fix error code in vc4_create_object() Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 48/69] ipv6: fix typos in __ip6_finish_output() Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 49/69] net/smc: Ensure the active closing peer first closes clcsock Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 50/69] PM: hibernate: use correct mode for swsusp_close() Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 51/69] tcp_cubic: fix spurious Hystart ACK train detections for not-cwnd-limited flows Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 52/69] MIPS: use 3-level pgtable for 64KB page size on MIPS_VA_BITS_48 Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 53/69] net/smc: Dont call clcsock shutdown twice when smc shutdown Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 54/69] net: hns3: fix VF RSS failed problem after PF enable multi-TCs Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 55/69] vhost/vsock: fix incorrect used length reported to the guest Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 56/69] tracing: Check pid filtering when creating events Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 57/69] s390/mm: validate VMA in PGSTE manipulation functions Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 58/69] hugetlbfs: flush TLBs correctly after huge_pmd_unshare Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 59/69] NFC: add NCI_UNREG flag to eliminate the race Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 60/69] fuse: release pipe buf after last use Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 61/69] xen: sync include/xen/interface/io/ring.h with Xens newest version Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 62/69] xen/blkfront: read response from backend only once Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 63/69] xen/blkfront: dont take local copy of a request from the ring page Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 64/69] xen/blkfront: dont trust the backend response data blindly Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 65/69] xen/netfront: read response from backend only once Greg Kroah-Hartman
2021-11-29 18:18 ` Greg Kroah-Hartman [this message]
2021-11-29 18:18 ` [PATCH 4.19 67/69] xen/netfront: disentangle tx_skb_freelist Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 68/69] xen/netfront: dont trust the backend response data blindly Greg Kroah-Hartman
2021-11-29 18:18 ` [PATCH 4.19 69/69] tty: hvc: replace BUG_ON() with negative return value Greg Kroah-Hartman
2021-11-30  1:04 ` [PATCH 4.19 00/69] 4.19.219-rc1 review Shuah Khan
2021-11-30  1:24 ` Samuel Zou
2021-11-30  8:42 ` Jon Hunter
2021-11-30  9:32 ` Naresh Kamboju
2021-11-30 13:38 ` Sudip Mukherjee
2021-11-30 16:02 ` Pavel Machek
2021-11-30 17:42 ` Guenter Roeck

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=20211129181705.791385322@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=davem@davemloft.net \
    --cc=jbeulich@suse.com \
    --cc=jgross@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.