Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp330429rdb; Thu, 16 Nov 2023 23:07:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IE8fghcPvwiTbJdRtVYOA2kibOn/f5qvS0AfPyI72rCs6SZiTrul3ygKEI2euk+5C1RCw0M X-Received: by 2002:a17:902:b618:b0:1cc:449b:689e with SMTP id b24-20020a170902b61800b001cc449b689emr10619274pls.20.1700204826609; Thu, 16 Nov 2023 23:07:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700204826; cv=none; d=google.com; s=arc-20160816; b=qX80hR4zh6/C/7LBrHtZesTRb7Cn3XbSL2n/cEInYOtvX2Q64AexMujYAQ7z63um5S LuXFVJZx6ITcmw34ERjkazBRPlWCdft38A/yNUi3boEafvXuz9NyGAXZCZpn5cuBqeEf jOdWPlP3viwEsvFkLhNNzBLzn21BJKkAC64hBkD8xFEOTHe7FIl6LFTYRfc8SuijCwu3 /dIUZ2k/kwFx9hsS9pXotina5yLnVQEHnyVuKlBosRFRWxLV3G2o3iuCVnO9eG8CmZpJ LRuXlU24E0apdWGx+Gzq9tvnCMqlg2SwNKpTMzpugjsAEq7fh48mb+sU2E2JcUvn+pOr GyhA== 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=w+k1naxiBRigjb9CCtVvFHueFOdp+dkB3oPWurngV94=; fh=RMqoAO95oxMs7e+chqG2l09CybDGeQeR+KoVuGpROMM=; b=mTImkyGOxxtrx34ifNP2lk0qM+qApLPovinTfakmhFPCqNHDJZTmQa8ajIMi6z5JDv TQMQVrMlHoEMY0o9o460OuXOzOta4lYcW3hPxIEZNpHWx67X32/PEFBbtKHSDwKqDVX4 K1r30hNqgNwLXON5unmG0KqWmoECA6zihtk39C58pr4EPwx4NDOIjZfC3aNb96dJV4NC vbAWi5QG4ww1P/OyMp6MFWCnhEeo8tz9I43gVheEcKtiBdXp3EB7oluRvRFNOXntEo9V lipZqVaQ7JA01W4bPkt6BFALQaBVKqKaBrmrdTbm2zh4b0XEgZkphsP+HxzJXDzo3N8t CQSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@126.com header.s=s110527 header.b=QhdU0NGy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=126.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id q5-20020a170902bd8500b001bb6d711625si1154448pls.279.2023.11.16.23.07.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 23:07:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@126.com header.s=s110527 header.b=QhdU0NGy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=126.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 1142E81B4AE1; Thu, 16 Nov 2023 23:07:04 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230105AbjKQHG4 (ORCPT + 99 others); Fri, 17 Nov 2023 02:06:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229952AbjKQHGy (ORCPT ); Fri, 17 Nov 2023 02:06:54 -0500 X-Greylist: delayed 920 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 16 Nov 2023 23:06:48 PST Received: from m126.mail.126.com (m126.mail.126.com [220.181.12.36]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4C1E0194; Thu, 16 Nov 2023 23:06:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=w+k1n axiBRigjb9CCtVvFHueFOdp+dkB3oPWurngV94=; b=QhdU0NGyLpAU8XH//DS3W zBuLHe2UcjOEFNKfGL31mchchuLgbTEOnDovgOuIvM+xwC4Dz5Xu6HiAspRN/t0s M9td+ZXci7X7I486Q8uYd4BF33vycEVSQEYLPtYlOiVxOoLoydqMwVyUpKGQ/REy h+T9RLM9qeHqQMavFmXjwU= Received: from ubuntu.localdomain (unknown [111.222.250.119]) by zwqz-smtp-mta-g3-0 (Coremail) with SMTP id _____wD3X0lFDVdliS8pCw--.42252S2; Fri, 17 Nov 2023 14:50:50 +0800 (CST) From: Shifeng Li To: mustafa.ismail@intel.com Cc: shiraz.saleem@intel.com, jgg@ziepe.ca, leon@kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, dinghui@sangfor.com.cn, Shifeng Li Subject: [PATCH] RDMA/irdma: Fix UAF in irdma_sc_ccq_get_cqe_info() Date: Thu, 16 Nov 2023 22:50:43 -0800 Message-Id: <20231117065043.3822-1-lishifeng1992@126.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _____wD3X0lFDVdliS8pCw--.42252S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxXFy5tF1kCFy7GFyrJF4kXrb_yoW5GFy5pa 45Gw1jvrsrJw42g3yFya4UKF98JFs8tFnF9a4Sy34fCr47Z3WFvr42kr4jvFW5Za43Jr17 JF1jgrn3ur45GrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRfR67UUUUU= X-Originating-IP: [111.222.250.119] X-CM-SenderInfo: xolvxx5ihqwiqzzsqiyswou0bp/1tbiFw0rr1pEH5Dx9gAAsI X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 16 Nov 2023 23:07:04 -0800 (PST) When removing the irdma driver or unplugging its aux device, the ccq queue is released before destorying the cqp_cmpl_wq queue. But in the window, there may still be completion events for wqes. That will cause a UAF in irdma_sc_ccq_get_cqe_info(). [34693.333191] BUG: KASAN: use-after-free in irdma_sc_ccq_get_cqe_info+0x82f/0x8c0 [irdma] [34693.333194] Read of size 8 at addr ffff889097f80818 by task kworker/u67:1/26327 [34693.333194] [34693.333199] CPU: 9 PID: 26327 Comm: kworker/u67:1 Kdump: loaded Tainted: G O --------- -t - 4.18.0 #1 [34693.333200] Hardware name: SANGFOR Inspur/NULL, BIOS 4.1.13 08/01/2016 [34693.333211] Workqueue: cqp_cmpl_wq cqp_compl_worker [irdma] [34693.333213] Call Trace: [34693.333220] dump_stack+0x71/0xab [34693.333226] print_address_description+0x6b/0x290 [34693.333238] ? irdma_sc_ccq_get_cqe_info+0x82f/0x8c0 [irdma] [34693.333240] kasan_report+0x14a/0x2b0 [34693.333251] irdma_sc_ccq_get_cqe_info+0x82f/0x8c0 [irdma] [34693.333264] ? irdma_free_cqp_request+0x151/0x1e0 [irdma] [34693.333274] irdma_cqp_ce_handler+0x1fb/0x3b0 [irdma] [34693.333285] ? irdma_ctrl_init_hw+0x2c20/0x2c20 [irdma] [34693.333290] ? __schedule+0x836/0x1570 [34693.333293] ? strscpy+0x83/0x180 [34693.333296] process_one_work+0x56a/0x11f0 [34693.333298] worker_thread+0x8f/0xf40 [34693.333301] ? __kthread_parkme+0x78/0xf0 [34693.333303] ? rescuer_thread+0xc50/0xc50 [34693.333305] kthread+0x2a0/0x390 [34693.333308] ? kthread_destroy_worker+0x90/0x90 [34693.333310] ret_from_fork+0x1f/0x40 Signed-off-by: Shifeng Li --- drivers/infiniband/hw/irdma/hw.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/hw/irdma/hw.c b/drivers/infiniband/hw/irdma/hw.c index ab246447520b..de7337a6a874 100644 --- a/drivers/infiniband/hw/irdma/hw.c +++ b/drivers/infiniband/hw/irdma/hw.c @@ -570,8 +570,6 @@ static void irdma_destroy_cqp(struct irdma_pci_f *rf, bool free_hwcqp) struct irdma_cqp *cqp = &rf->cqp; int status = 0; - if (rf->cqp_cmpl_wq) - destroy_workqueue(rf->cqp_cmpl_wq); if (free_hwcqp) status = irdma_sc_cqp_destroy(dev->cqp); if (status) @@ -737,6 +735,8 @@ static void irdma_destroy_ccq(struct irdma_pci_f *rf) struct irdma_ccq *ccq = &rf->ccq; int status = 0; + if (rf->cqp_cmpl_wq) + destroy_workqueue(rf->cqp_cmpl_wq); if (!rf->reset) status = irdma_sc_ccq_destroy(dev->ccq, 0, true); if (status) -- 2.25.1