Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10225176ybi; Wed, 24 Jul 2019 18:44:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqzOMXOtW25QpKyLfsR6UEr1dKOkVA93LbFh0P9nOYB5bo7foDaFLxtMF2KkVpLb66lFgKFV X-Received: by 2002:aa7:9ad2:: with SMTP id x18mr14734800pfp.192.1564019084707; Wed, 24 Jul 2019 18:44:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564019084; cv=none; d=google.com; s=arc-20160816; b=YA1QVptjt1c6d5dgr53H5pGf6RhvzZ3ICufrBnbRRhZKZCm+nZBEywXr+Z/2i5gwPi whv7n8c+ORnIWrmyYBZFWIE0Au/EFCM5FkC4e24HsAS6ShlqNl2SGuBwupvdMZLGQ/Ba E9dnJ+xoYG23QdVeGe/kBavvOovjktw0dAmEWQx9TD6COc9hX61WWoTJsWiJchkrd+pK B9ValVV2JRQTOMovxlKfn/074inXpycAgXZXMSL40kVlb8z3pEcLNeC4wb8fBF3t5CbF /GkxfEItJtIK3sLDxP8jkwnlAudxlMBUtR77B0Quw6N9mtJw08zRS5tObyxptuNTSyWh 7ntw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=P17uCJbZN1pPMPzgIo2ZDyWeu3WrUJ7UiwGCUFMJioU=; b=GSEc8Uc7scMvHWzmlOCAAA8Uh2eeH2uLS66iH/AEBkMazvqPIU8n3F48dACY1CUqsa jBUs1/nifdB1YCEEHuo9XLK3aY30XbagLl88t0sxbSNB+ApCnhS2sfCfnl+hbpDjIAmc Me33SehelivwgEdoixOBuaAGSJ84lk+S+R7iaSAorxkUAfor7uP+8xYoQ89257NgQici GVTYzWFLm3Q9pbOMTxNMevPs5aGubc9D/FxmrZHIEyG5MpI6vAEFG2k63G2xN0jjSRKw q1z3Y3yltfCLQ4tOUu3BDBqs5L+54vGHWQwM9ssQKqvGqWq7tfhYm0a619w3ij+fehkk mSHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AcT+KDkj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gb4si15370932plb.429.2019.07.24.18.44.30; Wed, 24 Jul 2019 18:44:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AcT+KDkj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389383AbfGXThB (ORCPT + 99 others); Wed, 24 Jul 2019 15:37:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:36776 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388478AbfGXTgy (ORCPT ); Wed, 24 Jul 2019 15:36:54 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A9511214AF; Wed, 24 Jul 2019 19:36:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563997014; bh=eBZ62cRWa9VRaFzG4EcxN3DST27SeKFUtLhOrnP5MaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AcT+KDkjLmu5dwmyYxnT/L9qusgdkzC2JKmVWBNZ1z3VzzJyp3xgwg4R1/BiT1c6T 1juUNwOMC+eIJJkS45VXFC8y2ppQeNK878UhYPYu3Zej2elA2rZhzre/P7yFpOY5Do F//JSH4FaMtKGa8y2gD2ypI0F4jLC8jIkZ5vim4Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Hellwig , Hannes Reinecke , "Ewan D. Milne" , Ming Lei , "Martin K. Petersen" Subject: [PATCH 5.2 256/413] scsi: core: Fix race on creating sense cache Date: Wed, 24 Jul 2019 21:19:07 +0200 Message-Id: <20190724191754.319591458@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ming Lei commit f9b0530fa02e0c73f31a49ef743e8f44eb8e32cc upstream. When scsi_init_sense_cache(host) is called concurrently from different hosts, each code path may find that no cache has been created and allocate a new one. The lack of locking can lead to potentially overriding a cache allocated by a different host. Fix 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 Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: Ewan D. Milne Signed-off-by: Ming Lei Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/scsi_lib.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -72,11 +72,11 @@ int scsi_init_sense_cache(struct Scsi_Ho 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_Ho if (!scsi_sense_cache) ret = -ENOMEM; } - + exit: mutex_unlock(&scsi_sense_cache_mutex); return ret; }