From: Paolo Abeni <pabeni@redhat.com>
To: Haoli Zhang <26031212468@stu.xidian.edu.cn>,
andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
kuba@kernel.org
Cc: linux-ppp@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org,
syzbot+6b18da3ef22e33061add@syzkaller.appspotmail.com,
25031212117@stu.xidian.edu.cn, byu@xidian.edu.cn
Subject: Re: [PATCH net v2] ppp: serialize channel operations with unregister
Date: Fri, 27 Nov 2026 09:46:07 +0100 [thread overview]
Message-ID: <a806ef26-fba7-4e36-a168-7b0b98bc0098@redhat.com> (raw)
In-Reply-To: <20261119084333.371234-1-26031212468@stu.xidian.edu.cn>
On 11/19/26 09:43, Haoli Zhang wrote:
> The channel unregister path disconnects a channel before clearing
> pch->chan. A concurrent PPPIOCCONNECT can observe pch->ppp as NULL while
> pch->chan is still valid and attach the channel again. Unregister can
> then clear pch->chan and release the channel while its clist remains
> linked to a PPP unit.
>
> Serialize PPPIOCCONNECT with unregister using chan_sem. Hold the mutex
> from before disconnecting the channel until it has been removed from the
> channel list and marked dead. An in-flight connect completes before
> unregister disconnects the channel; later connects see the cleared
> channel and fail.
>
> PPPIOCDISCONN must use the same mutex. An in-progress PPPIOCDISCONN can
> clear pch->ppp before it has removed pch->clist and completed
> synchronize_net(). Without the mutex, unregister can see pch->ppp as NULL
> and proceed before that disconnect has finished unlinking the channel and
> waiting for network readers. Taking chan_sem in both paths makes
> unregister wait for the disconnect to finish before clearing pch->chan.
>
> Bridge establishment must also be serialized with unregistering either
> endpoint. Hold both channels' chan_sem mutexes in a stable order while
> establishing the bridge, and reject channels that have been marked dead.
> Unregister holds its channel mutex through unbridging and marking the
> channel dead, so bridge establishment cannot pass the teardown step and
> leave a new bridge reference behind.
>
> The transmit fast path is unchanged. chan_sem drains channel ioctl
> callbacks. ppp_disconnect_channel() removes the channel from the PPP unit
> and waits for network readers before unregister clears pch->chan.
>
> 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>
> ---
> Changes in v2:
> - Serialize PPPIOCDISCONN with channel unregister.
> - Serialize bridge establishment with unregistering either endpoint.
> - Clarify the chan_sem comment and bridge lock ordering.
>
> drivers/net/ppp/ppp_generic.c | 55 ++++++++++++++++------
> 1 file changed, 40 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
> index 1a610a1..7b0bcac 100644
> --- a/drivers/net/ppp/ppp_generic.c
> +++ b/drivers/net/ppp/ppp_generic.c
> @@ -174,7 +174,7 @@ struct channel {
> 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 in ioctls; serializes with 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 */
> @@ -639,11 +639,30 @@ static struct bpf_prog *compat_ppp_get_filter(struct sock_fprog32 __user *p)
> */
> static int ppp_bridge_channels(struct channel *pch, struct channel *pchb)
> {
> + struct channel *first, *second, *bridge;
> + bool pch_first;
> + int ret = -EALREADY;
> +
> + if (pch == pchb)
> + return -EALREADY;
> +
> + /* Use a stable order to avoid deadlock with reverse bridge requests. */
> + pch_first = (unsigned long)pch < (unsigned long)pchb;
> + first = pch_first ? pch : pchb;
> + second = pch_first ? pchb : pch;
> + mutex_lock(&first->chan_sem);
> + mutex_lock_nested(&second->chan_sem, SINGLE_DEPTH_NESTING);
Sashiko noted that the above is defensive programming:
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119084333.371234-1-26031212468@stu.xidian.edu.cn
and we don't wan't it (especially not for locking!)
/P
prev parent reply other threads:[~2026-11-27 8:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 8:43 Haoli Zhang
2026-11-26 14:30 ` Simon Horman
2026-11-27 8:46 ` Paolo Abeni [this message]
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=a806ef26-fba7-4e36-a168-7b0b98bc0098@redhat.com \
--to=pabeni@redhat.com \
--cc=25031212117@stu.xidian.edu.cn \
--cc=26031212468@stu.xidian.edu.cn \
--cc=andrew+netdev@lunn.ch \
--cc=byu@xidian.edu.cn \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-ppp@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=syzbot+6b18da3ef22e33061add@syzkaller.appspotmail.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®