Skip to contentSkip to conversation

scsi: sg: Do not sleep in atomic context

PATCH New Bart Van Assche 1 participant 1 message Nov 13, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: sg: Do not sleep in atomic context

sg_finish_rem_req() calls blk_rq_unmap_user(). The latter function may sleep. Hence, call sg_finish_rem_req() with interrupts enabled instead of disabled.

Reported-by [email protected]
Cc Hannes Reinecke <[email protected]>
Fixes 97d27b0dd015 ("scsi: sg: close race condition in sg_remove_sfp_usercontext()")
---
 drivers/scsi/sg.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/scsi/sg.c +9 -1
index 4c62c597c7be..b3af9b78fa12 100644
@@ -2208,9 +2208,17 @@ sg_remove_sfp_usercontext(struct work_struct *work)
 	write_lock_irqsave(&sfp->rq_list_lock, iflags);
 	while (!list_empty(&sfp->rq_list)) {
 		srp = list_first_entry(&sfp->rq_list, Sg_request, entry);
-		sg_finish_rem_req(srp);
 		list_del(&srp->entry);
+		write_unlock_irqrestore(&sfp->rq_list_lock, iflags);
+
+		sg_finish_rem_req(srp);
+		/*
+		 * sg_rq_end_io() uses srp->parentfp. Hence, only clear
+		 * srp->parentfp after blk_mq_free_request() has been called.
+		 */
 		srp->parentfp = NULL;
+
+		write_lock_irqsave(&sfp->rq_list_lock, iflags);
 	}
 	write_unlock_irqrestore(&sfp->rq_list_lock, iflags);