Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4736918pxj; Wed, 12 May 2021 12:03:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+DZQdxHeoSu0AgrH5yqCBvl8FUBVotFjXpAQlFcq3sSPKg1iOmFuGXWqUkn1UoejHsfUt X-Received: by 2002:aa7:d90d:: with SMTP id a13mr44124397edr.76.1620846222603; Wed, 12 May 2021 12:03:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620846222; cv=none; d=google.com; s=arc-20160816; b=tFb0dLi3y6GfiGGJuXWp7QVcbmYVYUkH2GgDFUaKTVMqhXBjRcITPdrcqkZ4M4dVGl HS8BIIliMmwn5kgiTLXBf2Y8Dy8LA5/YpunHtlalWXWiS4VfXo0wlippwUa9gdvOHAdl RPYAl7/V+UStMKKfb479S/tnSBA5wl0L4qssSSrnKqkze/8Zm/xDN8v8gl8+sF+y06LI G1nrKKOWjFHj2zZMYyA+2GjUnvJKK0o5dNEoqMq089+t27E8Y4UanHLRWHJM9WCWZz2G tEDBRohCH5JE7rZlXb7RUKoh3bTygt0zIHblQ2dUpq769osA6bW4oDGJoVcYPaUM9rs4 5w9g== 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=DC+v7CQTOL0krMDyqG1VMU5tVACCbuQrSN+hMGaK1h8=; b=xXs5yo/CorugYQKeEglO441GaEQWHNgz0TjvHlo/e6YpHYX9kkWUneqrKCylfHdqNc S1gFTsUb6kqj5Qgfqnar1I69KymOR0yCKsJZ5AbQEGGxzlkFUOF0v4DtQL7ZUxxzNB8/ mMElDRlB31CYuNKRg9ulMe0P1V1R75URffEpZr3AFSKB5t/pmKH+ywLp0idCZuewjs6y y5KL7FNsgiGnjzjytxEk3a/ICHdAmI/Zk46tIqrQxGu1s7paGlmf+YxddcjIb8HbpANu pm40G7aZ9kpZKjCDnIZMg+eHSSz6AWK2H8ugFvr22ueunm+snLFZEJUdIvvlJDsKoXJN igHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=y7O6kPaZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f26si736005ejf.128.2021.05.12.12.03.11; Wed, 12 May 2021 12:03:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=y7O6kPaZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1359779AbhELSyA (ORCPT + 99 others); Wed, 12 May 2021 14:54:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:35814 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243993AbhELQmW (ORCPT ); Wed, 12 May 2021 12:42:22 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2017A61C5B; Wed, 12 May 2021 16:09:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620835756; bh=qYZsLFiEcMAcRQ/VB1HSXD+ll6OTncUh9ekmxuMEqqE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y7O6kPaZ1zRmUlgb9MVhEQUxu4pE8EvJ8yqaF8YncnPiwQrYOeuMHEW22vy1bcVhT TNtmcBtx9HzI5HREqRmr8eFyL2r8+TB7NJxNYnChOmr46RolV2XCo3vx8nGOwzOgDz EbXcVsP9GJtK2I7fn5I5+Cb6hu2b0Q6cS3dBrVYo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lv Yunlong , Sagi Grimberg , Leon Romanovsky , Max Gurtovoy , Jason Gunthorpe , Sasha Levin Subject: [PATCH 5.12 472/677] IB/isert: Fix a use after free in isert_connect_request Date: Wed, 12 May 2021 16:48:38 +0200 Message-Id: <20210512144853.040391996@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144837.204217980@linuxfoundation.org> References: <20210512144837.204217980@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lv Yunlong [ Upstream commit adb76a520d068a54ee5ca82e756cf8e5a47363a4 ] The device is got by isert_device_get() with refcount is 1, and is assigned to isert_conn by isert_conn->device = device. When isert_create_qp() failed, device will be freed with isert_device_put(). Later, the device is used in isert_free_login_buf(isert_conn) by the isert_conn->device->ib_device statement. Free the device in the correct order. Fixes: ae9ea9ed38c9 ("iser-target: Split some logic in isert_connect_request to routines") Link: https://lore.kernel.org/r/20210322161325.7491-1-lyl2019@mail.ustc.edu.cn Signed-off-by: Lv Yunlong Acked-by: Sagi Grimberg Reviewed-by: Leon Romanovsky Reviewed-by: Max Gurtovoy Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/ulp/isert/ib_isert.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/infiniband/ulp/isert/ib_isert.c b/drivers/infiniband/ulp/isert/ib_isert.c index 7305ed8976c2..18266f07c58d 100644 --- a/drivers/infiniband/ulp/isert/ib_isert.c +++ b/drivers/infiniband/ulp/isert/ib_isert.c @@ -438,23 +438,23 @@ isert_connect_request(struct rdma_cm_id *cma_id, struct rdma_cm_event *event) isert_init_conn(isert_conn); isert_conn->cm_id = cma_id; - ret = isert_alloc_login_buf(isert_conn, cma_id->device); - if (ret) - goto out; - device = isert_device_get(cma_id); if (IS_ERR(device)) { ret = PTR_ERR(device); - goto out_rsp_dma_map; + goto out; } isert_conn->device = device; + ret = isert_alloc_login_buf(isert_conn, cma_id->device); + if (ret) + goto out_conn_dev; + isert_set_nego_params(isert_conn, &event->param.conn); isert_conn->qp = isert_create_qp(isert_conn, cma_id); if (IS_ERR(isert_conn->qp)) { ret = PTR_ERR(isert_conn->qp); - goto out_conn_dev; + goto out_rsp_dma_map; } ret = isert_login_post_recv(isert_conn); @@ -473,10 +473,10 @@ isert_connect_request(struct rdma_cm_id *cma_id, struct rdma_cm_event *event) out_destroy_qp: isert_destroy_qp(isert_conn); -out_conn_dev: - isert_device_put(device); out_rsp_dma_map: isert_free_login_buf(isert_conn); +out_conn_dev: + isert_device_put(device); out: kfree(isert_conn); rdma_reject(cma_id, NULL, 0, IB_CM_REJ_CONSUMER_DEFINED); -- 2.30.2