|
Olaf Hering |
1788de |
From: "Andrea Parri (Microsoft)" <parri.andrea@gmail.com>
|
|
Olaf Hering |
1788de |
Date: Thu, 7 Oct 2021 14:28:28 +0200
|
|
Olaf Hering |
1788de |
Patch-mainline: v5.15-rc7
|
|
Olaf Hering |
1788de |
Subject: scsi: storvsc: Fix validation for unsolicited incoming packets
|
|
Olaf Hering |
1788de |
Git-commit: 6fd13d699d24beaa28310848fe65fd898fbb9043
|
|
Olaf Hering |
1788de |
References: bsc#1204017
|
|
Olaf Hering |
1788de |
|
|
Olaf Hering |
1788de |
The validation on the length of incoming packets performed in
|
|
Olaf Hering |
1788de |
storvsc_on_channel_callback() does not apply to unsolicited packets with ID
|
|
Olaf Hering |
1788de |
of 0 sent by Hyper-V. Adjust the validation for such unsolicited packets.
|
|
Olaf Hering |
1788de |
|
|
Olaf Hering |
1788de |
Link: https://lore.kernel.org/r/20211007122828.469289-1-parri.andrea@gmail.com
|
|
Olaf Hering |
1788de |
Fixes: 91b1b640b834b2 ("scsi: storvsc: Validate length of incoming packet in storvsc_on_channel_callback()")
|
|
Olaf Hering |
1788de |
Reported-by: Dexuan Cui <decui@microsoft.com>
|
|
Olaf Hering |
1788de |
Reviewed-by: Michael Kelley <mikelley@microsoft.com>
|
|
Olaf Hering |
1788de |
Reviewed-by: Haiyang Zhang <haiyangz@microsoft.com>
|
|
Olaf Hering |
1788de |
Signed-off-by: Andrea Parri (Microsoft) <parri.andrea@gmail.com>
|
|
Olaf Hering |
1788de |
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
|
|
Olaf Hering |
1788de |
Acked-by: Olaf Hering <ohering@suse.de>
|
|
Olaf Hering |
1788de |
---
|
|
Olaf Hering |
1788de |
drivers/scsi/storvsc_drv.c | 32 ++++++++++++++++------
|
|
Olaf Hering |
1788de |
1 file changed, 23 insertions(+), 9 deletions(-)
|
|
Olaf Hering |
1788de |
|
|
Olaf Hering |
1788de |
diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
|
|
Olaf Hering |
1788de |
--- a/drivers/scsi/storvsc_drv.c
|
|
Olaf Hering |
1788de |
+++ b/drivers/scsi/storvsc_drv.c
|
|
Olaf Hering |
1788de |
@@ -1285,11 +1285,15 @@ static void storvsc_on_channel_callback(void *context)
|
|
Olaf Hering |
1788de |
foreach_vmbus_pkt(desc, channel) {
|
|
Olaf Hering |
1788de |
struct vstor_packet *packet = hv_pkt_data(desc);
|
|
Olaf Hering |
1788de |
struct storvsc_cmd_request *request = NULL;
|
|
Olaf Hering |
1788de |
+ u32 pktlen = hv_pkt_datalen(desc);
|
|
Olaf Hering |
1788de |
u64 rqst_id = desc->trans_id;
|
|
Olaf Hering |
1788de |
+ u32 minlen = rqst_id ? sizeof(struct vstor_packet) -
|
|
Olaf Hering |
1788de |
+ stor_device->vmscsi_size_delta : sizeof(enum vstor_packet_operation);
|
|
Olaf Hering |
1788de |
|
|
Olaf Hering |
1788de |
- if (hv_pkt_datalen(desc) < sizeof(struct vstor_packet) -
|
|
Olaf Hering |
1788de |
- stor_device->vmscsi_size_delta) {
|
|
Olaf Hering |
1788de |
- dev_err(&device->device, "Invalid packet len\n");
|
|
Olaf Hering |
1788de |
+ if (pktlen < minlen) {
|
|
Olaf Hering |
1788de |
+ dev_err(&device->device,
|
|
Olaf Hering |
1788de |
+ "Invalid pkt: id=%llu, len=%u, minlen=%u\n",
|
|
Olaf Hering |
1788de |
+ rqst_id, pktlen, minlen);
|
|
Olaf Hering |
1788de |
continue;
|
|
Olaf Hering |
1788de |
}
|
|
Olaf Hering |
1788de |
|
|
Olaf Hering |
1788de |
@@ -1302,13 +1306,23 @@ static void storvsc_on_channel_callback(void *context)
|
|
Olaf Hering |
1788de |
if (rqst_id == 0) {
|
|
Olaf Hering |
1788de |
/*
|
|
Olaf Hering |
1788de |
* storvsc_on_receive() looks at the vstor_packet in the message
|
|
Olaf Hering |
1788de |
- * from the ring buffer. If the operation in the vstor_packet is
|
|
Olaf Hering |
1788de |
- * COMPLETE_IO, then we call storvsc_on_io_completion(), and
|
|
Olaf Hering |
1788de |
- * dereference the guest memory address. Make sure we don't call
|
|
Olaf Hering |
1788de |
- * storvsc_on_io_completion() with a guest memory address that is
|
|
Olaf Hering |
1788de |
- * zero if Hyper-V were to construct and send such a bogus packet.
|
|
Olaf Hering |
1788de |
+ * from the ring buffer.
|
|
Olaf Hering |
1788de |
+ *
|
|
Olaf Hering |
1788de |
+ * - If the operation in the vstor_packet is COMPLETE_IO, then
|
|
Olaf Hering |
1788de |
+ * we call storvsc_on_io_completion(), and dereference the
|
|
Olaf Hering |
1788de |
+ * guest memory address. Make sure we don't call
|
|
Olaf Hering |
1788de |
+ * storvsc_on_io_completion() with a guest memory address
|
|
Olaf Hering |
1788de |
+ * that is zero if Hyper-V were to construct and send such
|
|
Olaf Hering |
1788de |
+ * a bogus packet.
|
|
Olaf Hering |
1788de |
+ *
|
|
Olaf Hering |
1788de |
+ * - If the operation in the vstor_packet is FCHBA_DATA, then
|
|
Olaf Hering |
1788de |
+ * we call cache_wwn(), and access the data payload area of
|
|
Olaf Hering |
1788de |
+ * the packet (wwn_packet); however, there is no guarantee
|
|
Olaf Hering |
1788de |
+ * that the packet is big enough to contain such area.
|
|
Olaf Hering |
1788de |
+ * Future-proof the code by rejecting such a bogus packet.
|
|
Olaf Hering |
1788de |
*/
|
|
Olaf Hering |
1788de |
- if (packet->operation == VSTOR_OPERATION_COMPLETE_IO) {
|
|
Olaf Hering |
1788de |
+ if (packet->operation == VSTOR_OPERATION_COMPLETE_IO ||
|
|
Olaf Hering |
1788de |
+ packet->operation == VSTOR_OPERATION_FCHBA_DATA) {
|
|
Olaf Hering |
1788de |
dev_err(&device->device, "Invalid packet with ID of 0\n");
|
|
Olaf Hering |
1788de |
continue;
|
|
Olaf Hering |
1788de |
}
|