Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp2207651rdb; Mon, 20 Nov 2023 05:17:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IEkLSk6aOynqOVrw3ADFIVvxNT7x6bZAzc2WFb1RWkA4HuyA/bIRz8xwuAYh5Lo9HW5ilPO X-Received: by 2002:a05:6a00:e07:b0:6cb:42de:24e0 with SMTP id bq7-20020a056a000e0700b006cb42de24e0mr6400091pfb.28.1700486274626; Mon, 20 Nov 2023 05:17:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700486274; cv=none; d=google.com; s=arc-20160816; b=AKoxZTBNjuVTi27SjXwZqPapkxQyceQYCMnBqZ1eDViO4Swo9SJpBwrpw8dTtm04cz ak0sT9xnzFSmRXPYGiPojy7ny+LUJ8O5th4IfrFpBh6WEhlTohRNzydeF5iz3pf5vDKw jTUtNRMHYdzlsxeuSmLelp8J0rOFs7g1y0vehM18I3HQTO5eJsIJQOn+FJ39Kzdb4M3T u+UgGAX0AVWlDT8SHsi0YUecphnMm2HxaFmkqki8tNnxhcmrHoim42d1IpdUSCY8Ij25 ovcidzyGTry5t/al9oyqyNqmy7cT7EV4uilc3OTbSxF77UEUOrfIfzTl/iyqzoP7T1cm ZnQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=IRTWkzq+mZIfxkQtrcyg7e+T0ZFBaY6OXSxXhJkhqJU=; fh=qbpIcWFAgt1thdhzZOITJaI1HR6sQ0ZdtrML7d39yi0=; b=qnBBb82uDeubL0BdHEYwa86RYnKfYoQDY/5xofpHzd3ByZSOzq7U8VYKbHQfMLoLnI qvOM2h1h++vLPcKih6zY97V3WLnNpvsgfUOZnne3t3rpv0t37cnFQ0pG/aYtqwq5tULp aSvTbdxk0YWVmY7h+D+DT0ActXBWHoDTdrYPIt/5PO/0aQTFQY/vgCJLOPgcLIEsfeE/ 3xrfiN2fbW9XIodOF2tH1tzQ+OS9QyrgV5atVUBYPlgAIk20BKSy5mTleRwvqySdAd7w vEuBwMemNSLcxWMPn4wjmiSVHHg500GTvavdc/l9nDTmq3BGVh0C7DfZl+EQjA1tFJzr PHsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="qsNq/mpB"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id m20-20020a056a00081400b006c0febe4496si8568528pfk.205.2023.11.20.05.17.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 05:17:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="qsNq/mpB"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 5C06A8069D8A; Mon, 20 Nov 2023 05:16:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232138AbjKTNNV (ORCPT + 99 others); Mon, 20 Nov 2023 08:13:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231961AbjKTNNU (ORCPT ); Mon, 20 Nov 2023 08:13:20 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 956EEF2; Mon, 20 Nov 2023 05:13:17 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B035CC433C7; Mon, 20 Nov 2023 13:13:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700485997; bh=EdLuhwM7Jtz2SU14padLa5AJv5bzwq3E/Djcv5K11gQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qsNq/mpBUNNeEZJh168u3w41TsczwfkNL5GVNI0206KdYZvP8FjbVlO2Y/tH1pI0L OeZUkTuYA962aukwWdPtNsLrBnSJYSc+f4n1A4JQCHOFqZE63Vl7snEUztuAPdFuR7 7Pl5oWEq2LVlJBwqM/2PdsAdWyt4mPtgVnXIxOhO7ca1uOgVJD4fu7U8OhmAjw9Mb5 q4fOieTxKXfcWR5SBPjhpAb/k7h8LbAGwIg4IhctZTqH/U4aFFMOBqoJG7Z4FYNrmO hktx7i45Qwx/lqS6IkXGpb2Stbncd/cObXmGi54blCz+0N48oERzQl6qnDUzIFQQ3B 4Yq5PfltWGpNw== Date: Mon, 20 Nov 2023 15:13:12 +0200 From: Leon Romanovsky To: Shifeng Li Cc: mustafa.ismail@intel.com, shiraz.saleem@intel.com, jgg@ziepe.ca, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, dinghui@sangfor.com.cn Subject: Re: [PATCH v2] RDMA/irdma: Fix UAF in irdma_sc_ccq_get_cqe_info() Message-ID: <20231120131312.GC15293@unreal> References: <20231120024940.17321-1-lishifeng1992@126.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231120024940.17321-1-lishifeng1992@126.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 20 Nov 2023 05:16:12 -0800 (PST) On Sun, Nov 19, 2023 at 06:49:40PM -0800, Shifeng Li wrote: > 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 > > Fixes: 44d9e52977a1 ("RDMA/irdma: Implement device initialization definitions") > Signed-off-by: Shifeng Li > Acked-by: Shiraz Saleem > --- > drivers/infiniband/hw/irdma/hw.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > --- > v1->v2: add Fixes line. This patch doesn't apply cleanly due to this patch. https://lore.kernel.org/all/20230725155505.1069-3-shiraz.saleem@intel.com/ Thanks > > 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 >