Skip to contentSkip to conversation

hv_netvsc: Add validation for untrusted Hyper-V values

PATCH Applied Andrea Parri (Microsoft) 3 participants 3 messages Sep 16, 2020 – Sep 17, 2020

Subsystems (4)

v3 of 4 Applied Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 hv_netvsc: Add validation for untrusted Hyper-V values

From: Andres Beltran <[email protected]>

For additional robustness in the face of Hyper-V errors or malicious behavior, validate all values that originate from packets that Hyper-V has sent to the guest in the host-to-guest ring buffer. Ensure that invalid values cannot cause indexing off the end of an array, or subvert an existing validation via integer overflow. Ensure that outgoing packets do not have any leftover guest memory that has not been zeroed out.

---
Changes in v3:
- Include header size in the estimate for hv_pkt_datalen (Haiyang)
Changes in v2:
- Replace size check on struct nvsp_message with sub-checks (Haiyang)

 drivers/net/hyperv/hyperv_net.h   |   4 +
 drivers/net/hyperv/netvsc.c       | 124 ++++++++++++++++++++++++++----
 drivers/net/hyperv/netvsc_drv.c   |   7 ++
 drivers/net/hyperv/rndis_filter.c |  73 ++++++++++++++++--
 4 files changed, 188 insertions(+), 20 deletions(-)
drivers/net/hyperv/hyperv_net.h +4 -0
index 4d2b2d48ff2a1..da78bd0fb2aa2 100644
@@ -860,6 +860,10 @@ static inline u32 netvsc_rqstor_size(unsigned long ringbytes)
 	       ringbytes / NETVSC_MIN_IN_MSG_SIZE;
 }
 
+#define NETVSC_XFER_HEADER_SIZE(rng_cnt) \
+		(offsetof(struct vmtransfer_page_packet_header, ranges) + \
+		(rng_cnt) * sizeof(struct vmtransfer_page_range))
+
 struct multi_send_data {
 	struct sk_buff *skb; /* skb containing the pkt */
 	struct hv_netvsc_packet *pkt; /* netvsc pkt pending */
drivers/net/hyperv/netvsc.c +111 -13

228 lines not on this page · raw message

drivers/net/hyperv/netvsc_drv.c +7 -0
index 787f17e2a9716..720a381c951f2 100644
@@ -748,6 +748,13 @@ void netvsc_linkstatus_callback(struct net_device *net,
 	struct netvsc_reconfig *event;
 	unsigned long flags;
 
+	/* Ensure the packet is big enough to access its fields */
+	if (resp->msg_len - RNDIS_HEADER_SIZE < sizeof(struct rndis_indicate_status)) {
+		netdev_err(net, "invalid rndis_indicate_status packet, len: %u\n",
+			   resp->msg_len);
+		return;
+	}
+
 	/* Update the physical link speed when changing to another vSwitch */
 	if (indicate->status == RNDIS_STATUS_LINK_SPEED_CHANGE) {
 		u32 speed;
drivers/net/hyperv/rndis_filter.c +66 -7

124 lines not on this page · raw message

Signature · 1 line
2.25.1
maintainer Reviewed-by on v3 1/1
#1 lore raw
Quoted 38 lines

-----Original Message-----
From: Andrea Parri (Microsoft) <[email protected]>
Sent: Wednesday, September 16, 2020 5:47 AM
To: [email protected]
Cc: KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; Stephen Hemminger <[email protected]>; Wei Liu <[email protected]>; linux- [email protected]; Andres Beltran <[email protected]>; Michael Kelley <[email protected]>; Saruhan Karademir <[email protected]>; Juan Vazquez <[email protected]>; Andrea Parri <[email protected]>; David S. Miller <[email protected]>; Jakub Kicinski <[email protected]>; [email protected]
Subject: [PATCH v3] hv_netvsc: Add validation for untrusted Hyper-V values

From: Andres Beltran <[email protected]>

For additional robustness in the face of Hyper-V errors or malicious behavior, validate all values that originate from packets that Hyper-V has sent to the guest in the host-to-guest ring buffer. Ensure that invalid values cannot cause indexing off the end of an array, or subvert an existing validation via integer overflow. Ensure that outgoing packets do not have any leftover guest memory that has not been zeroed out.

---
Changes in v3:
- Include header size in the estimate for hv_pkt_datalen (Haiyang)
Changes in v2:
- Replace size check on struct nvsp_message with sub-checks (Haiyang)

Quoted 5 lines
 drivers/net/hyperv/hyperv_net.h   |   4 +
 drivers/net/hyperv/netvsc.c       | 124 ++++++++++++++++++++++++++----
 drivers/net/hyperv/netvsc_drv.c   |   7 ++
 drivers/net/hyperv/rndis_filter.c |  73 ++++++++++++++++--
 4 files changed, 188 insertions(+), 20 deletions(-)
maintainer Applied
#2 lore raw
In reply to Andrea Parri (Microsoft)

From: "Andrea Parri (Microsoft)" <[email protected]>
Date: Wed, 16 Sep 2020 11:47:27 +0200

Quoted 10 lines

From: Andres Beltran <[email protected]>

For additional robustness in the face of Hyper-V errors or malicious behavior, validate all values that originate from packets that Hyper-V has sent to the guest in the host-to-guest ring buffer. Ensure that invalid values cannot cause indexing off the end of an array, or subvert an existing validation via integer overflow. Ensure that outgoing packets do not have any leftover guest memory that has not been zeroed out.

Quoted 3 lines

Applied, thank you.