* [PATCH] usb: storage: Fix a possible data race in uas_queuecommand_lck
@ 2018-05-08 7:47 Jia-Ju Bai
2018-05-08 8:27 ` [usb-storage] " Oliver Neukum
0 siblings, 1 reply; 3+ messages in thread
From: Jia-Ju Bai @ 2018-05-08 7:47 UTC (permalink / raw)
To: oneukum, stern, gregkh
Cc: linux-usb, linux-scsi, usb-storage, linux-kernel, Jia-Ju Bai
The write operations to "cmnd->result" and "cmnd->scsi_done"
are protected by the lock on line 642-643, but the write operations
to these data on line 634-635 are not protected by the lock.
Thus, there may exist a data race for "cmnd->result"
and "cmnd->scsi_done".
To fix this data race, the write operations on line 634-635
should be also protected by the lock.
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
drivers/usb/storage/uas.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c
index 6034c39b67d1..dde7a43ad491 100644
--- a/drivers/usb/storage/uas.c
+++ b/drivers/usb/storage/uas.c
@@ -627,17 +627,18 @@ static int uas_queuecommand_lck(struct scsi_cmnd *cmnd,
if (cmnd->device->host->host_self_blocked)
return SCSI_MLQUEUE_DEVICE_BUSY;
+ spin_lock_irqsave(&devinfo->lock, flags);
+
if ((devinfo->flags & US_FL_NO_ATA_1X) &&
(cmnd->cmnd[0] == ATA_12 || cmnd->cmnd[0] == ATA_16)) {
memcpy(cmnd->sense_buffer, usb_stor_sense_invalidCDB,
sizeof(usb_stor_sense_invalidCDB));
cmnd->result = SAM_STAT_CHECK_CONDITION;
cmnd->scsi_done(cmnd);
+ spin_unlock_irqrestore(&devinfo->lock, flags);
return 0;
}
- spin_lock_irqsave(&devinfo->lock, flags);
-
if (devinfo->resetting) {
cmnd->result = DID_ERROR << 16;
cmnd->scsi_done(cmnd);
--
2.17.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [usb-storage] [PATCH] usb: storage: Fix a possible data race in uas_queuecommand_lck
2018-05-08 7:47 [PATCH] usb: storage: Fix a possible data race in uas_queuecommand_lck Jia-Ju Bai
@ 2018-05-08 8:27 ` Oliver Neukum
2018-05-08 8:39 ` Jia-Ju Bai
0 siblings, 1 reply; 3+ messages in thread
From: Oliver Neukum @ 2018-05-08 8:27 UTC (permalink / raw)
To: Jia-Ju Bai, stern, gregkh
Cc: linux-usb, linux-scsi, usb-storage, linux-kernel
Am Dienstag, den 08.05.2018, 15:47 +0800 schrieb Jia-Ju Bai:
> The write operations to "cmnd->result" and "cmnd->scsi_done"
> are protected by the lock on line 642-643, but the write operations
> to these data on line 634-635 are not protected by the lock.
> Thus, there may exist a data race for "cmnd->result"
> and "cmnd->scsi_done".
No,
the write operations need no lock. The low level driver at this point
owns the command. We cannot race with abort() for a command within
queuecommand(). We take the lock where we take it to protect
dev->resetting.
I don't see why the scope of the lock would need to be enlarged.
Regards
Oliver
> To fix this data race, the write operations on line 634-635
> should be also protected by the lock.
>
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
Nacked-by: Oliver Neukum <oneukum@suse.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [usb-storage] [PATCH] usb: storage: Fix a possible data race in uas_queuecommand_lck
2018-05-08 8:27 ` [usb-storage] " Oliver Neukum
@ 2018-05-08 8:39 ` Jia-Ju Bai
0 siblings, 0 replies; 3+ messages in thread
From: Jia-Ju Bai @ 2018-05-08 8:39 UTC (permalink / raw)
To: Oliver Neukum, stern, gregkh
Cc: linux-usb, linux-scsi, usb-storage, linux-kernel
On 2018/5/8 16:27, Oliver Neukum wrote:
> Am Dienstag, den 08.05.2018, 15:47 +0800 schrieb Jia-Ju Bai:
>> The write operations to "cmnd->result" and "cmnd->scsi_done"
>> are protected by the lock on line 642-643, but the write operations
>> to these data on line 634-635 are not protected by the lock.
>> Thus, there may exist a data race for "cmnd->result"
>> and "cmnd->scsi_done".
> No,
>
> the write operations need no lock. The low level driver at this point
> owns the command. We cannot race with abort() for a command within
> queuecommand(). We take the lock where we take it to protect
> dev->resetting.
>
> I don't see why the scope of the lock would need to be enlarged.
Okay, thanks for your reply and explanation.
Best wishes,
Jia-Ju Bai
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-05-08 8:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-08 7:47 [PATCH] usb: storage: Fix a possible data race in uas_queuecommand_lck Jia-Ju Bai
2018-05-08 8:27 ` [usb-storage] " Oliver Neukum
2018-05-08 8:39 ` Jia-Ju Bai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).