From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 727823242BE; Sat, 30 May 2026 18:19:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780165167; cv=none; b=QdhR54btCHIr0i9ytsYVw6d+3lctjXy41MH58DGO4RkK/aX2UoAVmB5mcrTE8+pQ434aD56VdbLyTf0G59AYQ1n0ojMJLdlahTd8IjxtHR5w7/CpW0Yea1SpjSadILTcesvID7suTE5lPT1vBc7dwR3O/+fEagNzOvFQ4TuCl48= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780165167; c=relaxed/simple; bh=FgHdVxFT69f7FZlqAO3n2HuX494kW07Pj6Vupi557+o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k4q/PzHUPdEy4nmUS5/FAFoaGggvFdJjvNdlTIMU6zgnnY9dZMlhnAzzVLCHTFPSgPimdT5lL4mTKKAYgDdI8sqwAgFa+5Xeprn7J94Dk47JnRnVfn/iSFs8YVYbua9qpehRKA9RfkIO91m2bpV+K/LnepjCDmHpwWsthW77EdQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=tgmuWiQU; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="tgmuWiQU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B79CC1F00893; Sat, 30 May 2026 18:19:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1780165166; bh=E2Wc5LhiFGNm1VldT+c/ukYSw6tollpKjrRfaw8RHTs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=tgmuWiQUD2dYgjvsFV0Bma5M3lk6C1pk80gxhpA2hHED8oTo7PypwSbOnjMlKB2FV AbIJmMsDvkFl6a+dOy0BBus4anzd9EDqnlmCO9qtJ8sf2+fgOyIZdy1P3NZn6xR3TN cnibwIpA1T54ZTRndPDMRDy9UtHAfuU9mnM5dQ50= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Guangshuo Li , Leon Romanovsky , Sasha Levin Subject: [PATCH 5.15 768/776] RDMA/rtrs: Fix use-after-free in path file creation cleanup Date: Sat, 30 May 2026 18:08:02 +0200 Message-ID: <20260530160259.570798542@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260530160240.228940103@linuxfoundation.org> References: <20260530160240.228940103@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Guangshuo Li [ Upstream commit 5b74373390113fba798a76b483837029ab010fef ] In the error path of rtrs_srv_create_path_files(), the sysfs root folders may already have been created and srv_path->kobj may already have been initialized. If a later step fails, the cleanup currently calls kobject_put(&srv_path->kobj) before rtrs_srv_destroy_once_sysfs_root_folders(srv_path). kobject_put() may drop the last reference to srv_path->kobj and invoke the release callback, rtrs_srv_release(), which frees srv_path. The following call to rtrs_srv_destroy_once_sysfs_root_folders(srv_path) then dereferences srv_path internally to access srv_path->srv, resulting in a use-after-free. This failure path is reached before rtrs_srv_create_path_files() returns success, so the successful-path lifetime handling is not involved. Fix this by destroying the sysfs root folders before calling kobject_put(&srv_path->kobj), so srv_path is still valid while the helper accesses it. This issue was found by a static analysis tool I am developing. Fixes: ae4c81644e91 ("RDMA/rtrs-srv: Rename rtrs_srv_sess to rtrs_srv_path") Signed-off-by: Guangshuo Li Link: https://patch.msgid.link/20260514113834.865530-1-lgs201920130244@gmail.com Signed-off-by: Leon Romanovsky Signed-off-by: Sasha Levin --- drivers/infiniband/ulp/rtrs/rtrs-srv-sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/infiniband/ulp/rtrs/rtrs-srv-sysfs.c b/drivers/infiniband/ulp/rtrs/rtrs-srv-sysfs.c index 309080184aac7..d42659a2e9058 100644 --- a/drivers/infiniband/ulp/rtrs/rtrs-srv-sysfs.c +++ b/drivers/infiniband/ulp/rtrs/rtrs-srv-sysfs.c @@ -294,8 +294,8 @@ int rtrs_srv_create_path_files(struct rtrs_srv_path *srv_path) put_kobj: kobject_del(&srv_path->kobj); destroy_root: - kobject_put(&srv_path->kobj); rtrs_srv_destroy_once_sysfs_root_folders(srv_path); + kobject_put(&srv_path->kobj); return err; } -- 2.53.0