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 D764F1A76A9; Tue, 30 Jul 2024 17:18:02 +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=1722359882; cv=none; b=HO2T4FfbEceNOKMPVPWIqDOeeMrZ8ZwwB4olZ9xQ4f1UYTySNsZDNnmLXBSmQhwEihNifdoqslPXV5CiJ25jG7WAVl/YeB4NfB36iBd6ifM2swW5g45iWsWdl/8r/twgi4RvPxvwu1EEvrti2+66jm/uEWJgVCWa9dEYWlz1yNI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722359882; c=relaxed/simple; bh=NVVIHub+ywa76zK9jkNt8aHGHNCykl6or+53Ymsj7gQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WATzKzV5AZAGCy+zLgsGKx/ZkQgTXAYVVKZLN3F4+81hJ0/CFanN+USiBvuOSzOLavLqmBOWH0kC+gK55rhCm6KQ9BVlT19AUMvaLY4rZWsmze9D0zqty8GLzLw5WiHdwXDZNHU0bfVLkcteBPY60cNAuYxvvvBS6myW2J9PFc0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=oXlJTfsA; 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="oXlJTfsA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42F66C4AF0A; Tue, 30 Jul 2024 17:18:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1722359882; bh=NVVIHub+ywa76zK9jkNt8aHGHNCykl6or+53Ymsj7gQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oXlJTfsAGcrgIQB2JdnW3hZ3LYiPSjIZDNM1/H/LtWXFzbxBkz6b+qLY01piZRbrj qw0Ai77lWhwlz9HaodMpFDCFffXZsx9P2XIlNQY4ovItAtqXoT3HAoSnxV1Xt2A7OJ wB5fV4vupnWbM6DEitETvYqI28Q4hd2vPqDY20A0= 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 6.10 549/809] net: netconsole: Disable target before netpoll cleanup Date: Tue, 30 Jul 2024 17:47:05 +0200 Message-ID: <20240730151746.438903487@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240730151724.637682316@linuxfoundation.org> References: <20240730151724.637682316@linuxfoundation.org> User-Agent: quilt/0.67 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 6.10-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 @@ -974,6 +974,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); @@ -981,7 +982,6 @@ restart: spin_lock_irqsave(&target_list_lock, flags); netdev_put(nt->np.dev, &nt->np.dev_tracker); nt->np.dev = NULL; - nt->enabled = false; stopped = true; netconsole_target_put(nt); goto restart;