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 1CA001A6195; Tue, 30 Jul 2024 16:55:08 +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=1722358509; cv=none; b=JjXmPqU9u1LYUonYMso1+Il6O/fMgrMcZG0d+bExBIdHTKjQdBd9EJmJfQxxui/wJRNMB2kO9FVYlRnQ7NOIguq531dTjsBXe+k8Hh+NxRTHLAoao6YvU9x0Xy+umm5oIDprbrgOBywr/AWPGub/kzUckDkHCTAim6nGd28DaKg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722358509; c=relaxed/simple; bh=8TueQuDdOnik5oZfzL0bDZOR2M4W6h40AHXuS1uWkWc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n69duGhwzYMnt/zOLaKnv6axHD1sv2VKC/HwolU5nRabtULguiN0hicBfTMNv89eB3++CU0gGdi61toRjvogjziV6P5dDL72EPC725la7FQDWF3cioSun8RqQpt7E5eGvG04YH8wS0bz1mG3gO4dG7SdRD9fbqpM8XEIIZHAgHY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Ur4rvmyo; 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="Ur4rvmyo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 109CBC32782; Tue, 30 Jul 2024 16:55:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1722358508; bh=8TueQuDdOnik5oZfzL0bDZOR2M4W6h40AHXuS1uWkWc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ur4rvmyoz9NzpW45pVadXvHSxMyGon+eUstfPqndkzmfdh2SpPa4SzMno0lUELxFH mglTsB8JadebdajkIantLIrneFbQQa/BvfpOI5F2y2huCoYWpDkaKv7/Bcj5ps4WUY ho+Xs/bK2vPovpHBw3GJFRJMEQOFntm30RO5zWp4= 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.6 368/568] net: netconsole: Disable target before netpoll cleanup Date: Tue, 30 Jul 2024 17:47:55 +0200 Message-ID: <20240730151654.244653008@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240730151639.792277039@linuxfoundation.org> References: <20240730151639.792277039@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.6-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 @@ -770,6 +770,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); @@ -777,7 +778,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;