Skip to contentSkip to conversation

netconsole configfs target release NULL dereference

PATCH In review David Lee 2 participants 2 messages Jul 17

Subsystems (3)
lore
Share & tools
lore

David Lee

author
#0 lore raw

PATCH 1/1 netconsole configfs target release NULL dereference

configfs target release can call netpoll cleanup with missing netpoll state.

Mark targets as disabled before releasing their netpoll state and skip cleanup when no netpoll device is present. This prevents teardown races from reaching netpoll cleanup after nt->np.dev has already been cleared.

Fixes 97714695ef90 ("net: netconsole: Defer netpoll cleanup to avoid lock release during list traversal")
Assisted-by Codex:gpt-5.5

---

drivers/net/netconsole.c | 10 +++++++---

 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/net/netconsole.c +7 -3
index 862001d..ad30e2e 100644
@@ -287,6 +287,8 @@ static bool bound_by_mac(struct netconsole_target *nt)
 
 static void netcons_release_dev(struct netconsole_target *nt)
 {
+	if (!nt->np.dev)
+		return;
 	do_netpoll_cleanup(&nt->np);
 	if (bound_by_mac(nt))
 		memset(&nt->np.dev_name, 0, IFNAMSIZ);
@@ -1490,10 +1492,12 @@ static void drop_netconsole_target(struct config_group *group,
 	 */
 	needs_cleanup = nt->state == STATE_ENABLED ||
 			nt->state == STATE_DEACTIVATED;
-	/* Disable deactivated target to prevent races between resume attempt
-	 * and target removal.
+	/* Disable targets that still own netpoll state before removal. This
+	 * prevents races between open configfs writers, resume attempts, and
+	 * target removal from observing STATE_ENABLED after netpoll_cleanup()
+	 * has cleared nt->np.dev.
 	 */
-	if (nt->state == STATE_DEACTIVATED)
+	if (needs_cleanup)
 		nt->state = STATE_DISABLED;
 	list_del(&nt->list);
 	spin_unlock_irqrestore(&target_list_lock, flags);
maintainer
#1 lore raw

Hello David,

Quoted 19 lines · David Lee

configfs target release can call netpoll cleanup with missing netpoll state.

Mark targets as disabled before releasing their netpoll state and skip cleanup when no netpoll device is present. This prevents teardown races from reaching netpoll cleanup after nt->np.dev has already been cleared.

Fixes 97714695ef90 ("net: netconsole: Defer netpoll cleanup to avoid lock release during list traversal")
Assisted-by Codex:gpt-5.5

---

drivers/net/netconsole.c | 10 +++++++---

 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/net/netconsole.c +0 -0
index 862001d..ad30e2e 100644

drivers/net/netconsole.c static bool bound_by_mac(struct netconsole_target *nt) · line 291

Quoted 5 lines
drivers/net/netconsole.c +2 -0
@@ -287,6 +287,8 @@ static bool bound_by_mac(struct netconsole_target *nt)
 
 static void netcons_release_dev(struct netconsole_target *nt)
 {
+	if (!nt->np.dev)
+		return;

I am not sure we get here with nt->np.dev unset, otherwise it will panic in the next lines:

netcons_release_dev() calls do_netpoll_cleanup(), which calls calls __netpoll_cleanup() which dereferences dev, as in:

	static void __netpoll_cleanup(struct netpoll *np)
		...
		npinfo = rtnl_dereference(np->dev->npinfo);

Are you hitting this NULL pointer dereference, thus, we need the early return above?

Thanks for the patch,
--breno