From: Breno Leitao <leitao@debian.org>
To: davem@davemloft.net, edumazet@google.com, pabeni@redhat.com,
Jakub Kicinski <kuba@kernel.org>
Cc: thepacketgeek@gmail.com, riel@surriel.com, horms@kernel.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net-next 3/3] net: netconsole: Disable target before netpoll cleanup
Date: Tue, 9 Jul 2024 07:44:01 -0700 [thread overview]
Message-ID: <20240709144403.544099-4-leitao@debian.org> (raw)
In-Reply-To: <20240709144403.544099-1-leitao@debian.org>
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.
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.
Signed-off-by: Breno Leitao <leitao@debian.org>
---
drivers/net/netconsole.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index 5ef680cf994a..9c09293b5258 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -973,6 +973,7 @@ static int netconsole_netdev_event(struct notifier_block *this,
/* rtnl_lock already held
* we might sleep in __netpoll_cleanup()
*/
+ nt->enabled = false;
spin_unlock_irqrestore(&target_list_lock, flags);
__netpoll_cleanup(&nt->np);
@@ -980,7 +981,6 @@ static int netconsole_netdev_event(struct notifier_block *this,
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;
--
2.43.0
next prev parent reply other threads:[~2024-07-09 14:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-09 14:43 [PATCH net-next 0/3] netconsole: Fix potential race condition and improve code clarity Breno Leitao
2024-07-09 14:43 ` [PATCH net-next 1/3] net: netconsole: Remove unnecessary cast from bool Breno Leitao
2024-07-09 14:44 ` [PATCH net-next 2/3] net: netconsole: Eliminate redundant setting of enabled field Breno Leitao
2024-07-09 14:44 ` Breno Leitao [this message]
2024-07-12 1:32 ` [PATCH net-next 3/3] net: netconsole: Disable target before netpoll cleanup Jakub Kicinski
2024-07-12 2:00 ` [PATCH net-next 0/3] netconsole: Fix potential race condition and improve code clarity patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240709144403.544099-4-leitao@debian.org \
--to=leitao@debian.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=riel@surriel.com \
--cc=thepacketgeek@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®