From 5f638e5ac61ef1b9b588efdf688acc0a4cecdca2 Mon Sep 17 00:00:00 2001 From: Xie Yongji Date: Tue, 15 Jun 2021 18:52:18 +0800 Subject: scsi: virtio_scsi: Add validation for residual bytes from response This ensures that the residual bytes in response (might come from an untrusted device) will not exceed the data buffer length. Link: https://lore.kernel.org/r/20210615105218.214-1-xieyongji@bytedance.com Acked-by: Jason Wang Signed-off-by: Xie Yongji Signed-off-by: Martin K. Petersen --- drivers/scsi/virtio_scsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/scsi') diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c index ad78bf631900..b0deaf4af5a3 100644 --- a/drivers/scsi/virtio_scsi.c +++ b/drivers/scsi/virtio_scsi.c @@ -97,7 +97,7 @@ static inline struct Scsi_Host *virtio_scsi_host(struct virtio_device *vdev) static void virtscsi_compute_resid(struct scsi_cmnd *sc, u32 resid) { if (resid) - scsi_set_resid(sc, resid); + scsi_set_resid(sc, min(resid, scsi_bufflen(sc))); } /* -- cgit v1.2.3