scsi/scsi_bus: fix races in REPORT LUNS
commit8cfe8013baec2a6f66240ffd767fad2699d85144
authorMaxim Levitsky <mlevitsk@redhat.com>
Tue, 6 Oct 2020 12:39:04 +0000 (6 15:39 +0300)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 12 Oct 2020 15:50:51 +0000 (12 11:50 -0400)
tree2bc9af125683c19bd30ea479dcbb280d650e4bec
parent07a47d4a1879370009baab44f1f387610d88a299
scsi/scsi_bus: fix races in REPORT LUNS

Currently scsi_target_emulate_report_luns iterates over the child device list
twice, and there is no guarantee that this list is the same in both iterations.

The reason for iterating twice is that the first iteration calculates
how much memory to allocate.  However if we use a dynamic array we can
avoid iterating twice, and therefore we avoid this race.

Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1866707
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20200913160259.32145-10-mlevitsk@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20201006123904.610658-14-mlevitsk@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
hw/scsi/scsi-bus.c