* [PATCH V2] scsi: fix race on creating sense cache
@ 2019-07-12 2:08 Ming Lei
2019-07-17 2:43 ` Martin K. Petersen
0 siblings, 1 reply; 2+ messages in thread
From: Ming Lei @ 2019-07-12 2:08 UTC (permalink / raw)
To: linux-scsi, Martin K . Petersen
Cc: James Bottomley, Ming Lei, Stable, Christoph Hellwig,
Hannes Reinecke, Ewan D . Milne
When scsi_init_sense_cache(host) is called concurrently from different
hosts, each code path may see that the cache isn't created, then try
to create a new one, then the created sense cache may be overrided and
leaked.
Fixes the issue by moving 'mutex_lock(&scsi_sense_cache_mutex)' before
scsi_select_sense_cache().
Fixes: 0a6ac4ee7c21 ("scsi: respect unchecked_isa_dma for blk-mq")
Cc: Stable <stable@vger.kernel.org>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Ewan D. Milne <emilne@redhat.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
drivers/scsi/scsi_lib.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index e07a376a8c38..7493680ec104 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -72,11 +72,11 @@ int scsi_init_sense_cache(struct Scsi_Host *shost)
struct kmem_cache *cache;
int ret = 0;
+ mutex_lock(&scsi_sense_cache_mutex);
cache = scsi_select_sense_cache(shost->unchecked_isa_dma);
if (cache)
- return 0;
+ goto exit;
- mutex_lock(&scsi_sense_cache_mutex);
if (shost->unchecked_isa_dma) {
scsi_sense_isadma_cache =
kmem_cache_create("scsi_sense_cache(DMA)",
@@ -92,7 +92,7 @@ int scsi_init_sense_cache(struct Scsi_Host *shost)
if (!scsi_sense_cache)
ret = -ENOMEM;
}
-
+ exit:
mutex_unlock(&scsi_sense_cache_mutex);
return ret;
}
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH V2] scsi: fix race on creating sense cache
2019-07-12 2:08 [PATCH V2] scsi: fix race on creating sense cache Ming Lei
@ 2019-07-17 2:43 ` Martin K. Petersen
0 siblings, 0 replies; 2+ messages in thread
From: Martin K. Petersen @ 2019-07-17 2:43 UTC (permalink / raw)
To: Ming Lei
Cc: linux-scsi, Martin K . Petersen, James Bottomley, Stable,
Christoph Hellwig, Hannes Reinecke, Ewan D . Milne
Ming,
> When scsi_init_sense_cache(host) is called concurrently from different
> hosts, each code path may see that the cache isn't created, then try
> to create a new one, then the created sense cache may be overrided and
> leaked.
>
> Fixes the issue by moving 'mutex_lock(&scsi_sense_cache_mutex)' before
> scsi_select_sense_cache().
Applied to 5.3/scsi-fixes, thanks!
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-07-17 2:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-12 2:08 [PATCH V2] scsi: fix race on creating sense cache Ming Lei
2019-07-17 2:43 ` Martin K. Petersen
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).