* [PATCH] scsi: vmw_pscsi: Fix use-after-free in pvscsi_queue_lck()
@ 2019-06-19 7:05 Jan Kara
2019-06-19 15:13 ` Ewan D. Milne
2019-06-20 20:35 ` Martin K. Petersen
0 siblings, 2 replies; 3+ messages in thread
From: Jan Kara @ 2019-06-19 7:05 UTC (permalink / raw)
To: Jim Gill; +Cc: VMware PV-Drivers, linux-scsi, Jan Kara, stable
Once we unlock adapter->hw_lock in pvscsi_queue_lck() nothing prevents just
queued scsi_cmnd from completing and freeing the request. Thus cmd->cmnd[0]
dereference can dereference already freed request leading to kernel crashes or
other issues (which one of our customers observed). Store cmd->cmnd[0] in a
local variable before unlocking adapter->hw_lock to fix the issue.
CC: stable@vger.kernel.org
Signed-off-by: Jan Kara <jack@suse.cz>
---
drivers/scsi/vmw_pvscsi.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/vmw_pvscsi.c b/drivers/scsi/vmw_pvscsi.c
index ecee4b3ff073..377b07b2feeb 100644
--- a/drivers/scsi/vmw_pvscsi.c
+++ b/drivers/scsi/vmw_pvscsi.c
@@ -763,6 +763,7 @@ static int pvscsi_queue_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd
struct pvscsi_adapter *adapter = shost_priv(host);
struct pvscsi_ctx *ctx;
unsigned long flags;
+ unsigned char op;
spin_lock_irqsave(&adapter->hw_lock, flags);
@@ -775,13 +776,14 @@ static int pvscsi_queue_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd
}
cmd->scsi_done = done;
+ op = cmd->cmnd[0];
dev_dbg(&cmd->device->sdev_gendev,
- "queued cmd %p, ctx %p, op=%x\n", cmd, ctx, cmd->cmnd[0]);
+ "queued cmd %p, ctx %p, op=%x\n", cmd, ctx, op);
spin_unlock_irqrestore(&adapter->hw_lock, flags);
- pvscsi_kick_io(adapter, cmd->cmnd[0]);
+ pvscsi_kick_io(adapter, op);
return 0;
}
--
2.16.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] scsi: vmw_pscsi: Fix use-after-free in pvscsi_queue_lck()
2019-06-19 7:05 [PATCH] scsi: vmw_pscsi: Fix use-after-free in pvscsi_queue_lck() Jan Kara
@ 2019-06-19 15:13 ` Ewan D. Milne
2019-06-20 20:35 ` Martin K. Petersen
1 sibling, 0 replies; 3+ messages in thread
From: Ewan D. Milne @ 2019-06-19 15:13 UTC (permalink / raw)
To: Jan Kara, Jim Gill; +Cc: VMware PV-Drivers, linux-scsi, stable
On Wed, 2019-06-19 at 09:05 +0200, Jan Kara wrote:
> Once we unlock adapter->hw_lock in pvscsi_queue_lck() nothing prevents just
> queued scsi_cmnd from completing and freeing the request. Thus cmd->cmnd[0]
> dereference can dereference already freed request leading to kernel crashes or
> other issues (which one of our customers observed). Store cmd->cmnd[0] in a
> local variable before unlocking adapter->hw_lock to fix the issue.
>
> CC: stable@vger.kernel.org
> Signed-off-by: Jan Kara <jack@suse.cz>
> ---
> drivers/scsi/vmw_pvscsi.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/vmw_pvscsi.c b/drivers/scsi/vmw_pvscsi.c
> index ecee4b3ff073..377b07b2feeb 100644
> --- a/drivers/scsi/vmw_pvscsi.c
> +++ b/drivers/scsi/vmw_pvscsi.c
> @@ -763,6 +763,7 @@ static int pvscsi_queue_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd
> struct pvscsi_adapter *adapter = shost_priv(host);
> struct pvscsi_ctx *ctx;
> unsigned long flags;
> + unsigned char op;
>
> spin_lock_irqsave(&adapter->hw_lock, flags);
>
> @@ -775,13 +776,14 @@ static int pvscsi_queue_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd
> }
>
> cmd->scsi_done = done;
> + op = cmd->cmnd[0];
>
> dev_dbg(&cmd->device->sdev_gendev,
> - "queued cmd %p, ctx %p, op=%x\n", cmd, ctx, cmd->cmnd[0]);
> + "queued cmd %p, ctx %p, op=%x\n", cmd, ctx, op);
>
> spin_unlock_irqrestore(&adapter->hw_lock, flags);
>
> - pvscsi_kick_io(adapter, cmd->cmnd[0]);
> + pvscsi_kick_io(adapter, op);
>
> return 0;
> }
Reviewed-by: Ewan D. Milne <emilne@redhat.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] scsi: vmw_pscsi: Fix use-after-free in pvscsi_queue_lck()
2019-06-19 7:05 [PATCH] scsi: vmw_pscsi: Fix use-after-free in pvscsi_queue_lck() Jan Kara
2019-06-19 15:13 ` Ewan D. Milne
@ 2019-06-20 20:35 ` Martin K. Petersen
1 sibling, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2019-06-20 20:35 UTC (permalink / raw)
To: Jan Kara; +Cc: Jim Gill, VMware PV-Drivers, linux-scsi, stable
Jan,
> Once we unlock adapter->hw_lock in pvscsi_queue_lck() nothing prevents
> just queued scsi_cmnd from completing and freeing the request. Thus
> cmd->cmnd[0] dereference can dereference already freed request leading
> to kernel crashes or other issues (which one of our customers
> observed). Store cmd->cmnd[0] in a local variable before unlocking
> adapter->hw_lock to fix the issue.
Applied to 5.2/scsi-fixes. Thanks!
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-06-20 20:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-19 7:05 [PATCH] scsi: vmw_pscsi: Fix use-after-free in pvscsi_queue_lck() Jan Kara
2019-06-19 15:13 ` Ewan D. Milne
2019-06-20 20:35 ` Martin K. Petersen
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.