Netdev List
 help / color / mirror / Atom feed
* [PATCH net] ppp: serialize channel connect with unregister
@ 2026-11-16 12:27 Haoli Zhang
  2026-11-19  3:28 ` netdev-bot+sashiko
  0 siblings, 1 reply; 2+ messages in thread
From: Haoli Zhang @ 2026-11-16 12:27 UTC (permalink / raw)
  To: andrew+netdev, davem, edumazet, kuba, pabeni
  Cc: linux-ppp, netdev, linux-kernel, syzbot+6b18da3ef22e33061add,
	qingfang.deng, 25031212117, byu, Haoli Zhang

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: syzbot+6b18da3ef22e33061add@syzkaller.appspotmail.com
Closes: https://syzbot.org/bug?extid=6b18da3ef22e33061add
Co-developed-by: Jinning Zhang <25031212117@stu.xidian.edu.cn>
Signed-off-by: Jinning Zhang <25031212117@stu.xidian.edu.cn>
Co-developed-by: Bin Yu <byu@xidian.edu.cn>
Signed-off-by: Bin Yu <byu@xidian.edu.cn>
Signed-off-by: Haoli Zhang <26031212468@stu.xidian.edu.cn>

---

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);


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-19  3:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 12:27 [PATCH net] ppp: serialize channel connect with unregister Haoli Zhang
2026-11-19  3:28 ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox