scsi: pvscsi: limit loop to fetch SG list
commit49adc5d3f8c6bb75e55ebfeab109c5c37dea65e8
authorPrasad J Pandit <pjp@fedoraproject.org>
Mon, 5 Sep 2016 20:50:43 +0000 (6 02:20 +0530)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 13 Sep 2016 17:08:47 +0000 (13 19:08 +0200)
treed9f34b84688b61354f92fa5239598456ac5a98a8
parenta2feb3483e11a389bc93a5bbd40815d6cfdfb07f
scsi: pvscsi: limit loop to fetch SG list

In PVSCSI paravirtual SCSI bus, pvscsi_convert_sglist can take a very
long time or go into an infinite loop due to two different bugs:

1) the request descriptor data length is defined to be 64 bit. While
building SG list from a request descriptor, it gets truncated to 32bit
in routine 'pvscsi_convert_sglist'. This could lead to an infinite loop
situation large 'dataLen' values when data_length is cast to uint32_t and
chunk_size becomes always zero.  Fix this by removing the incorrect cast.

2) pvscsi_get_next_sg_elem can be called arbitrarily many times if the
element has a zero length.  Get out of the loop early when this happens,
by introducing an upper limit on the number of SG list elements.

Reported-by: Li Qiang <liqiang6-s@360.cn>
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
Message-Id: <1473108643-12983-1-git-send-email-ppandit@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
hw/scsi/vmw_pvscsi.c