Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4626894pxj; Wed, 12 May 2021 09:32:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwM3X5JsFNdLQGbc6YLnUj+3fj9XQ3iOuR7tdffPFxesxHw+EHDETrlgnbcKP8VZgtnIBxd X-Received: by 2002:a05:6402:d05:: with SMTP id eb5mr44167780edb.6.1620837126817; Wed, 12 May 2021 09:32:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620837126; cv=none; d=google.com; s=arc-20160816; b=diWWlaVu+ksihMIBYXSIbAhVsnfRqGlFpJE2OZq8XFzL76NTvZT8e9aSh7c+/yg6Io D149sH3AHpk+sJSrjZxWFUwF63MtClBOZGq43GCZCULOgs+03Ln35fqESmoLdnr8KCTv bsDvccuEb+Yxc2PCLOsX/ax2/iBuiWrJFM7ybSerL0ekZQQvfxl9xwzbiLT/E8xhhR5w A2bhDED+DyHSwHIhCrJ+Vg+YOa6WR3o2d4tMcowyovvfcnOPftU563lPEoubuhSH+Z54 y5TVPVDBenAGsBMEQYBjqZxjJcgcWtbQcqDE4ggZizr8mnAx/Ov2fMtLKt7t5Id4ZUSW 2hqg== 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=ZQ3rF55/o/9CbeAirWg76b9dSwutRMPxAV1rNUfCOjc=; b=PQGDByxMrQ0No9Ysh5x9XWkQGDtO6efJ2n6ll5xuY1mwrbby91hNdpcliLSrNffsK0 kfmZkrwM8YriKTG0et5vp+eWMhWwz5IJzoYmaBTn9BYmYnQ/QhkahQV0QIU/uW/c66NA OjgzM3p70aFeDj/VbL7+cZ5kuRUkBJf5zgyP3zChoXnfnBc0XaSi3/8DsZR5wak8ldEX NhCBW0IOpeODGmrq779aOxShsrY4W/h21jkCE3pEzhny2CgfhYLA9qb9q+qtmWsCCn1g QwgYhYmUcaUIWR6ihsAL+lPzA1Wy6lDLTsg5Eu1IxyUSfgZrkfS0+PikdnCOHkON+NZM AB0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xInGsXv0; 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 j11si372662ejy.418.2021.05.12.09.31.42; Wed, 12 May 2021 09:32:06 -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=xInGsXv0; 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 S240783AbhELQZf (ORCPT + 99 others); Wed, 12 May 2021 12:25:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:56688 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236334AbhELPho (ORCPT ); Wed, 12 May 2021 11:37:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 130A261C5A; Wed, 12 May 2021 15:19:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832751; bh=YLOmhJ7HfP38QkJFXy0sv+hxh0svdSTboTyR9xfawvE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xInGsXv0YU3/70m2cUBpivuxqcVXYYYI0xNfKrCEwddvLctFVNIMZseFEj4CSFj3G Q9uCvwg1+ocyr3hMG9HDN6rnUPb3B7HOPGVwOCCBP2HiNLDipcJJpvFxhHUqvAYk5c bWFC8bnoMGNNMAxd9rn4O73goEorIfCqAeTUw6tI= 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.10 374/530] IB/isert: Fix a use after free in isert_connect_request Date: Wed, 12 May 2021 16:48:04 +0200 Message-Id: <20210512144832.070956826@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@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 bd478947b93a..e653c83f8a35 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