scsi: vmw_pvscsi: clamp on e->dataLen in pvscsi_complete_request
Subsystems (2)
When calculating the residual bytes, clamp dataLen to the buffer length before the subtraction. This prevents an overflow if the device sends a larger value than expected.
Signed-off-by Matt Wang <[email protected]>
--- drivers/scsi/vmw_pvscsi.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/scsi/vmw_pvscsi.c +6 -3
@@ -548,6 +548,8 @@ static void pvscsi_complete_request(struct pvscsi_adapter *adapter,struct completion *abort_cmp;u32 btstat = e->hostStatus;u32 sdstat = e->scsiStatus; +u64 data_len = e->dataLen; +u32 data_trans =0 ; ctx =pvscsi_get_context (adapter, e->context); cmd = ctx->cmd;
@@ -590,15 +592,16 @@ static void pvscsi_complete_request(struct pvscsi_adapter *adapter,* returns zero dataLen with non zero data - do not set * residual count in that case. */ -if (e->dataLen && (e->dataLen <scsi_bufflen (cmd))) -scsi_set_resid (cmd,scsi_bufflen (cmd) - e->dataLen); +if (data_len && (data_len <scsi_bufflen (cmd))) +scsi_set_resid (cmd,scsi_bufflen (cmd) - data_len); cmd->result = (DID_OK <<16 );break ;case BTSTAT_DATARUN :case BTSTAT_DATA_UNDERRUN :/* Report residual data in underruns */ -scsi_set_resid (cmd,scsi_bufflen (cmd) - e->dataLen); + data_trans =min_t (u64, data_len,scsi_bufflen (cmd)); +scsi_set_resid (cmd,scsi_bufflen (cmd) - data_trans); cmd->result = (DID_ERROR <<16 );break ;
Signature · 1 line
2.52.0
Matt,
Quoted 3 lines
When calculating the residual bytes, clamp dataLen to the buffer length before the subtraction. This prevents an overflow if the device sends a larger value than expected.
Applied to 7.5/scsi-staging, thanks!
Signature · 1 line
Martin K. Petersen
Quoted 3 lines · Matt Wang
When calculating the residual bytes, clamp dataLen to the buffer length before the subtraction. This prevents an overflow if the device sends a larger value than expected.
Applied to 7.5/scsi-queue, thanks!
[1/1] scsi: vmw_pvscsi: clamp on e->dataLen in pvscsi_complete_request
https://git.kernel.org/mkp/scsi/c/a3d959d2778f
Signature · 1 line
Martin K. Petersen