Skip to contentSkip to conversation

Drivers: hv: vmbus: Initialize unload_event statically

PATCH Applied Andrea Parri (Microsoft) 3 participants 3 messages Apr 20, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Drivers: hv: vmbus: Initialize unload_event statically

If a malicious or compromised Hyper-V sends a spurious message of type CHANNELMSG_UNLOAD_RESPONSE, the function vmbus_unload_response() will call complete() on an uninitialized event, and cause an oops.

---
Changes since v1[1]:
- add inline comment in vmbus_unload_response()

[1] https://lkml.kernel.org/r/[email protected]

 drivers/hv/channel_mgmt.c | 7 ++++++-
 drivers/hv/connection.c   | 2 ++
 2 files changed, 8 insertions(+), 1 deletion(-)
drivers/hv/channel_mgmt.c +6 -1
index 4c9e45d1f462c..335a10ee03a5e 100644
@@ -826,6 +826,11 @@ static void vmbus_unload_response(struct vmbus_channel_message_header *hdr)
 	/*
 	 * This is a global event; just wakeup the waiting thread.
 	 * Once we successfully unload, we can cleanup the monitor state.
+	 *
+	 * NB.  A malicious or compromised Hyper-V could send a spurious
+	 * message of type CHANNELMSG_UNLOAD_RESPONSE, and trigger a call
+	 * of the complete() below.  Make sure that unload_event has been
+	 * initialized by the time this complete() is executed.
 	 */
 	complete(&vmbus_connection.unload_event);
 }
@@ -841,7 +846,7 @@ void vmbus_initiate_unload(bool crash)
 	if (vmbus_proto_version < VERSION_WIN8_1)
 		return;
 
-	init_completion(&vmbus_connection.unload_event);
+	reinit_completion(&vmbus_connection.unload_event);
 	memset(&hdr, 0, sizeof(struct vmbus_channel_message_header));
 	hdr.msgtype = CHANNELMSG_UNLOAD;
 	vmbus_post_msg(&hdr, sizeof(struct vmbus_channel_message_header),
drivers/hv/connection.c +2 -0
index dc19d5ae4373c..311cd005b3be6 100644
@@ -26,6 +26,8 @@
 
 struct vmbus_connection vmbus_connection = {
 	.conn_state		= DISCONNECTED,
+	.unload_event		= COMPLETION_INITIALIZER(
+				  vmbus_connection.unload_event),
 	.next_gpadl_handle	= ATOMIC_INIT(0xE1E10),
 
 	.ready_for_suspend_event = COMPLETION_INITIALIZER(
Signature · 1 line
2.25.1
Reviewed-by on v2 1/1
#1 lore raw

From: Andrea Parri (Microsoft) <[email protected]> Sent: Monday, April 19, 2021 6:44 PM

Quoted 11 lines

If a malicious or compromised Hyper-V sends a spurious message of type CHANNELMSG_UNLOAD_RESPONSE, the function vmbus_unload_response() will call complete() on an uninitialized event, and cause an oops.

---
Changes since v1[1]:
- add inline comment in vmbus_unload_response()

Quoted 6 lines

[1] https://lore.kernel.org/linux-hyperv/[email protected]/

 drivers/hv/channel_mgmt.c | 7 ++++++-
 drivers/hv/connection.c   | 2 ++
 2 files changed, 8 insertions(+), 1 deletion(-)
Quoted 41 lines
drivers/hv/channel_mgmt.c +5 -0
index 4c9e45d1f462c..335a10ee03a5e 100644
@@ -826,6 +826,11 @@ static void vmbus_unload_response(struct
 vmbus_channel_message_header *hdr)
 	/*
 	 * This is a global event; just wakeup the waiting thread.
 	 * Once we successfully unload, we can cleanup the monitor state.
+	 *
+	 * NB.  A malicious or compromised Hyper-V could send a spurious
+	 * message of type CHANNELMSG_UNLOAD_RESPONSE, and trigger a call
+	 * of the complete() below.  Make sure that unload_event has been
+	 * initialized by the time this complete() is executed.
 	 */
 	complete(&vmbus_connection.unload_event);

}

drivers/hv/channel_mgmt.c +1 -1
@@ -841,7 +846,7 @@ void vmbus_initiate_unload(bool crash)
 	if (vmbus_proto_version < VERSION_WIN8_1)
 		return;
 
-	init_completion(&vmbus_connection.unload_event);
+	reinit_completion(&vmbus_connection.unload_event);
 	memset(&hdr, 0, sizeof(struct vmbus_channel_message_header));
 	hdr.msgtype = CHANNELMSG_UNLOAD;
 	vmbus_post_msg(&hdr, sizeof(struct vmbus_channel_message_header),
drivers/hv/connection.c +2 -1
index dc19d5ae4373c..311cd005b3be6 100644
@@ -26,6 +26,8 @@
 
 struct vmbus_connection vmbus_connection = {
 	.conn_state		= DISCONNECTED,
+	.unload_event		= COMPLETION_INITIALIZER(
+				  vmbus_connection.unload_event),
 	.next_gpadl_handle	= ATOMIC_INIT(0xE1E10),
 
 	.ready_for_suspend_event = COMPLETION_INITIALIZER(
--

2.25.1

maintainer Applied
#2 lore raw
Quoted 12 lines · Michael Kelley

From: Andrea Parri (Microsoft) <[email protected]> Sent: Monday, April 19, 2021 6:44 PM

Quoted 11 lines

If a malicious or compromised Hyper-V sends a spurious message of type CHANNELMSG_UNLOAD_RESPONSE, the function vmbus_unload_response() will call complete() on an uninitialized event, and cause an oops.

---
Changes since v1[1]:
- add inline comment in vmbus_unload_response()

Quoted 8 lines
Quoted 6 lines

[1] https://lore.kernel.org/linux-hyperv/[email protected]/

 drivers/hv/channel_mgmt.c | 7 ++++++-
 drivers/hv/connection.c   | 2 ++
 2 files changed, 8 insertions(+), 1 deletion(-)

Applied to hyperv-next. Thanks.