2020-12-17 20:35:26

by Andrea Parri

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

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

Reported-by: Saruhan Karademir <[email protected]>
Signed-off-by: Andrea Parri (Microsoft) <[email protected]>
Cc: "James E.J. Bottomley" <[email protected]>
Cc: "Martin K. Petersen" <[email protected]>
Cc: [email protected]
---
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


2020-12-17 21:35:18

by Dexuan Cui

[permalink] [raw]
Subject: RE: [PATCH 3/3] scsi: storvsc: Validate length of incoming packet in storvsc_on_channel_callback()

> From: Andrea Parri (Microsoft) <[email protected]>
> 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 <[email protected]>
> Signed-off-by: Andrea Parri (Microsoft) <[email protected]>
> Cc: "James E.J. Bottomley" <[email protected]>
> Cc: "Martin K. Petersen" <[email protected]>
> Cc: [email protected]

Reviewed-by: Dexuan Cui <[email protected]>

2020-12-18 15:18:25

by Michael Kelley (LINUX)

[permalink] [raw]
Subject: RE: [PATCH 3/3] scsi: storvsc: Validate length of incoming packet in storvsc_on_channel_callback()

From: Andrea Parri (Microsoft) <[email protected]> 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 <[email protected]>
> Signed-off-by: Andrea Parri (Microsoft) <[email protected]>
> Cc: "James E.J. Bottomley" <[email protected]>
> Cc: "Martin K. Petersen" <[email protected]>
> Cc: [email protected]
> ---
> 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 <[email protected]>

2021-03-29 16:39:44

by Olaf Hering

[permalink] [raw]
Subject: Re: [PATCH 3/3] scsi: storvsc: Validate length of incoming packet in storvsc_on_channel_callback()

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




Attachments:
(No filename) (622.00 B)
signature.asc (849.00 B)
Download all attachments

2021-03-30 09:12:25

by Andrea Parri

[permalink] [raw]
Subject: Re: [PATCH 3/3] scsi: storvsc: Validate length of incoming packet in storvsc_on_channel_callback()

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