Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2537926yba; Mon, 6 May 2019 07:41:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqyd2O6N0MfSJnTeGm7KMGjuuLrm/2z9BFbGNxTTUgAzi1OUYzvJLFH2u+qww8QzzbHjkVQV X-Received: by 2002:a63:e042:: with SMTP id n2mr7352465pgj.201.1557153669908; Mon, 06 May 2019 07:41:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557153669; cv=none; d=google.com; s=arc-20160816; b=PgMarAlWmbhdexPqAdxDkIsssoWTHcUx+Po9xps44K6xnjwXvkkWpgaV81cJ2UBI6m h16eV8W3Kij/WIIyDAFakGuORLcyxHYj03IV+UeVv1Ni1rE5WvPXvub8BZyfK8wcxAvh JQz0Qzla1z1sX+p1SyQlb7xgnKPhhC5GbVYTRRJP/HPAtN2rBVKFranvncNn5SywcZNU ILLCaRNxC3ifqYwMty4dwXYQV3oaxthpmYQtOC3wiTd4At0ViUjLBOpjHCvZCzY9aVu5 XA1OWijmQH8qChuWus/+FAUGkWRu3MLPuH4tuzZI5bD0BevwfJmJ6oxdWuTYAieNYYn8 uULQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CtsbBbsO+wvM+XkpqZz0d1Ct2NHGQuuaEiv1KpyqXtY=; b=HSHUT5LNbDsdaaAu24tmcuEDY59bNxiC2v2i1wa9du6EuA9zDUvWdhB1K0qvuz+ECy 1KqbAy1kofTpAVMxCmDw7pwrTziESbNkh4+5M4jvPny5NdimiycLt3QsbEHwhegNqUAO x+CGYWmNckqbRzm0AsEEjws07zIyX/WpdlepWQGwlLUdVAl3HCZPBzevrFYOjrUfeezk uJtTneTjmo/MPe1soKGYKXDXZ3sGzH2E5G9rWVkXbRiwLvlEemkDuTGSbfRcwnFXoVwo 6q85z5R18z8E+DSexl9ClKkCAb8REjKRgezdk/3KMv0ZFk/WIbeU1Yb7I+NOpzHGWx3G WDNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="llPeup/C"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m10si13845943pgq.39.2019.05.06.07.40.53; Mon, 06 May 2019 07:41:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="llPeup/C"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727743AbfEFOjI (ORCPT + 99 others); Mon, 6 May 2019 10:39:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:60442 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727737AbfEFOjH (ORCPT ); Mon, 6 May 2019 10:39:07 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 26B4421479; Mon, 6 May 2019 14:39:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557153545; bh=drJzGQRvPDLu2T3YjTdevjln3E4+BxvfPv+TvbHmfis=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=llPeup/CoeZED2Akx9I3RG1E6uFw0QV4Ri2ce778xy8JFGflDm6Tg5IWWNnSRzx22 /InYdGaVQrtvKD0TyH4yOrffxBed1KbVo1oCLW2MJdgj6RfXmeiGuHhwOeKiWYYinb RLdItlN788UKIXr2iYmOI2SL+gImvBmHiDotL6WE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Parav Pandit , Yuval Avnery , Daniel Jurgens , Leon Romanovsky , Jason Gunthorpe Subject: [PATCH 5.0 108/122] IB/core: Destroy QP if XRC QP fails Date: Mon, 6 May 2019 16:32:46 +0200 Message-Id: <20190506143104.265363973@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190506143054.670334917@linuxfoundation.org> References: <20190506143054.670334917@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yuval Avnery commit 535005ca8e5e71918d64074032f4b9d4fef8981e upstream. The open-coded variant missed destroy of SELinux created QP, reuse already existing ib_detroy_qp() call and use this opportunity to clean ib_create_qp() from double prints and unclear exit paths. Reported-by: Parav Pandit Fixes: d291f1a65232 ("IB/core: Enforce PKey security on QPs") Signed-off-by: Yuval Avnery Reviewed-by: Parav Pandit Reviewed-by: Daniel Jurgens Signed-off-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/core/verbs.c | 41 +++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) --- a/drivers/infiniband/core/verbs.c +++ b/drivers/infiniband/core/verbs.c @@ -1106,8 +1106,8 @@ struct ib_qp *ib_open_qp(struct ib_xrcd } EXPORT_SYMBOL(ib_open_qp); -static struct ib_qp *ib_create_xrc_qp(struct ib_qp *qp, - struct ib_qp_init_attr *qp_init_attr) +static struct ib_qp *create_xrc_qp(struct ib_qp *qp, + struct ib_qp_init_attr *qp_init_attr) { struct ib_qp *real_qp = qp; @@ -1122,10 +1122,10 @@ static struct ib_qp *ib_create_xrc_qp(st qp = __ib_open_qp(real_qp, qp_init_attr->event_handler, qp_init_attr->qp_context); - if (!IS_ERR(qp)) - __ib_insert_xrcd_qp(qp_init_attr->xrcd, real_qp); - else - real_qp->device->ops.destroy_qp(real_qp); + if (IS_ERR(qp)) + return qp; + + __ib_insert_xrcd_qp(qp_init_attr->xrcd, real_qp); return qp; } @@ -1156,10 +1156,8 @@ struct ib_qp *ib_create_qp(struct ib_pd return qp; ret = ib_create_qp_security(qp, device); - if (ret) { - ib_destroy_qp(qp); - return ERR_PTR(ret); - } + if (ret) + goto err; qp->real_qp = qp; qp->qp_type = qp_init_attr->qp_type; @@ -1172,8 +1170,15 @@ struct ib_qp *ib_create_qp(struct ib_pd INIT_LIST_HEAD(&qp->sig_mrs); qp->port = 0; - if (qp_init_attr->qp_type == IB_QPT_XRC_TGT) - return ib_create_xrc_qp(qp, qp_init_attr); + if (qp_init_attr->qp_type == IB_QPT_XRC_TGT) { + struct ib_qp *xrc_qp = create_xrc_qp(qp, qp_init_attr); + + if (IS_ERR(xrc_qp)) { + ret = PTR_ERR(xrc_qp); + goto err; + } + return xrc_qp; + } qp->event_handler = qp_init_attr->event_handler; qp->qp_context = qp_init_attr->qp_context; @@ -1200,11 +1205,8 @@ struct ib_qp *ib_create_qp(struct ib_pd if (qp_init_attr->cap.max_rdma_ctxs) { ret = rdma_rw_init_mrs(qp, qp_init_attr); - if (ret) { - pr_err("failed to init MR pool ret= %d\n", ret); - ib_destroy_qp(qp); - return ERR_PTR(ret); - } + if (ret) + goto err; } /* @@ -1217,6 +1219,11 @@ struct ib_qp *ib_create_qp(struct ib_pd device->attrs.max_sge_rd); return qp; + +err: + ib_destroy_qp(qp); + return ERR_PTR(ret); + } EXPORT_SYMBOL(ib_create_qp);