Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp380209pxm; Wed, 2 Mar 2022 17:52:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJz1inpLoWmsrT3sk7oLqiPR8fwU9GzTriLr+Xf7/Qqx56t89u6GwK39TL4c3TUbIDU0Fsg9 X-Received: by 2002:a65:6d8b:0:b0:376:bfb9:1f3b with SMTP id bc11-20020a656d8b000000b00376bfb91f3bmr25218625pgb.427.1646272329178; Wed, 02 Mar 2022 17:52:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646272329; cv=none; d=google.com; s=arc-20160816; b=NLPhYmIMAmJ03s4Q3T7kkaM0Z2zkk8VfiKfEc9iQNbDqrEC/LXXbl/mSjdSGNrUpGB 15/nRkR//eaSMr6x//CLxEpHgdJQNhURYOU2vQSsA5OT0uEscLq2zgkbrZKmsSYB8jFg CiPUGdmaICqkyZ9i6jrPcRw/GX6LDdu0cgH1bTUjPtwfs20PiJvVdFbX9LdpcTX2oZpd PjIVD0gQIB9rCQhpjjjPnQbQUtqelA+nVIvYRjRwHQfAZ3zD1xNhyWhtsiyR+S75t7qj 5YLU+sc9mJFHdQFVAKC/oIf8h2XpcAzS1KBU89EvKgQlmm7UYvKtuQqQrAviC+51Eb9S AKEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=zQiqJMMK3nLRrtLWwk0/n0GVF6Y3EScFNSuSayheZUw=; b=Mne7bbge4f/SE68APkFxUGvZntTV9m3Hxq+Plgqc0t8xGLYAZATzex35zdYbGqFol5 caCnnXy+wxksbuWsUONqTvExTMBXArpx8YBim6Rue7R3vue918x95HP2QN+8FcGrxmF/ 0jX0kWI1eGuY/1S4QA8PzmSg/pVfWFk0l9d6vDmMsTWbo0MIGFEFvrvZnVZOh27zAwjW Ltk93giWszakaPJzfGgZH201ojgnIDjVB6iHWn7Cx6J/l9KJ0X3l/gyV2gXjbd2cBugw P7/2PdVENULKH7j3cenkKbfcevhIBJ910F7/lKIhTnzgivTaSX5rpwP6WEzfZRa0m2ev K+Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b="JZ/RQWOo"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id u12-20020a17090341cc00b001518307b2edsi834964ple.252.2022.03.02.17.52.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 17:52:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b="JZ/RQWOo"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3B74DF94D9; Wed, 2 Mar 2022 17:51:58 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231527AbiCCBwi (ORCPT + 99 others); Wed, 2 Mar 2022 20:52:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231549AbiCCBwY (ORCPT ); Wed, 2 Mar 2022 20:52:24 -0500 Received: from mail-m972.mail.163.com (mail-m972.mail.163.com [123.126.97.2]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B2D31DF0F for ; Wed, 2 Mar 2022 17:51:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=zQiqJ MMK3nLRrtLWwk0/n0GVF6Y3EScFNSuSayheZUw=; b=JZ/RQWOo4LkyI9KS8H0Bz yVctZZxQEKmaazdKVi9m8U2bYd8R0h5/sTpwqAVKb4+Akj8581HPCBiWx+RURmxL yJtrQT8sWLN3mCxF4e+V1U10ci16fiBfimSpVZSn9R2b35TBeA3/9ci43s2GHIPN /3uA0G+/ojrMLmLVOl3UVc= Received: from localhost.localdomain (unknown [218.106.182.227]) by smtp2 (Coremail) with SMTP id GtxpCgDn708VHyBiSEeUAA--.9337S4; Thu, 03 Mar 2022 09:51:26 +0800 (CST) From: Jianglei Nie To: hare@suse.de, jejb@linux.ibm.com, martin.petersen@oracle.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Jianglei Nie Subject: [PATCH] scsi: libfc: Fix use after free in fc_exch_abts_resp() Date: Thu, 3 Mar 2022 09:51:15 +0800 Message-Id: <20220303015115.459778-1-niejianglei2021@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: GtxpCgDn708VHyBiSEeUAA--.9337S4 X-Coremail-Antispam: 1Uf129KBjvdXoWrKrWkJF4DWrW5urWrZr1rtFb_yoWDJrc_ua 9rGr17Gr1UtrWxWw18GF4fZrWa934DXFnakrn2qF1fuay5urWkZF1UZr95ury5Ww4UKFZx Gr4DWryrAF1avjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xREzuWtUUUUU== X-Originating-IP: [218.106.182.227] X-CM-SenderInfo: xqlhyxxdqjzvrlsqjii6rwjhhfrp/1tbiQx64jFc7XpxpwwAAst X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org fc_exch_release(ep) will decrease the ep's reference count. When the reference count reaches zero, it is freed. But ep is still used in the following code, which will lead to a use after free. We should return the function after the call of fc_exch_release() to avoid use after free. Signed-off-by: Jianglei Nie --- drivers/scsi/libfc/fc_exch.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c index 841000445b9a..aa223db4cf53 100644 --- a/drivers/scsi/libfc/fc_exch.c +++ b/drivers/scsi/libfc/fc_exch.c @@ -1701,6 +1701,7 @@ static void fc_exch_abts_resp(struct fc_exch *ep, struct fc_frame *fp) if (cancel_delayed_work_sync(&ep->timeout_work)) { FC_EXCH_DBG(ep, "Exchange timer canceled due to ABTS response\n"); fc_exch_release(ep); /* release from pending timer hold */ + return; } spin_lock_bh(&ep->ex_lock); -- 2.25.1