scsi: snic: Disable the devcmd2 WQ before freeing its results ring
Subsystems (2)
PATCH 1/1 scsi: snic: Disable the devcmd2 WQ before freeing its results ring
vnic_dev_deinit_devcmd2() frees the devcmd2 results ring before it disables the devcmd2 WQ. The adapter writes the result of each devcmd2 command into that ring. When a command times out in _svnic_dev_cmd2(), its descriptor stays posted on the WQ, and snic_remove() ignores the error from svnic_dev_close(), so the adapter can still complete the command and write its result after the ring has been freed.
Disable the WQ first, so that the adapter has acknowledged stopping the queue before the results ring is freed.
---
Compile-tested only (x86_64, SCSI_SNIC=m, W=1). I have no Cisco VIC adapter, and the late write would come from the adapter, so I could not reproduce it.
drivers/scsi/snic/vnic_dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/snic/vnic_dev.c +1 -1
@@ -421,8 +421,8 @@ static void vnic_dev_deinit_devcmd2(struct vnic_dev *vdev) vdev->devcmd2 =NULL ; vdev->devcmd_rtn =NULL ; -svnic_dev_free_desc_ring (vdev, &dc2c->results_ring);svnic_wq_disable (&dc2c->wq); +svnic_dev_free_desc_ring (vdev, &dc2c->results_ring);svnic_wq_free (&dc2c->wq);kfree (dc2c); }
base-commit: 8dac6df92a2e66e2098bbc69061964cfe7e8375b
Signature · 1 line
2.56.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [Critical] enic: DMA use-after-free in…
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce:
- [Critical] enic: DMA use-after-free in vnic_dev_deinit_devcmd2() [1] --
commit 69fa45723f24d1ae5b1a578c30346f49638a7cfb
Author: Yuho Choi <[email protected]>
scsi: snic: Disable the devcmd2 WQ before freeing its results ring
This commit reorders vnic_dev_deinit_devcmd2() to disable the devcmd2 work queue before freeing the devcmd2 results descriptor ring.
Quoted 5 lines
drivers/scsi/snic/vnic_dev.c +0
-0
drivers/scsi/snic/vnic_dev.c static void vnic_dev_deinit_devcmd2(struct vnic_dev *vdev) · line 428
Quoted 9 lines
drivers/scsi/snic/vnic_dev.c +1
-1@@ -421,8 +421,8 @@ static void vnic_dev_deinit_devcmd2(struct vnic_dev *vdev) vdev->devcmd2 =NULL ; vdev->devcmd_rtn =NULL ; -svnic_dev_free_desc_ring (vdev, &dc2c->results_ring);svnic_wq_disable (&dc2c->wq); +svnic_dev_free_desc_ring (vdev, &dc2c->results_ring);svnic_wq_free (&dc2c->wq);kfree (dc2c); }
[Severity: Critical]
This problem wasn't introduced by this patch, but can the adapter still perform DMA to freed memory [1] when svnic_wq_disable() times out, or along the svnic_dev_init_devcmd2() error path and the matching devcmd2 teardown code in enic and fnic?
svnic_wq_disable() returns -ETIMEDOUT if the hardware does not acknowledge stopping the queue, yet vnic_dev_deinit_devcmd2() ignores its return value and unconditionally frees both dc2c->results_ring and dc2c->wq.ring while the queue remains active.
In the same file, svnic_dev_init_devcmd2() also frees dc2c->results_ring before calling svnic_wq_disable():
drivers/scsi/snic/vnic_dev.c:svnic_dev_init_devcmd2() {
...
err_free_desc_ring:
svnic_dev_free_desc_ring(vdev, &dc2c->results_ring);err_free_wq:
svnic_wq_disable(&dc2c->wq);
svnic_wq_free(&dc2c->wq);
...
}The identical devcmd2 init and deinit paths in drivers/net/ethernet/cisco/enic/vnic_dev.c and drivers/scsi/fnic/vnic_dev.c likewise free results_ring before calling vnic_wq_disable() and ignore the disable return value before freeing the WQ descriptor ring.
[1] https://sashiko.dev/#/bug/linux-20f156a6-d2c2-49bc-b1ee-432c3af0d669
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1