]> www.infradead.org Git - users/jedix/linux-maple.git/commit
scsi: ufs: core: Fix a race condition related to device commands
authorBart Van Assche <bvanassche@acm.org>
Fri, 14 Mar 2025 22:51:50 +0000 (15:51 -0700)
committerMartin K. Petersen <martin.petersen@oracle.com>
Fri, 21 Mar 2025 00:48:37 +0000 (20:48 -0400)
commit20b97acc4cafa2be8ac91a777de135110e58a90b
tree5572805739e661444d8f27c87dd9b7b6ba46d1d0
parentdaff37f00c7506ca322ccfce95d342022f06ec58
scsi: ufs: core: Fix a race condition related to device commands

There is a TOCTOU race in ufshcd_compl_one_cqe(): hba->dev_cmd.complete may
be cleared from another thread after it has been checked and before it is
used. Fix this race by moving the device command completion from the stack
of the device command submitter into struct ufs_hba. This patch fixes the
following kernel crash:

Unable to handle kernel NULL pointer dereference at virtual address 0000000000000008
Call trace:
 _raw_spin_lock_irqsave+0x34/0x80
 complete+0x24/0xb8
 ufshcd_compl_one_cqe+0x13c/0x4f0
 ufshcd_mcq_poll_cqe_lock+0xb4/0x108
 ufshcd_intr+0x2f4/0x444
 __handle_irq_event_percpu+0xbc/0x250
 handle_irq_event+0x48/0xb0

Fixes: 5a0b0cb9bee7 ("[SCSI] ufs: Add support for sending NOP OUT UPIU")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Link: https://lore.kernel.org/r/20250314225206.1487838-1-bvanassche@acm.org
Reviewed-by: Peter Wang <peter.wang@mediatek.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/ufs/core/ufshcd.c
include/ufs/ufshcd.h