From patchwork Sat Oct 22 07:25:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7577 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1106275wrr; Sat, 22 Oct 2022 01:37:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6M3xZXi9aeH1fJKkK9tpHtY6DTiuQB5BXfeT5mW5t3CcyNKH4VcPSvRGNRXyeYILAqWpaj X-Received: by 2002:a17:906:58c7:b0:722:f4bf:cb75 with SMTP id e7-20020a17090658c700b00722f4bfcb75mr19023908ejs.450.1666427833434; Sat, 22 Oct 2022 01:37:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666427833; cv=none; d=google.com; s=arc-20160816; b=zS7MQDJum+4HCqShXPxaF3YKZRBoxlDr9pfY2hCr80HusWwxBQ5vayO9cjQ4lE/0+I I5SZMUCACd2MIg3ydyfz02eXgZXcLGvVyUgXWi1we2mROqbi4zcpqcFyUhGE+03yAIH6 VCw1R7LGt8JvqM6Ahe2HameEzbzTaY0Vaox28E/hsXZhX5NS+6i+dRGz1d6KYXh4RndT t0UZAa6yMDtCTRlfn3pbMnQt6blxbg55NTjrhB8SpXS/WmLyWXKAv9xEzAZ5nfPLV6Em zEKpRyKP58jeKn/aeRaVVu5YCcbqmeGIG58NvhXR6aqx9XX1JCtr2Foai+awjHn38L8A WN9Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=WuHcgaNB7AD0dlIy3T/zniGXed44No87gpLgAs9eJaI=; b=YtX2nULEx+Jchn/if2P+yknI0t80+actjLc+qcSKq20LS9G+zmPw+WDh7oa9HQiEVX P9Yjt/jMxQIajyKnCJnOla33E2UvErufFBiYoaGME/u6usEsujs4SVg3RDZVWpvC8Td1 aRMr2Kb/sd3o15hQSp6l2lNn+19AgFqrwAOauWMGN/lSWwAe5/qNwjKjYuKY/lBD8jzL //Sx4l0LCPbE4achV07poThUmutVnUfuW1a3AM7I7mhfbbrDv/q8RcbQPJpa8luJbjIP tACXbDz3y4GkbD/M0bwHH9NGUCjKbipdd7HmW/T24F66Cr5pOrtSOyDP8p9PIQCSQmYD yt2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HjtWpkAh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id go11-20020a1709070d8b00b0078ac0d5d03esi19041861ejc.562.2022.10.22.01.36.44; Sat, 22 Oct 2022 01:37:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HjtWpkAh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233980AbiJVIcC (ORCPT + 99 others); Sat, 22 Oct 2022 04:32:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233987AbiJVI3G (ORCPT ); Sat, 22 Oct 2022 04:29:06 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9E5F2CB88B; Sat, 22 Oct 2022 01:01:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 52845B82E07; Sat, 22 Oct 2022 07:53:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC416C433D6; Sat, 22 Oct 2022 07:53:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425226; bh=QuHmkVD5GrEIany+pQ95OQ4C3Xd093q6+PFGtcYblMY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HjtWpkAhRNoAb0dcNMfmbedHD5DZFCT/Z3oxjeIA1hGcgx94hPpf/ba+d9BJU7JJ9 ZjOHIF6vVcVqDMgXxBZTs1EH+vzMYCe/Iqv1yNuhbO9ohpYJRHpWx66WkfVkHsc1tw f4sfrGAmlb85VUU2V6KIEZKr9Hbp5h/X6xbLB4JM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Olga Kornievskaia , Bernard Metzler , Leon Romanovsky , Sasha Levin Subject: [PATCH 5.19 433/717] RDMA/siw: Fix QP destroy to wait for all references dropped. Date: Sat, 22 Oct 2022 09:25:12 +0200 Message-Id: <20221022072517.571666640@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747376232032276300?= X-GMAIL-MSGID: =?utf-8?q?1747376232032276300?= From: Bernard Metzler [ Upstream commit a3c278807a459e6f50afee6971cabe74cccfb490 ] Delay QP destroy completion until all siw references to QP are dropped. The calling RDMA core will free QP structure after successful return from siw_qp_destroy() call, so siw must not hold any remaining reference to the QP upon return. A use-after-free was encountered in xfstest generic/460, while testing NFSoRDMA. Here, after a TCP connection drop by peer, the triggered siw_cm_work_handler got delayed until after QP destroy call, referencing a QP which has already freed. Fixes: 303ae1cdfdf7 ("rdma/siw: application interface") Reported-by: Olga Kornievskaia Signed-off-by: Bernard Metzler Link: https://lore.kernel.org/r/20220920082503.224189-1-bmt@zurich.ibm.com Signed-off-by: Leon Romanovsky Signed-off-by: Sasha Levin --- drivers/infiniband/sw/siw/siw.h | 1 + drivers/infiniband/sw/siw/siw_qp.c | 2 +- drivers/infiniband/sw/siw/siw_verbs.c | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/sw/siw/siw.h b/drivers/infiniband/sw/siw/siw.h index df03d84c6868..2f3a9cda3850 100644 --- a/drivers/infiniband/sw/siw/siw.h +++ b/drivers/infiniband/sw/siw/siw.h @@ -418,6 +418,7 @@ struct siw_qp { struct ib_qp base_qp; struct siw_device *sdev; struct kref ref; + struct completion qp_free; struct list_head devq; int tx_cpu; struct siw_qp_attrs attrs; diff --git a/drivers/infiniband/sw/siw/siw_qp.c b/drivers/infiniband/sw/siw/siw_qp.c index 7e01f2438afc..e6f634971228 100644 --- a/drivers/infiniband/sw/siw/siw_qp.c +++ b/drivers/infiniband/sw/siw/siw_qp.c @@ -1342,6 +1342,6 @@ void siw_free_qp(struct kref *ref) vfree(qp->orq); siw_put_tx_cpu(qp->tx_cpu); - + complete(&qp->qp_free); atomic_dec(&sdev->num_qp); } diff --git a/drivers/infiniband/sw/siw/siw_verbs.c b/drivers/infiniband/sw/siw/siw_verbs.c index 09316072b789..598dab44536b 100644 --- a/drivers/infiniband/sw/siw/siw_verbs.c +++ b/drivers/infiniband/sw/siw/siw_verbs.c @@ -480,6 +480,8 @@ int siw_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *attrs, list_add_tail(&qp->devq, &sdev->qp_list); spin_unlock_irqrestore(&sdev->lock, flags); + init_completion(&qp->qp_free); + return 0; err_out_xa: @@ -624,6 +626,7 @@ int siw_destroy_qp(struct ib_qp *base_qp, struct ib_udata *udata) qp->scq = qp->rcq = NULL; siw_qp_put(qp); + wait_for_completion(&qp->qp_free); return 0; }