Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4628451pxj; Wed, 12 May 2021 09:34:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVwOuj5OYNHUZS+4NMSTw4vXP7JSMKdXX39VbVFBl+A5ZWecXXaUifwtTI9IjMNHZcNVuL X-Received: by 2002:aa7:cb48:: with SMTP id w8mr44424815edt.55.1620837251422; Wed, 12 May 2021 09:34:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620837251; cv=none; d=google.com; s=arc-20160816; b=NSIYksPxMQofPvupb6+OQMHxYzh0dj+Ty1oHfygutVKFCDkGV3eCaoMSPpwBA7+NmX gwztTmyr6No+ZDbsc7ANZf0c/EDGNBIdIdRTXxvnuV2oBACTHxXp/sqrBMqxd6xvaPRv 7izHuukFTKmVo6O78JrygdTWVIRwjawaVGINZkQn/5hAErqBPvdtz1Dc38nQMYHf2VYY WyLOKDe0FzUNQ7ldiCCkiRG5sLGSftm+oHErGRR81ywDq9pHKL4fupaSda5CElUK5XmM I2Ijo7Ix0ZsKlUtvBh7sWCqQO2i+Cu65MeQ2S1e3BS7ppgSr5xWIP2/ltBXrWGMc5k4Y qULA== 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=Irr6i7tQHKCzQPDjzt2J8GVg83sD/BnofrvstH/2gI0=; b=ib1wvJsCZQ/VdNY+nruidiO3IRSQDdMvJX4uKsk4NM2K8+kQMMwzNkrDRmHJ8iW8Hn S/nSiaWID0x4RW06A8+LnsGSHvz49hOONSjgxCkLD2VfiiHL/mQB3I87HRFyA04mK+UL 7KUyA4IdI9z9KAC0atQISnFD/OTloAF3PtV0XzTyAxNf6T+A/LvAzyx5aKVjAN4EELUO hKK7T786NIKO5sEcAG0HN3BDVNxq8A1bz2zos7/LpxY4VcPukWLDiO7O8M+gB/ViZIor nyb09d23xkdxeIaAvbkZh+eHrbVFFldqvVzP0oytlbicOQmDZS/4ihfVgQdMdQMVGQ4f VqNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rXVztiz9; 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 b19si145199edr.521.2021.05.12.09.33.46; Wed, 12 May 2021 09:34:11 -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=rXVztiz9; 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 S241452AbhELQ1T (ORCPT + 99 others); Wed, 12 May 2021 12:27:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:56692 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230386AbhELPiF (ORCPT ); Wed, 12 May 2021 11:38:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5C16A61C6E; Wed, 12 May 2021 15:19:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832797; bh=fO2fHsD0IVdto+d7E9gn9FjLdq6EZNwkwUaeS+EI/Ow=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rXVztiz9pImJHnTR0Zix04k/0o6PQVI8hEAlo/Tfw0mkq/uiHupLJZE4FW/20F+yn aRCqMMaH+liBseIhb3YTO+LjGQsBNxEaaKRMTqfdlN3ML79LGZy183shPqAf5xxcAM JCmjPsyFDTVmx7zD30fjEU0CZkwaCzCd42p6lbO8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gioh Kim , Jack Wang , Jason Gunthorpe , Sasha Levin Subject: [PATCH 5.10 427/530] RDMA/rtrs-clt: destroy sysfs after removing session from active list Date: Wed, 12 May 2021 16:48:57 +0200 Message-Id: <20210512144833.804933395@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: Gioh Kim [ Upstream commit 7f4a8592ff29f19c5a2ca549d0973821319afaad ] A session can be removed dynamically by sysfs interface "remove_path" that eventually calls rtrs_clt_remove_path_from_sysfs function. The current rtrs_clt_remove_path_from_sysfs first removes the sysfs interfaces and frees sess->stats object. Second it removes the session from the active list. Therefore some functions could access non-connected session and access the freed sess->stats object even-if they check the session status before accessing the session. For instance rtrs_clt_request and get_next_path_min_inflight check the session status and try to send IO to the session. The session status could be changed when they are trying to send IO but they could not catch the change and update the statistics information in sess->stats object, and generate use-after-free problem. (see: "RDMA/rtrs-clt: Check state of the rtrs_clt_sess before reading its stats") This patch changes the rtrs_clt_remove_path_from_sysfs to remove the session from the active session list and then destroy the sysfs interfaces. Each function still should check the session status because closing or error recovery paths can change the status. Fixes: 6a98d71daea1 ("RDMA/rtrs: client: main functionality") Link: https://lore.kernel.org/r/20210412084002.33582-1-gi-oh.kim@ionos.com Signed-off-by: Gioh Kim Reviewed-by: Jack Wang Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/ulp/rtrs/rtrs-clt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c index 6ff97fbf8756..7db550ba25d7 100644 --- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c +++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c @@ -2803,8 +2803,8 @@ int rtrs_clt_remove_path_from_sysfs(struct rtrs_clt_sess *sess, } while (!changed && old_state != RTRS_CLT_DEAD); if (likely(changed)) { - rtrs_clt_destroy_sess_files(sess, sysfs_self); rtrs_clt_remove_path_from_arr(sess); + rtrs_clt_destroy_sess_files(sess, sysfs_self); kobject_put(&sess->kobj); } -- 2.30.2