From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 11E911171B for ; Mon, 21 Aug 2023 20:01:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85528C433C9; Mon, 21 Aug 2023 20:01:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1692648071; bh=gWWTRAjBDLug2UH0WcXXyezQSq+Wp41igj5jfjS2gYk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=opiuNslnGG/VDGnwGRsC8B90ZEUzDBkD0K2DwoN/JeG66Bc4nbh6erKMWe0htf1FO zzmNgZ14kKY5+fzboTsAmuFt3bG4buNypWmGwzXQkyAi6E+f/S5WMLrtnAM/qO6d7b vTBqi31z1EPwLo0EofXme0+vnDdZdY8pvXeOHtvQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Winston Wen , Shyam Prasad N , Steve French , Sasha Levin Subject: [PATCH 6.4 045/234] cifs: fix session state check in reconnect to avoid use-after-free issue Date: Mon, 21 Aug 2023 21:40:08 +0200 Message-ID: <20230821194130.727467205@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230821194128.754601642@linuxfoundation.org> References: <20230821194128.754601642@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Winston Wen [ Upstream commit 99f280700b4cc02d5f141b8d15f8e9fad0418f65 ] Don't collect exiting session in smb2_reconnect_server(), because it will be released soon. Note that the exiting session will stay in server->smb_ses_list until it complete the cifs_free_ipc() and logoff() and then delete itself from the list. Signed-off-by: Winston Wen Reviewed-by: Shyam Prasad N Signed-off-by: Steve French Signed-off-by: Sasha Levin --- fs/smb/client/smb2pdu.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index 17fe212ab895d..e04766fe6f803 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -3797,6 +3797,12 @@ void smb2_reconnect_server(struct work_struct *work) spin_lock(&cifs_tcp_ses_lock); list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) { + spin_lock(&ses->ses_lock); + if (ses->ses_status == SES_EXITING) { + spin_unlock(&ses->ses_lock); + continue; + } + spin_unlock(&ses->ses_lock); tcon_selected = false; -- 2.40.1