Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3784821ybi; Mon, 29 Jul 2019 12:34:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqwYpZImiF7jFYMrPN90HuoTPM1ftz/m+WpCQZ7H2N61FTZ2taXNb8ty0XeSGv88p15JPpV9 X-Received: by 2002:a17:902:7d8b:: with SMTP id a11mr58047216plm.306.1564428849680; Mon, 29 Jul 2019 12:34:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564428849; cv=none; d=google.com; s=arc-20160816; b=Lxeb2lHjd5Fa3iQgg2RNH/Ph5ssVDnoaMZBpJYDG8FfyRqP/kyzShF3efQhFFqqahv sFnp29/9gOiQZZkIUW50WonZmLToXOkA+1EVGPjdIE6y8U3Y2V9+3fvPey93FF3KGNdV MsDD9nbRT6YsGQi4am/slIb8fb0gH+xuNtWGt469im3YkxIIMGX8tknq//T53+B4O8nO J+aPpSiYWar8XvhSmoFuC8QkFRNau5jZN2Jq0peyPDhx62O+8bPSllNs4Wy5Omd81WA4 mWveqHziLwm9dA3Ah89bARp4lV0eIEnpzha3NNXFAdYAsEkZyQjtAroVqVRFj1viarnm Jslw== 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=yYE4rhoMk6wNp2nWJrT2EyrGA/OoP8IoOGE4wvteBTs=; b=ZMzrOqu7MKOIZwJEmCa7M/qBaoy1v3Kt7gmE6ujPR1CAAe7Z4mOHx4ky3hyLfAMBCp tOLl1AfI7ZGI3w50Fd7NOqpP4xEZ/53FH6fVizFzICgwjwDGaPuyV/bVSSGEm+rEDaqP Yl/mqbjn265AuJPPlbnRort2i6bFB4zbtDqJYleaMOaW0ZJiiDvcP9uiP41b9kTmhRLg UZMjuHDrNBrB/9OW3SvRTROh1D+78f4VXRHJRHurQAoVip/mQ3Ja6mfdCCd+HYnfU6yn fxX4ByPwSlQRssbU7U/fPWm75vewM8gCrFr2Oc3jXa1NsLzES1iOqz/TqzGINxqBD+Sv n1Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iWDrhbig; 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 o2si29265224pfp.113.2019.07.29.12.33.54; Mon, 29 Jul 2019 12:34:09 -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=iWDrhbig; 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 S1729161AbfG2T3W (ORCPT + 99 others); Mon, 29 Jul 2019 15:29:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:42006 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727721AbfG2T3T (ORCPT ); Mon, 29 Jul 2019 15:29:19 -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 DAE30217D7; Mon, 29 Jul 2019 19:29:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564428558; bh=GFBXUdjCkqdWSyja6Renha4vSWYo1fMMNG5jLNDPuTA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iWDrhbig7bKmbb0yPMBKFlnYBVBEvvl76TkkSKmZqd+esdf96ikmq9/hAJFSMbIiy W1QzyNLLd/JFWyhn4ngKHz7EO0qnUV2u3uZbJzIBccqkCjKE4VU4eEct2803n5c1fT HLu36S2uajVhiSKVu0AovfP7TfMMoQPUOedoVnQ0= 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 4.14 115/293] scsi: core: Fix race on creating sense cache Date: Mon, 29 Jul 2019 21:20:06 +0200 Message-Id: <20190729190833.421885040@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190820.321094988@linuxfoundation.org> References: <20190729190820.321094988@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 @@ -71,11 +71,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)", @@ -90,7 +90,7 @@ int scsi_init_sense_cache(struct Scsi_Ho if (!scsi_sense_cache) ret = -ENOMEM; } - + exit: mutex_unlock(&scsi_sense_cache_mutex); return ret; }