From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Andres Beltran <lkmlabelt@gmail.com>,
Andrea Parri <parri.andrea@gmail.com>,
Michael Kelley <mikelley@microsoft.com>,
Jakub Kicinski <kuba@kernel.org>, Wei Liu <wei.liu@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
netdev@vger.kernel.org, Sasha Levin <sashal@kernel.org>
Subject: [PATCH 5.10 52/73] hv_netvsc: Use vmbus_requestor to generate transaction IDs for VMBus hardening
Date: Wed, 13 Mar 2024 12:46:19 -0400 [thread overview]
Message-ID: <20240313164640.616049-53-sashal@kernel.org> (raw)
In-Reply-To: <20240313164640.616049-1-sashal@kernel.org>
From: Andres Beltran <lkmlabelt@gmail.com>
[ Upstream commit 4d18fcc95f50950a99bd940d4e61a983f91d267a ]
Currently, pointers to guest memory are passed to Hyper-V as
transaction IDs in netvsc. In the face of errors or malicious
behavior in Hyper-V, netvsc should not expose or trust the transaction
IDs returned by Hyper-V to be valid guest memory addresses. Instead,
use small integers generated by vmbus_requestor as requests
(transaction) IDs.
Signed-off-by: Andres Beltran <lkmlabelt@gmail.com>
Co-developed-by: Andrea Parri (Microsoft) <parri.andrea@gmail.com>
Signed-off-by: Andrea Parri (Microsoft) <parri.andrea@gmail.com>
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
Acked-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Wei Liu <wei.liu@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: netdev@vger.kernel.org
Link: https://lore.kernel.org/r/20201109100402.8946-4-parri.andrea@gmail.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Stable-dep-of: 9cae43da9867 ("hv_netvsc: Register VF in netvsc_probe if NET_DEVICE_REGISTER missed")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/net/hyperv/hyperv_net.h | 13 +++++++++++++
drivers/net/hyperv/netvsc.c | 22 ++++++++++++++++------
drivers/net/hyperv/rndis_filter.c | 1 +
include/linux/hyperv.h | 1 +
4 files changed, 31 insertions(+), 6 deletions(-)
diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
index 367878493e704..15652d7951f9e 100644
--- a/drivers/net/hyperv/hyperv_net.h
+++ b/drivers/net/hyperv/hyperv_net.h
@@ -847,6 +847,19 @@ struct nvsp_message {
#define NETVSC_XDP_HDRM 256
+#define NETVSC_MIN_OUT_MSG_SIZE (sizeof(struct vmpacket_descriptor) + \
+ sizeof(struct nvsp_message))
+#define NETVSC_MIN_IN_MSG_SIZE sizeof(struct vmpacket_descriptor)
+
+/* Estimated requestor size:
+ * out_ring_size/min_out_msg_size + in_ring_size/min_in_msg_size
+ */
+static inline u32 netvsc_rqstor_size(unsigned long ringbytes)
+{
+ return ringbytes / NETVSC_MIN_OUT_MSG_SIZE +
+ 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))
diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index 3eae31c0f97a6..c9b73a0448813 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -50,7 +50,7 @@ void netvsc_switch_datapath(struct net_device *ndev, bool vf)
vmbus_sendpacket(dev->channel, init_pkt,
sizeof(struct nvsp_message),
- (unsigned long)init_pkt,
+ VMBUS_RQST_ID_NO_RESPONSE,
VM_PKT_DATA_INBAND, 0);
}
@@ -163,7 +163,7 @@ static void netvsc_revoke_recv_buf(struct hv_device *device,
ret = vmbus_sendpacket(device->channel,
revoke_packet,
sizeof(struct nvsp_message),
- (unsigned long)revoke_packet,
+ VMBUS_RQST_ID_NO_RESPONSE,
VM_PKT_DATA_INBAND, 0);
/* If the failure is because the channel is rescinded;
* ignore the failure since we cannot send on a rescinded
@@ -213,7 +213,7 @@ static void netvsc_revoke_send_buf(struct hv_device *device,
ret = vmbus_sendpacket(device->channel,
revoke_packet,
sizeof(struct nvsp_message),
- (unsigned long)revoke_packet,
+ VMBUS_RQST_ID_NO_RESPONSE,
VM_PKT_DATA_INBAND, 0);
/* If the failure is because the channel is rescinded;
@@ -557,7 +557,7 @@ static int negotiate_nvsp_ver(struct hv_device *device,
ret = vmbus_sendpacket(device->channel, init_packet,
sizeof(struct nvsp_message),
- (unsigned long)init_packet,
+ VMBUS_RQST_ID_NO_RESPONSE,
VM_PKT_DATA_INBAND, 0);
return ret;
@@ -614,7 +614,7 @@ static int netvsc_connect_vsp(struct hv_device *device,
/* Send the init request */
ret = vmbus_sendpacket(device->channel, init_packet,
sizeof(struct nvsp_message),
- (unsigned long)init_packet,
+ VMBUS_RQST_ID_NO_RESPONSE,
VM_PKT_DATA_INBAND, 0);
if (ret != 0)
goto cleanup;
@@ -698,10 +698,19 @@ static void netvsc_send_tx_complete(struct net_device *ndev,
const struct vmpacket_descriptor *desc,
int budget)
{
- struct sk_buff *skb = (struct sk_buff *)(unsigned long)desc->trans_id;
struct net_device_context *ndev_ctx = netdev_priv(ndev);
+ struct sk_buff *skb;
u16 q_idx = 0;
int queue_sends;
+ u64 cmd_rqst;
+
+ cmd_rqst = vmbus_request_addr(&channel->requestor, (u64)desc->trans_id);
+ if (cmd_rqst == VMBUS_RQST_ERROR) {
+ netdev_err(ndev, "Incorrect transaction id\n");
+ return;
+ }
+
+ skb = (struct sk_buff *)(unsigned long)cmd_rqst;
/* Notify the layer above us */
if (likely(skb)) {
@@ -1530,6 +1539,7 @@ struct netvsc_device *netvsc_device_add(struct hv_device *device,
netvsc_poll, NAPI_POLL_WEIGHT);
/* Open the channel */
+ device->channel->rqstor_size = netvsc_rqstor_size(netvsc_ring_bytes);
ret = vmbus_open(device->channel, netvsc_ring_bytes,
netvsc_ring_bytes, NULL, 0,
netvsc_channel_cb, net_device->chan_table);
diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
index 90bc0008fa2fd..13f62950eeb9f 100644
--- a/drivers/net/hyperv/rndis_filter.c
+++ b/drivers/net/hyperv/rndis_filter.c
@@ -1170,6 +1170,7 @@ static void netvsc_sc_open(struct vmbus_channel *new_sc)
/* Set the channel before opening.*/
nvchan->channel = new_sc;
+ new_sc->rqstor_size = netvsc_rqstor_size(netvsc_ring_bytes);
ret = vmbus_open(new_sc, netvsc_ring_bytes,
netvsc_ring_bytes, NULL, 0,
netvsc_channel_cb, nvchan);
diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index 4cb65a79d92f6..2aaf450c8d800 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -779,6 +779,7 @@ struct vmbus_requestor {
#define VMBUS_NO_RQSTOR U64_MAX
#define VMBUS_RQST_ERROR (U64_MAX - 1)
+#define VMBUS_RQST_ID_NO_RESPONSE (U64_MAX - 2)
struct vmbus_device {
u16 dev_type;
--
2.43.0
next prev parent reply other threads:[~2024-03-13 16:47 UTC|newest]
Thread overview: 98+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-13 16:45 [PATCH 5.10 00/73] 5.10.213-rc1 review Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 01/73] mmc: mmci: stm32: use a buffer for unaligned DMA requests Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 02/73] mmc: mmci: stm32: fix DMA API overlapping mappings warning Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 03/73] lan78xx: Fix white space and style issues Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 04/73] lan78xx: Add missing return code checks Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 05/73] lan78xx: Fix partial packet errors on suspend/resume Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 06/73] lan78xx: Fix race conditions in suspend/resume handling Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 07/73] net: lan78xx: fix runtime PM count underflow on link stop Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 08/73] ixgbe: {dis, en}able irqs in ixgbe_txrx_ring_{dis, en}able Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 09/73] i40e: disable NAPI right after disabling irqs when handling xsk_pool Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 10/73] tracing/net_sched: Fix tracepoints that save qdisc_dev() as a string Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 11/73] geneve: make sure to pull inner header in geneve_rx() Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 12/73] net: ice: Fix potential NULL pointer dereference in ice_bridge_setlink() Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 13/73] net/ipv6: avoid possible UAF in ip6_route_mpath_notify() Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 14/73] cpumap: Zero-initialise xdp_rxq_info struct before running XDP program Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 15/73] net/rds: fix WARNING in rds_conn_connect_if_down Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 16/73] netfilter: nft_ct: fix l3num expectations with inet pseudo family Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 17/73] netfilter: nf_conntrack_h323: Add protection for bmp length out of range Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 18/73] netrom: Fix a data-race around sysctl_netrom_default_path_quality Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 19/73] netrom: Fix a data-race around sysctl_netrom_obsolescence_count_initialiser Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 20/73] netrom: Fix data-races around sysctl_netrom_network_ttl_initialiser Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 21/73] netrom: Fix a data-race around sysctl_netrom_transport_timeout Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 22/73] netrom: Fix a data-race around sysctl_netrom_transport_maximum_tries Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 23/73] netrom: Fix a data-race around sysctl_netrom_transport_acknowledge_delay Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 24/73] netrom: Fix a data-race around sysctl_netrom_transport_busy_delay Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 25/73] netrom: Fix a data-race around sysctl_netrom_transport_requested_window_size Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 26/73] netrom: Fix a data-race around sysctl_netrom_transport_no_activity_timeout Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 27/73] netrom: Fix a data-race around sysctl_netrom_routing_control Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 28/73] netrom: Fix a data-race around sysctl_netrom_link_fails_count Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 29/73] netrom: Fix data-races around sysctl_net_busy_read Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 30/73] selftests/mm: switch to bash from sh Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 31/73] selftests: mm: fix map_hugetlb failure on 64K page size systems Sasha Levin
2024-03-13 16:45 ` [PATCH 5.10 32/73] um: allow not setting extra rpaths in the linux binary Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 33/73] xhci: remove extra loop in interrupt context Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 34/73] xhci: prevent double-fetch of transfer and transfer event TRBs Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 35/73] xhci: process isoc TD properly when there was a transaction error mid TD Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 36/73] xhci: handle isoc Babble and Buffer Overrun events properly Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 37/73] serial: max310x: Use devm_clk_get_optional() to get the input clock Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 38/73] serial: max310x: Try to get crystal clock rate from property Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 39/73] serial: max310x: fail probe if clock crystal is unstable Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 40/73] serial: max310x: Make use of device properties Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 41/73] serial: max310x: use regmap methods for SPI batch operations Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 42/73] serial: max310x: use a separate regmap for each port Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 43/73] serial: max310x: prevent infinite while() loop in port startup Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 44/73] net: Change sock_getsockopt() to take the sk ptr instead of the sock ptr Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 45/73] bpf: net: Change sk_getsockopt() to take the sockptr_t argument Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 46/73] lsm: make security_socket_getpeersec_stream() sockptr_t safe Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 47/73] lsm: fix default return value of the socket_getpeersec_*() hooks Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 48/73] ext4: make ext4_es_insert_extent() return void Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 49/73] ext4: refactor ext4_da_map_blocks() Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 50/73] ext4: convert to exclusive lock while inserting delalloc extents Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 51/73] Drivers: hv: vmbus: Add vmbus_requestor data structure for VMBus hardening Sasha Levin
2024-03-13 16:46 ` Sasha Levin [this message]
2024-03-13 16:46 ` [PATCH 5.10 53/73] hv_netvsc: Wait for completion on request SWITCH_DATA_PATH Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 54/73] hv_netvsc: Process NETDEV_GOING_DOWN on VF hot remove Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 55/73] hv_netvsc: Make netvsc/VF binding check both MAC and serial number Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 56/73] hv_netvsc: use netif_is_bond_master() instead of open code Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 57/73] hv_netvsc: Register VF in netvsc_probe if NET_DEVICE_REGISTER missed Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 58/73] mm/hugetlb: change hugetlb_reserve_pages() to type bool Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 59/73] mm: hugetlb pages should not be reserved by shmat() if SHM_NORESERVE Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 60/73] getrusage: add the "signal_struct *sig" local variable Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 61/73] getrusage: move thread_group_cputime_adjusted() outside of lock_task_sighand() Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 62/73] getrusage: use __for_each_thread() Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 63/73] getrusage: use sig->stats_lock rather than lock_task_sighand() Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 64/73] exit: Fix typo in comment: s/sub-theads/sub-threads Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 65/73] exit: wait_task_zombie: kill the no longer necessary spin_lock_irq(siglock) Sasha Levin
2024-03-13 17:03 ` Oleg Nesterov
2024-03-13 20:10 ` Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 66/73] serial: max310x: Unprepare and disable clock in error path Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 67/73] Drivers: hv: vmbus: Drop error message when 'No request id available' Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 68/73] regmap: allow to define reg_update_bits for no bus configuration Sasha Levin
2024-03-13 16:52 ` Mark Brown
2024-03-13 16:46 ` [PATCH 5.10 69/73] regmap: Add bulk read/write callbacks into regmap_config Sasha Levin
2024-03-13 16:53 ` Mark Brown
2024-03-13 16:46 ` [PATCH 5.10 70/73] serial: max310x: make accessing revision id interface-agnostic Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 71/73] serial: max310x: implement I2C support Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 72/73] serial: max310x: fix IO data corruption in batched operations Sasha Levin
2024-03-13 16:46 ` [PATCH 5.10 73/73] Linux 5.10.213-rc1 Sasha Levin
2024-03-13 20:05 ` [PATCH 5.10 00/73] 5.10.213-rc1 review Pavel Machek
2024-03-14 7:03 ` Dominique Martinet
2024-03-14 15:07 ` Daniel Díaz
2024-03-15 16:52 ` Sasha Levin
2024-03-14 14:50 ` Naresh Kamboju
2024-03-14 19:52 ` Florian Fainelli
2024-03-14 21:47 ` Salvatore Bonaccorso
2024-03-15 18:39 ` Sasha Levin
2024-03-26 6:59 ` Salvatore Bonaccorso
2024-03-27 13:45 ` Greg Kroah-Hartman
2024-03-15 10:48 ` Shreeya Patel
2024-03-20 13:41 ` Pavel Machek
2024-03-20 20:03 ` Marek Vasut
2024-03-22 9:48 ` Pavel Machek
2024-03-22 11:23 ` Marek Vasut
2024-03-22 13:35 ` Pavel Machek
2024-03-20 13:44 ` btrfs fix missing in 5.10-stable was " Pavel Machek
2024-03-20 22:12 ` Sasha Levin
2024-03-25 6:55 ` Daniel Díaz
2024-03-25 15:20 ` Daniel Díaz
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=20240313164640.616049-53-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lkmlabelt@gmail.com \
--cc=mikelley@microsoft.com \
--cc=netdev@vger.kernel.org \
--cc=parri.andrea@gmail.com \
--cc=stable@vger.kernel.org \
--cc=wei.liu@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome