linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] virtio_scsi: Add validation for residual bytes from response
@ 2021-06-15 10:52 Xie Yongji
  2021-06-29 20:54 ` Martin K. Petersen
  0 siblings, 1 reply; 2+ messages in thread
From: Xie Yongji @ 2021-06-15 10:52 UTC (permalink / raw)
  To: mst, jasowang, stefanha, jejb, martin.petersen
  Cc: virtualization, linux-scsi, linux-kernel

This ensures that the residual bytes in response (might come
from an untrusted device) will not exceed the data buffer length.

Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
Acked-by: Jason Wang <jasowang@redhat.com>
---
 drivers/scsi/virtio_scsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
index b9c86a7e3b97..2badc3c80d73 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)));
 }
 
 /*
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] virtio_scsi: Add validation for residual bytes from response
  2021-06-15 10:52 [PATCH v2] virtio_scsi: Add validation for residual bytes from response Xie Yongji
@ 2021-06-29 20:54 ` Martin K. Petersen
  0 siblings, 0 replies; 2+ messages in thread
From: Martin K. Petersen @ 2021-06-29 20:54 UTC (permalink / raw)
  To: Xie Yongji
  Cc: mst, jasowang, stefanha, jejb, martin.petersen, virtualization,
	linux-scsi, linux-kernel


Xie,

> This ensures that the residual bytes in response (might come
> from an untrusted device) will not exceed the data buffer length.

Applied to 5.14/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-06-29 20:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-15 10:52 [PATCH v2] virtio_scsi: Add validation for residual bytes from response Xie Yongji
2021-06-29 20:54 ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).