Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10425354ybi; Wed, 24 Jul 2019 23:00:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqw5QoUktbKmX1AHRSJU1yHcEqboC/MWZKw8skDwz45Yzr4X6tZLBx8O0cymKvo5758ZclIm X-Received: by 2002:a17:902:7687:: with SMTP id m7mr35480665pll.310.1564034427341; Wed, 24 Jul 2019 23:00:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564034427; cv=none; d=google.com; s=arc-20160816; b=C2x4+V4Cr9Q4ZE6WjtD56a03JoukwlmhviMR+OUUdYNZITTCLgiQzk4YDMOLeBswoR 3LK0Oqhv7ou6FPvUJsc4wfcv7YPNg4ZmHPZB5veSxk7tGAub/G+6fIyihXMXJUWDn6F/ 6ITSWyfEt46l1d5SLyurgkjm8JNQ+cnTUD/omlU07asuh5nurEr7ZnoSYuquekbrlc0P 41GFC2P7jIroEw+1qC2Niwwk/LKYk/8GJGPxQbgNr0ahiIAGBaiqpxsITzEoYSRmKi+W gB+mSTrWg4C5SXR0N9geM3mR93aUQSxLNrNsx/c6ai9xvu0g6hbhIgd3TC//E66fNS9u tAaQ== 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=CV4PLrv6hcr0z2n54L1j+baOg64tJeKPh9MTp6Mf1pg=; b=xg2YZ4JH64IHG5YYBakGqorfzAWCtwQdKIc/HITgqpRI8DaxWnhaAYQkUrU3JTVDha X8b7Pu/sPFTcV1KY3U1/xtw5izMdxtvrNleBd3n6pFcFDwtQr3Amo4XhuiJPJGN3YBgA zR4ghhpCI0KsYlTEiC00VWFhxG/GHdCC0LyKGqvwMaKAbsmkkfLgAh3ApYic6vHTSPgx VvcezCF90XWdg5sQUo0QQ6SrpqGnkLyvzGyAr94WFj+EqAMTyh8tHeBzyXGYpNWVLTa0 8h3ujrn8vA7dYBheafxZ6faWDxwA6nOSAmb5U1pCa8ZeDeZWUiisLVm1QSUyeGZz4zn5 qmtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=avWUmPqn; 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 g13si18107880pgk.369.2019.07.24.23.00.13; Wed, 24 Jul 2019 23:00:27 -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=avWUmPqn; 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 S2390978AbfGYFnA (ORCPT + 99 others); Thu, 25 Jul 2019 01:43:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:57860 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390967AbfGYFmx (ORCPT ); Thu, 25 Jul 2019 01:42:53 -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 EE2B721880; Thu, 25 Jul 2019 05:42:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564033372; bh=7qHMARGZqYN8XVCRyjerYdEwNpm0JOUaZFtCVUzQbSI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=avWUmPqnNlJdR+Mo99DcdRo23WgUiA48JlHCj32LaCmjJRbPQwp9hgSSZh5Xaw7dy OLyxfkw6wWtBepaWqa7VgGrzGUdpNFhXmHF2thrKyJ1nAK8Ow6ex/4RZK+DJf13K3O yK44zOY83MleuA/ud7d5S3Oje0yAc5M0cJeemoqE= 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.19 168/271] scsi: core: Fix race on creating sense cache Date: Wed, 24 Jul 2019 21:20:37 +0200 Message-Id: <20190724191709.569951829@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191655.268628197@linuxfoundation.org> References: <20190724191655.268628197@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)", @@ -91,7 +91,7 @@ int scsi_init_sense_cache(struct Scsi_Ho if (!scsi_sense_cache) ret = -ENOMEM; } - + exit: mutex_unlock(&scsi_sense_cache_mutex); return ret; }