[PATCH net] ppp: serialize channel connect with unregister

From
Haoli Zhang <hidden>
Date
2026-11-16 12:28:24
Also in
lkml
ppp_unregister_channel() disconnects a channel before clearing pch->chan.
During that interval, a concurrent PPPIOCCONNECT can observe pch->ppp as
NULL while pch->chan is still valid. It can reconnect the channel and add
its clist to a PPP unit, after which unregistering releases the channel
without removing the new list entry.

Serialize PPPIOCCONNECT with channel unregistering using chan_sem. Take
the mutex before disconnecting the channel and hold it until pch->chan
is cleared. A connect already in progress completes before unregistering
disconnects the channel; a later connect waits until pch->chan is NULL and
is rejected by the existing check in ppp_connect_channel().

This preserves the disconnect-before-null ordering needed by the transmit
path. The change adds no locking to the packet fast path.

Fixes: 6a196e83a1a7 ("ppp: disconnect channel before nullifying pch->chan")
Reported-by: <redacted>
Closes: https://syzbot.org/bug?extid=6b18da3ef22e33061add
Co-developed-by: Jinning Zhang <redacted>
Signed-off-by: Jinning Zhang <redacted>
Co-developed-by: Bin Yu <redacted>
Signed-off-by: Bin Yu <redacted>
Signed-off-by: Haoli Zhang <redacted>

---
diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
--- a/drivers/net/ppp/ppp_generic.c
+++ b/drivers/net/ppp/ppp_generic.c
@@ -175,7 +175,7 @@
 	struct ppp_file	file;		/* stuff for read/write/poll */
 	struct list_head list;		/* link in all/new_channels list */
 	struct ppp_channel *chan;	/* public channel data structure */
-	struct mutex chan_sem;		/* protects `chan' during chan ioctl */
+	struct mutex chan_sem;		/* protects chan ioctl; serializes connect/unregister */
 	spinlock_t	downl;		/* protects `chan', file.xq dequeue */
 	struct ppp __rcu *ppp;		/* ppp unit we're connected to */
 	struct net	*chan_net;	/* the net channel belongs to */
@@ -755,7 +755,9 @@
 		case PPPIOCCONNECT:
 			if (get_user(unit, p))
 				break;
+			mutex_lock(&pch->chan_sem);
 			err = ppp_connect_channel(pch, unit);
+			mutex_unlock(&pch->chan_sem);
 			break;
 
 		case PPPIOCDISCONN:
@@ -3093,11 +3095,14 @@
 	chan->ppp = NULL;
 
 	/*
+	 * Prevent PPPIOCCONNECT from reattaching the channel during removal.
+	 */
+	mutex_lock(&pch->chan_sem);
+	/*
 	 * This ensures that we have returned from any calls into
 	 * the channel's start_xmit or ioctl routine before we proceed.
 	 */
 	ppp_disconnect_channel(pch);
-	mutex_lock(&pch->chan_sem);
 	spin_lock_bh(&pch->downl);
 	pch->chan = NULL;
 	spin_unlock_bh(&pch->downl);
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help