Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10532964ybi; Thu, 25 Jul 2019 01:02:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqxo8W1cAvThwRh9Co6TlTRBHl8wOI/r2PqKEshNa5FfiGUtozozTC06qAterwwjWNolQeWm X-Received: by 2002:a17:902:b497:: with SMTP id y23mr90128602plr.68.1564041751304; Thu, 25 Jul 2019 01:02:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564041751; cv=none; d=google.com; s=arc-20160816; b=A/3ApCB8xVrAQXAHrXugfUPidmHGMqRij8uD3SfL2VWPBKawn57sOurFYc5gEomXLK n77UdN5nv7Sw6w299BQzgDhWGMs+YsKYtnzIldFupeP3rJBVYougYkZRO3qN9r/pNH8v 52ai4KuimfXgYa4HJS6VqT5D8nsj162A4blX8MAUExwir9D+4vSYLtf1/9xyiC08wbUo XMvyDuPKm4UqOj+ydk47TAd/s7hCoPLbeN3EVIFwqbSEvh2IY9NbigXA3yvOVoSdCubv sz1jRc34tOIgo1+oyjxI+DVBbszH3xVF80lze2GB9myk1alXPn0WtKKl8ouQAK4PcWWe V+sA== 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=B1c1ioeGztlHmz7QMXOHx4vctyigOE1lxWrqEDACRUotV8b1sY+//V/mBThtDhxc54 gTclRf810hBneyp7sM/zwf2lMVtMeHaWeu+QRguojxPkfKHeIH06I04PhvSBRnE7JP3i PutqG0Xp/qs25MIUChXJ5z/onJ7ZVyM/GitMQ+zrdYEMl81bwYORAA1N8VBhwRNJPFcb LEvUuK7HGHnnrcEju3mY+Qbii850dXgv08dzPVJMs5hcb9LlWcZPS/yjfoLr9kw12gUh dB0SmWBtlTvqHDP8Rxb/sbt3jBeMdvu9oY00vPiKP7So84nU03fGGq31g1+QOo3JhlTP rOyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lQ04XvIH; 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 a13si14317575pgn.359.2019.07.25.01.02.11; Thu, 25 Jul 2019 01:02:31 -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=lQ04XvIH; 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 S2392513AbfGXUPE (ORCPT + 99 others); Wed, 24 Jul 2019 16:15:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:37218 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404318AbfGXTyU (ORCPT ); Wed, 24 Jul 2019 15:54:20 -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 2976420665; Wed, 24 Jul 2019 19:54:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563998059; bh=7qHMARGZqYN8XVCRyjerYdEwNpm0JOUaZFtCVUzQbSI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lQ04XvIHiIWbjCPFhtrL/6bZ0EDWGY895RAgaeFgH2tXjks7bWVTG6t7YMkHmHHxl SwOJePt7xDCZ3rxs/9rb30EnutpieiLGQAnmj/poC0pyBjhg5wEqiYW+zLzndnG4fy QzLft9YD5yM3RK2mCKn3TVuRELV5wWW5KmNC1N20= 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.1 232/371] scsi: core: Fix race on creating sense cache Date: Wed, 24 Jul 2019 21:19:44 +0200 Message-Id: <20190724191741.947657397@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191724.382593077@linuxfoundation.org> References: <20190724191724.382593077@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; }