Thread (3 messages) 3 messages, 3 authors, 2021-03-16
STALE1947d LANDED

[PATCH] scsi: Fix a use after free in st_open

From: Lv Yunlong <hidden>
Date: 2021-03-11 06:47:49
Also in: lkml
Subsystem: scsi subsystem, scsi tape driver, the rest · Maintainers: "James E.J. Bottomley", "Martin K. Petersen", Kai Mäkisara, Linus Torvalds

In st_open, if STp->in_use is true, STp will be freed by
scsi_tape_put(). However, STp is still used by DEBC_printk()
after. It is better to DEBC_printk() before scsi_tape_put().

Signed-off-by: Lv Yunlong <redacted>
---
 drivers/scsi/st.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 841ad2fc369a..9ca536aae784 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -1269,8 +1269,8 @@ static int st_open(struct inode *inode, struct file *filp)
 	spin_lock(&st_use_lock);
 	if (STp->in_use) {
 		spin_unlock(&st_use_lock);
-		scsi_tape_put(STp);
 		DEBC_printk(STp, "Device already in use.\n");
+		scsi_tape_put(STp);
 		return (-EBUSY);
 	}
 
-- 
2.25.1

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help