Commit f1f609d8 authored by Jay Vosburgh's avatar Jay Vosburgh Committed by Stefan Bader

UBUNTU: SAUCE: (no-up) virtio-scsi: Fix race in target free

BugLink: http://bugs.launchpad.net/bugs/1765241

	A race condition exists in virtio_scsi between the completion of
a request and the freeing of the target structure.  The race is between
(a) virtscsi_complete_cmd that, first, wakes up a task waiting for a
completion, then, second, releases a reference in the target structure
and (b) the woken up task freeing that target structure.

	The race appears to exist in all verisons of virtio_scsi, but
most kernels are not impacted due to a coincidental RCU sync in the
"(b)" path above that will effectively wait for the "(a)" path to
complete.  The Ubuntu Xenial 4.4 kernel since commit be2a2080
lacks any RCU sync in the "(b)" code path, thus opening the race window.

	The fix is to wait for any outstanding requests to release their
references prior to freeing the target structure.
Signed-off-by: default avatarJay Vosburgh <jay.vosburgh@canonical.com>
Acked-by: default avatarStefan Bader <stefan.bader@canonical.com>
Acked-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
Signed-off-by: default avatarStefan Bader <stefan.bader@canonical.com>
parent 01d5daac
......@@ -785,6 +785,10 @@ static int virtscsi_target_alloc(struct scsi_target *starget)
static void virtscsi_target_destroy(struct scsi_target *starget)
{
struct virtio_scsi_target_state *tgt = starget->hostdata;
/* we can race with concurrent virtscsi_complete_cmd */
while (atomic_read(&tgt->reqs))
cpu_relax();
kfree(tgt);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment