diff mbox series

[3/3] scsi: storvsc: Validate length of incoming packet in storvsc_on_channel_callback()

Message ID 20201217203321.4539-4-parri.andrea@gmail.com
State New
Headers show
Series [1/3] scsi: storvsc: Fix max_outstanding_req_per_channel for Win8 and newer | expand

Commit Message

Andrea Parri Dec. 17, 2020, 8:33 p.m. UTC
Check that the packet is of the expected size at least, don't copy data
past the packet.

Reported-by: Saruhan Karademir <skarade@microsoft.com>
Signed-off-by: Andrea Parri (Microsoft) <parri.andrea@gmail.com>
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org
---
 drivers/scsi/storvsc_drv.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Dexuan Cui Dec. 17, 2020, 9:31 p.m. UTC | #1
> From: Andrea Parri (Microsoft) <parri.andrea@gmail.com>
> Sent: Thursday, December 17, 2020 12:33 PM
> 
> Check that the packet is of the expected size at least, don't copy data
> past the packet.
> 
> Reported-by: Saruhan Karademir <skarade@microsoft.com>
> Signed-off-by: Andrea Parri (Microsoft) <parri.andrea@gmail.com>
> Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
> Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
> Cc: linux-scsi@vger.kernel.org

Reviewed-by: Dexuan Cui <decui@microsoft.com>
Michael Kelley Dec. 18, 2020, 3:16 p.m. UTC | #2
From: Andrea Parri (Microsoft) <parri.andrea@gmail.com> Sent: Thursday, December 17, 2020 12:33 PM

> 

> Check that the packet is of the expected size at least, don't copy data

> past the packet.

> 

> Reported-by: Saruhan Karademir <skarade@microsoft.com>

> Signed-off-by: Andrea Parri (Microsoft) <parri.andrea@gmail.com>

> Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>

> Cc: "Martin K. Petersen" <martin.petersen@oracle.com>

> Cc: linux-scsi@vger.kernel.org

> ---

>  drivers/scsi/storvsc_drv.c | 6 ++++++

>  1 file changed, 6 insertions(+)

> 

> diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c

> index 8714355cb63e7..4b8bde2750fac 100644

> --- a/drivers/scsi/storvsc_drv.c

> +++ b/drivers/scsi/storvsc_drv.c

> @@ -1250,6 +1250,12 @@ static void storvsc_on_channel_callback(void *context)

>  		request = (struct storvsc_cmd_request *)

>  			((unsigned long)desc->trans_id);

> 

> +		if (hv_pkt_datalen(desc) < sizeof(struct vstor_packet) -

> +				stor_device->vmscsi_size_delta) {

> +			dev_err(&device->device, "Invalid packet len\n");

> +			continue;

> +		}

> +

>  		if (request == &stor_device->init_request ||

>  		    request == &stor_device->reset_request) {

>  			memcpy(&request->vstor_packet, packet,

> --

> 2.25.1


Reviewed-by: Michael Kelley <mikelley@microsoft.com>
Olaf Hering March 29, 2021, 4:37 p.m. UTC | #3
On Thu, Dec 17, Andrea Parri (Microsoft) wrote:

> Check that the packet is of the expected size at least, don't copy data

> past the packet.


> +		if (hv_pkt_datalen(desc) < sizeof(struct vstor_packet) -

> +				stor_device->vmscsi_size_delta) {

> +			dev_err(&device->device, "Invalid packet len\n");

> +			continue;

> +		}

> +


Sorry for being late:

It might be just cosmetic, but should this check be done prior the call to vmbus_request_addr()?


Unrelated: my copy of vmbus_request_addr() can return 0, which is apparently not handled by this loop in storvsc_on_channel_callback().


Olaf
Andrea Parri March 30, 2021, 9:08 a.m. UTC | #4
Hi Olaf,

On Mon, Mar 29, 2021 at 06:37:21PM +0200, Olaf Hering wrote:
> On Thu, Dec 17, Andrea Parri (Microsoft) wrote:

> 

> > Check that the packet is of the expected size at least, don't copy data

> > past the packet.

> 

> > +		if (hv_pkt_datalen(desc) < sizeof(struct vstor_packet) -

> > +				stor_device->vmscsi_size_delta) {

> > +			dev_err(&device->device, "Invalid packet len\n");

> > +			continue;

> > +		}

> > +

> 

> Sorry for being late:

> 

> It might be just cosmetic, but should this check be done prior the call to vmbus_request_addr()?


TBH, I'm not immediately seeing why it 'should'; it could make sense to move
the check on the packet data length.


> Unrelated: my copy of vmbus_request_addr() can return 0, which is apparently not handled by this loop in storvsc_on_channel_callback().


Indeed, IDs of 0 are reserved for so called unsolicited messages; I think we
should check that storvsc_on_io_completion() is not called on such messages.

Thanks,
  Andrea
diff mbox series

Patch

diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
index 8714355cb63e7..4b8bde2750fac 100644
--- a/drivers/scsi/storvsc_drv.c
+++ b/drivers/scsi/storvsc_drv.c
@@ -1250,6 +1250,12 @@  static void storvsc_on_channel_callback(void *context)
 		request = (struct storvsc_cmd_request *)
 			((unsigned long)desc->trans_id);
 
+		if (hv_pkt_datalen(desc) < sizeof(struct vstor_packet) -
+				stor_device->vmscsi_size_delta) {
+			dev_err(&device->device, "Invalid packet len\n");
+			continue;
+		}
+
 		if (request == &stor_device->init_request ||
 		    request == &stor_device->reset_request) {
 			memcpy(&request->vstor_packet, packet,