From patchwork Thu Mar 11 06:19:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lv Yunlong X-Patchwork-Id: 12130345 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82D84C433DB for ; Thu, 11 Mar 2021 06:21:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3F4AF64F34 for ; Thu, 11 Mar 2021 06:21:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230050AbhCKGUa (ORCPT ); Thu, 11 Mar 2021 01:20:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230004AbhCKGT6 (ORCPT ); Thu, 11 Mar 2021 01:19:58 -0500 Received: from ustc.edu.cn (email6.ustc.edu.cn [IPv6:2001:da8:d800::8]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8A3B9C061574; Wed, 10 Mar 2021 22:19:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mail.ustc.edu.cn; s=dkim; h=Received:From:To:Cc:Subject:Date: Message-Id:MIME-Version:Content-Type:Content-Transfer-Encoding; bh=b6u1iBvxf8QlPK+MfcxfGSBemsTGQ4ipDSR3NJ6YiYI=; b=h/XNx9vi6QYnK kvxU9vwZV3Ir6KL81S5S15vr2FqRlC3ES+lDowW/nrKTma3DujekeEuvYl8mVaRU VL1INCLlY5WYnKEqoP+U2ImLwzXz8bFAhAPJULbA745q0yHEjZgc/ppu6qC/WZFS kjtEIdLdwgq/OMODGaAhX6iy/ImxfA= Received: from ubuntu.localdomain (unknown [114.214.226.60]) by newmailweb.ustc.edu.cn (Coremail) with SMTP id LkAmygB3KWKGtklgZOgJAA--.1923S4; Thu, 11 Mar 2021 14:19:50 +0800 (CST) From: Lv Yunlong To: sathya.prakash@broadcom.com, sreekanth.reddy@broadcom.com, suganath-prabu.subramani@broadcom.com, jejb@linux.ibm.com, martin.petersen@oracle.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Lv Yunlong Subject: [PATCH] scsi: Fix a use after free in pcie_device_make_active Date: Wed, 10 Mar 2021 22:19:48 -0800 Message-Id: <20210311061948.9348-1-lyl2019@mail.ustc.edu.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CM-TRANSID: LkAmygB3KWKGtklgZOgJAA--.1923S4 X-Coremail-Antispam: 1UD129KBjvJXoW7Jw17WF1DKrW5GF17KrWkCrg_yoW8JrWxpr WDJa4YyryDWr4Igw4DWF45Wry8G3Z0y39Yga10ga4q9r1xJFyrt348trZxJw17J39ayFyU Jry7tr9Ygay8Jr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkE14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26F1j6w1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4j 6r4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAac4AC62xK8xCEY4vEwIxC4wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC 0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr 1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IE rcIFxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14 v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkG c2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6rWUJVWrZr1UMIIF0xvEx4A2jsIE14v26r1j 6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUQZ2 3UUUUU= X-CM-SenderInfo: ho1ojiyrz6zt1loo32lwfovvfxof0/ Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org In pcie_device_make_active, it will drop the last reference of pcie_device and release it by pcie_device_put(). It is obviously that pcie_device_get() should be called before release the pcie_device. Otherwise, it will cause a use after free. Fixes: d88e1eaba6eee ("scsi: mpt3sas: Add nvme device support in slave alloc, target alloc a…") Signed-off-by: Lv Yunlong --- drivers/scsi/mpt3sas/mpt3sas_scsih.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c index ffca03064797..d39b5a1f496b 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c @@ -11433,11 +11433,11 @@ static void pcie_device_make_active(struct MPT3SAS_ADAPTER *ioc, spin_lock_irqsave(&ioc->pcie_device_lock, flags); + pcie_device_get(pcie_device); if (!list_empty(&pcie_device->list)) { list_del_init(&pcie_device->list); pcie_device_put(pcie_device); } - pcie_device_get(pcie_device); list_add_tail(&pcie_device->list, &ioc->pcie_device_list); spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);