From patchwork Wed Oct 19 08:30:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4779 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp215717wrs; Wed, 19 Oct 2022 02:16:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7p9sETZg0CIpSEjlam/9zogZpc/ISGJ/t+NjRN793aOdteDbzekaIrnv5jdec7Yu67jq/y X-Received: by 2002:a17:907:760b:b0:78d:9d67:83b9 with SMTP id jx11-20020a170907760b00b0078d9d6783b9mr5819570ejc.568.1666170987797; Wed, 19 Oct 2022 02:16:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666170987; cv=none; d=google.com; s=arc-20160816; b=XhY9fCR39kfrtQlbIut6uS8+rehRDsvMz0g2szyqrn9L5yqPO1DsX4u9AnuwlRz84i 0A1sfeBJd4VnVDCs9zsrCzK6giV72tS7HvaS5kEA8GP8IUicUbCGdK7TzEqR7YXkY692 iBXDcMs6etQczpqLn4gaGiXdRaqliUhoLdxILeoH0163BT3GwwVFJZ7pZgPxwHX7ZxP1 STVi5j5pYiTeY7cnNjCVvsDvhYooBP3Xk3n89IRT0Mw2uLUVyzsDQUSjeUcIYLaDHqn6 c5dTgpJkB28dIahgkQYsty63JRjnn+YjwFWErva3VzCO/OcIcSuB4UNSewniuDvdf9KK xRWA== 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=3943B9jb7S3kyt4/eqG7dN2tyGV+alXqbqBaEMH8+Sw=; b=oWGfgxWSUjjAdQGVT+fTAaib1ES2s/rmDLoFtUsk7821Xd8fa/n45IfFkfY/i9vkQe yl/oAVYx0EbZ9x3wr9S5Mf4IuGMxZp6GWRp2TsENjldvNY94/aTMN25eGXs0j7lVdZI9 5JtfkAT7YN5Q6wmmNKNskIQeDsJpV1r9d9yrQZy36KPJYK6VdZtD+x3qYuIX5d4ayXGU S0h3RWAC4g6+y4q8vO7n3h9fNdIRvfU39dyYLqgxEyYG/K40OciQ6Z5YNQDHBNcrKGjn FCSnpq/S1fOVvqpG1AGBpvSSgBx8eMb/dUecWKOontX0AunE2OvZKc2gW5SZ9bz4qM0r /RtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fCaPBBbx; 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 c11-20020a0564021f8b00b00458ab55ccc9si14719207edc.168.2022.10.19.02.16.03; Wed, 19 Oct 2022 02:16:27 -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=fCaPBBbx; 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 S233044AbiJSJNf (ORCPT + 99 others); Wed, 19 Oct 2022 05:13:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232637AbiJSJK5 (ORCPT ); Wed, 19 Oct 2022 05:10:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E1B0C4DB9; Wed, 19 Oct 2022 02:02:33 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 7C92161825; Wed, 19 Oct 2022 09:02:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E90CC433C1; Wed, 19 Oct 2022 09:02:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170127; bh=SVGyauJPlNV9CwUJHeaBYDZmpQHU7dMSWq2bl8Wcheg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fCaPBBbxP023kNdTCIlsZDp8DveWT6QXLeEwTFuGGCOgsMt2IYKAnQ4n1Sf1FShV+ 7I5uyt/VYHvI32vpKh8mETZTcrSd9Q9usGR6n2fK2VbmL7JLLMyoKzyMjI/suDKueO 5qKHN3a9FmZn8Q8MPQsJOQgrqcFHBl6eF/xk+rdw= 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 6.0 538/862] RDMA/siw: Fix QP destroy to wait for all references dropped. Date: Wed, 19 Oct 2022 10:30:25 +0200 Message-Id: <20221019083313.726298309@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 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?1747106909842146682?= X-GMAIL-MSGID: =?utf-8?q?1747106909842146682?= 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 8dedae7ae79e..3e814cfb298c 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; }