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 66E741AC8AE; Thu, 15 Aug 2024 13:47:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723729671; cv=none; b=IxY75oGUDfh4+ZN4XuhrhgM5qp+uC4qi8ZqvtXxp4V/2T/TiduX8PlUg8kul2k2+tCFN5TPvLKy6o9QWgdYOp3iUfSZnuMRWjsx4gExdjvcXJbjyOAHlGr01Ypa6j1yO+340DzjeL39NiDq+fG1YlzOffq2+gYi5zpiKg0Ka7m4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723729671; c=relaxed/simple; bh=GFASCDLnXE8cAChFlvg5vKAw7dZFp67ueAH1GQV2pPg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YLwpoTdlFOX+wkjEnIjGxjf9GrjqErag4Qci60st3lCLkafavM+DWImMEQ1jQgmGYalH4qY/iDioBqla0oNNzcJ6Fjx9OUyjiDzXsSaJ477y2ijQoa/Ec07gOlwx8pS7GOSCWzZvbG0L7yi4HVcpKHQFtj3Np75m22WmPPsPcpY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=f7xBayk/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="f7xBayk/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 802CDC32786; Thu, 15 Aug 2024 13:47:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1723729671; bh=GFASCDLnXE8cAChFlvg5vKAw7dZFp67ueAH1GQV2pPg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f7xBayk/vAXuegt5N7otOPH/zQlNnPf+E2u/Nibdqojb491IDdU7LMzWshcMg45wV ipxCbCIAFFBg+s7y7dCa2yVerLCEqUBCj3Qj+UyxsJLbcP+MXeDdTN956bbpZfEC2S Fzelvzfx31sIjIdYIErfDDpVnK5EEsiOH9yCq/xE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Breno Leitao , Eric Dumazet , Jakub Kicinski Subject: [PATCH 5.15 172/484] net: netconsole: Disable target before netpoll cleanup Date: Thu, 15 Aug 2024 15:20:30 +0200 Message-ID: <20240815131948.057995819@linuxfoundation.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240815131941.255804951@linuxfoundation.org> References: <20240815131941.255804951@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org 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: Breno Leitao commit 97d9fba9a812cada5484667a46e14a4c976ca330 upstream. Currently, netconsole cleans up the netpoll structure before disabling the target. This approach can lead to race conditions, as message senders (write_ext_msg() and write_msg()) check if the target is enabled before using netpoll. The sender can validate that the target is enabled, but, the netpoll might be de-allocated already, causing undesired behaviours. This patch reverses the order of operations: 1. Disable the target 2. Clean up the netpoll structure This change eliminates the potential race condition, ensuring that no messages are sent through a partially cleaned-up netpoll structure. Fixes: 2382b15bcc39 ("netconsole: take care of NETDEV_UNREGISTER event") Cc: stable@vger.kernel.org Signed-off-by: Breno Leitao Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20240712143415.1141039-1-leitao@debian.org Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/net/netconsole.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -716,6 +716,7 @@ restart: /* rtnl_lock already held * we might sleep in __netpoll_cleanup() */ + nt->enabled = false; spin_unlock_irqrestore(&target_list_lock, flags); __netpoll_cleanup(&nt->np); @@ -723,7 +724,6 @@ restart: spin_lock_irqsave(&target_list_lock, flags); dev_put(nt->np.dev); nt->np.dev = NULL; - nt->enabled = false; stopped = true; netconsole_target_put(nt); goto restart;