Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4683348pxj; Wed, 12 May 2021 10:48:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5mCDqQSH+YzvgCExDVcb0/d3yfm6DH5EFDKDdJKh1asrstXUMj6f2AR7q7P+1UcRaUbZS X-Received: by 2002:a17:906:7e0f:: with SMTP id e15mr227369ejr.398.1620841705609; Wed, 12 May 2021 10:48:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620841705; cv=none; d=google.com; s=arc-20160816; b=w+WyY4fapi7T4K6bT9F+g5OnTdHyQiIfrdpeG25zsxyHYmnzRrTEeXeGGH56rtuMP0 hWitxrngc9ePI8nbWUoMbRyQuCbUYRiGQoNSih8anKD074FvCG6Q1+FWttKHCJCZ1DHM D4SinDxDVJaldGWONetCZyK5Xc7S03fTe6n3monLcGqU0NHR2opmoDFk6eubB4XRno9J W1LleBHTnJGPxy9ySiv/f6MVSAUhgx0XQbVS7yHBjJQ5gLyLlNzt9/M91NkjVXLJbC3V 2bjTMpjhwjB5Pn/55etnBrETPcXlw1etKeIzjW4urmzXv5HDv2Jg4EfS5QP1khl63w5W +0SA== 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=LhXIUKbLD6iZl2tG3PkGySIlPDZRNef0/G7xW2bpNl4=; b=mPddLyh3OmLeEk3Z9RqZTJ2NBZRyJFYx7AHzCAkPvsRM5nWbU3uhtILSvj62z2YtIv UBNix33VF0MINcH/9pOuvwwupuQi5aHk8v5PUDaamka0pY4ue9+7KSx9xvf/uvz7ek6n 3EvLav+lXSsB3KWK7lf9x/E9Nd+vpS3s8wanQ3z3jnMZfrVfgtML3oKjGA8iT9rrE0a9 NTKF2OXjvNVC1cge/AdZJcU0ruD+1FFmlLlqJcKjerd7/jqVIJUPlUrtOuUEZ9v/0yL9 jvbn1ug1McFq5RpaK7fYsI572TOBK7PqpTLAT1+asV6u9Z97CXkzs9vLs7zWlnUaQ8go Xn4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nl0LylDs; 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 s19si292112edd.423.2021.05.12.10.48.01; Wed, 12 May 2021 10:48:25 -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=nl0LylDs; 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 S239658AbhELRk7 (ORCPT + 99 others); Wed, 12 May 2021 13:40:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:49652 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236679AbhELQOf (ORCPT ); Wed, 12 May 2021 12:14:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A257E61CCE; Wed, 12 May 2021 15:42:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620834127; bh=8Y09VXsnasBtoNug1N3cjQaxjpT+nb0+24JLvqZ0/Zw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nl0LylDsk8YkzfMzGGhMeClKjj+G47pcfFcOUbMgIW82tfILnTmUklJaQc3qkgmU0 CEdJNbfHdJHR3l85HhudwwsHAkXzTbPTt51RyDokfiWmI/VXZ6UYDDzwLp4PloeuDL JsbVtu/SZTOdOD57Dqaq/Ydhxl2cMRxxKgGmWBWU= 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.11 419/601] IB/isert: Fix a use after free in isert_connect_request Date: Wed, 12 May 2021 16:48:16 +0200 Message-Id: <20210512144841.630001946@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144827.811958675@linuxfoundation.org> References: <20210512144827.811958675@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 2ba27221ea85..11339cc72214 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