From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796053598; b=v7axMdrc/ip8vwT84uItQFAK7XDHfw6hNcqAKvRz6XpHY0hRbUwebi7+QsMsitNfYUvC X9H5pIKv7+be3TVepFk0ESYbZZ//ynjUmws1lR6+08eRsvH/tqOIHwYjubLz8WfygHNji 1UAk8Z+XhWXs/8MyMhK9TuJ/Dyi5M4p02wgMakK4/h2t7fJNDeBrZklDEsQVvqA6dQQFx bba/iMucThyMQZGpwyPk2cv5mAPJSnayjuwgZ24Xu0gik3qf0eKdI/4VUtPsf1kYdOhOp AQjOnxGHkoDQi82Mtih7VyYllK3fmzAjsPhoT+0kwSb2l9DXxbJP4ZgMUV75/XFdoNA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796053598; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=gDdKiggkySBAFnnsDf69yNOmQ+ztJYO0Va1e67d+OvQ=; b=OLGzhK5TFU/1ea86qqTWvdiztZaw5vOSq6JQJQzwCX0F7pBQDa8BpSdYFae5of1QeiUF Fwq3NUyMpKCXrpvHMS8DipM5RJv2GdVPDcJ/zjjpqAuOtT+00nd6t5/ZqVnIIR2ERS+Da +3Sw13nNqazKXbHrbxbVlr7tpTIipDKuyK0NUnWZ8Pew2E7j/LwtT7R6I4CYb8JwUlyg8 eJGlm8Hsmjq4w59036rRsErrvzPiyhHQGDjo2xv6CZpgCYESSQkpu4MgnVpsMjhhiX+hl 4Wt7JjB+Ko4vmZixrUGt3verrXBIXAAsYZs+PtWjIt83C54nsf45MNCHbkDCwRynRBQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="NhVs/bFi"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECDAD606A31C; Mon, 30 Nov 2026 15:46:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NhVs/bFi Received: by smtp.kernel.org (Postfix) with ESMTPSA id D63AB1F000C1; Mon, 30 Nov 2026 15:46:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796053597; bh=gDdKiggkySBAFnnsDf69yNOmQ+ztJYO0Va1e67d+OvQ=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=NhVs/bFilKwxUP9eimAmQ4uIJV9M6CjQnvO/ekuxA2jQ3lzIPR5NdUWJBgd1UBLTW Lsm0Ri7mvru2Cbfi1Smqose4H4vIQqFsCchT9KW2oRSBrd0MPpW7HCWfZK1AHEPfwn pl2++44Xcd2CDGBsVsbub2BMVnU1vfQq7bqKuozXWEgk8LPxzuBeHrYdBRF7odgZDZ a/b88BmEfqhlM4OrVZNg6mMMq50wjgMrB7U01RkuMigJITotFAxMJ9bvxzf7jyEPhx 6q5VOlLPVvYRxga0dCM3hfjD58SAOVuNHhSj4SFNnq5c69dfw7PRaQk6uq6qT/ITJ3 hWn2mt9QkHoAA== Subject: Re: [PATCH net-next 1/3] ppp: transmit data frames without the unit and channel locks From: netdev-bot+sashiko@kernel.org To: julius@bairaktaris.de Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, willemb@google.com, horms@kernel.org, shuah@kernel.org, qingfang.deng@linux.dev, gnault@redhat.com, bigeasy@linutronix.de, 26031212468@stu.xidian.edu.cn, linux-ppp@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Date: Mon, 30 Nov 2026 15:46:36 +0000 Message-ID: <179605359638.3146.9210576638379871377@kernel.org> In-Reply-To: <20261129144319.1489366-2-julius@bairaktaris.de> References: <20261129144319.1489366-2-julius@bairaktaris.de> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider. Critical: 0 · High: 1 · Medium: 0 · Low: 3 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [High] ppp: race with ppp_unregister_channel() causes NULL deref and UAF in ppp_xmit_lockless() - [Low] Baseline decision: false positive, resolved later in the series. - [Low] When `ppp_set_compress()` (drivers/net/ppp/ppp_generic.c) installs a transmit compressor while `ostate` is NULL, it now always… - [Low] The channel API documentation was not updated for the new `lockless_xmit` contract, and this is still true at the end of the… -- ppp: transmit data frames without the unit and channel locks This adds ppp_xmit_lockless(). It sends data frames straight to the first channel under RCU, without ppp->wlock and pch->downl, as long as no multilink, compression, VJ, loopback, filter or backlog work applies. Channels opt in with a new lockless_xmit flag, and ppp_set_compress() now waits for a grace period after it installs the first transmit compressor. > diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c > index bd5a7630f297d..89a756ae3f4a2 100644 > --- a/drivers/net/ppp/ppp_generic.c > +++ b/drivers/net/ppp/ppp_generic.c [ ... ] > @@ -1660,8 +1660,73 @@ static void ppp_xmit_flush(struct ppp *ppp) [ ... ] > +static bool ppp_xmit_lockless(struct ppp *ppp, struct sk_buff *skb) > +{ [ ... ] > + rcu_read_lock(); > + pch = list_first_or_null_rcu(&ppp->channels, struct channel, clist); > + if (!pch) > + goto out; > + chan = pch->chan; > + if (!chan->lockless_xmit) > + goto out; > + > + skb->dev = dev; > + /* Do not dirty a cache line shared by all CPUs for every frame. */ > + if (READ_ONCE(ppp->last_xmit) != now) > + WRITE_ONCE(ppp->last_xmit, now); > + dev_sw_netstats_tx_add(dev, 1, skb->len - PPP_PROTO_LEN); > + > + if (unlikely(!chan->direct_xmit && skb_linearize(skb))) > + kfree_skb(skb); > + else if (WARN_ON_ONCE(!chan->ops->start_xmit(chan, skb))) > + kfree_skb(skb); [Severity: High] Can ppp_xmit_lockless() see a channel that ppp_unregister_channel() has already torn down? The lockless path reads pch->chan without downl and without a NULL check. It then dereferences chan->lockless_xmit and calls chan->ops->start_xmit(). The comment above the function says this is safe because the channel stays registered until ppp_disconnect_channel() has unlinked pch->clist and waited for a grace period. That only holds when the ppp_disconnect_channel() call made by ppp_unregister_channel() is the one that does the unlinking. PPPIOCDISCONN calls ppp_disconnect_channel() with ppp_mutex held, but ppp_unregister_channel() calls it without ppp_mutex, so the two can run at the same time: CPU0 (PPPIOCDISCONN) CPU1 (channel teardown) ppp_disconnect_channel() pch->ppp = NULL under upl ppp_unregister_channel() ppp_disconnect_channel() sees pch->ppp == NULL, returns pch->chan = NULL under downl returns, driver frees chan ppp_lock(ppp) list_del_rcu(&pch->clist) synchronize_net() Until CPU0 reaches list_del_rcu(), pch is still the first entry on ppp->channels. A sender on another CPU can then load pch->chan as NULL and oops on chan->lockless_xmit. A sender that loaded chan just before CPU1 cleared it can still be inside chan->ops->start_xmit() after the driver has freed the channel. Nothing waits for a grace period between pch->chan = NULL and the driver freeing chan. PPPIOCCONNECT has a similar window. If ppp_connect_channel() takes downl after ppp_unregister_channel() has returned from ppp_disconnect_channel() but before it clears pch->chan, it sees a non-NULL chan and links pch onto ppp->channels. pch->chan then goes to NULL while pch stays on the list. The locked path survives both, because ppp_push() checks pch->chan for NULL under downl and drops the frame. The new path doesn't take downl, so the same races now end in a NULL deref or a use-after-free. They are reachable from ordinary teardown, for example a PPPoE PADT or a socket close racing with pppd's PPPIOCDISCONN. A process with CAP_NET_ADMIN in a user namespace can also trigger them on purpose. Would it be enough to read pch->chan with READ_ONCE() and bail out on NULL here? ppp_unregister_channel() would then clear it with WRITE_ONCE() and wait for a grace period before it returns to the driver. Or would you rather serialise the two ppp_disconnect_channel() callers so that the existing synchronize_net() always runs before pch->chan is cleared? The second option would not cover the PPPIOCCONNECT case on its own. [Severity: Low] Should Documentation/networking/ppp_generic.rst and the start_xmit comment in include/linux/ppp_channel.h be updated for the new lockless_xmit contract? ppp_generic.rst still lists this as a guarantee of the generic layer: * The generic layer will not call the start_xmit() function for a channel while any thread is already executing in that function for that channel. It also says start_xmit() may return 0 for flow control, and that the generic layer will retry the frame after ppp_output_wakeup(). The struct ppp_channel_ops comment for start_xmit still says "Returns 1 if it was accepted, 0 if not". For channels that set lockless_xmit, ppp_xmit_lockless() calls start_xmit() from several CPUs at once without pch->downl. It can also run at the same time as ppp_push() and __ppp_channel_push(), which do hold downl. A 0 return here gives a WARN and drops the skb instead of queuing it. The downl comment in struct channel says it protects chan and the file.xq dequeue. That is now incomplete, because pch->chan is read here under RCU only. The only place the new rules are written down is the field comment "concurrent start_xmit, never 0". As far as I can tell, no Documentation/ files change anywhere in the series. > + ret = true; > +out: > + rcu_read_unlock(); > + return ret; > +} [ ... ] > @@ -3153,11 +3218,17 @@ ppp_set_compress(struct ppp *ppp, struct ppp_option_data *data) > ocomp = ppp->xcomp; > ostate = ppp->xc_state; > ppp->xcomp = cp; > - ppp->xc_state = state; > + WRITE_ONCE(ppp->xc_state, state); > ppp_xmit_unlock(ppp); > if (ostate) { > ocomp->comp_free(ostate); > module_put(ocomp->owner); > + } else { > + /* Compression can start with the next CCP > + * frame from pppd; let lockless senders that > + * saw no compressor finish first. > + */ > + synchronize_net(); > } [Severity: Low] Does this need to hold up every PPP ioctl on the system for a full grace period? ppp_ioctl() and ppp_compat_ioctl() call ppp_set_compress() with the global ppp_mutex held: ppp_ioctl() mutex_lock(&ppp_mutex); ... ppp_set_compress() synchronize_net(); This happens on the first transmit PPPIOCSCOMPRESS of a session and again after every ppp_ccp_closed(). While it runs, all other PPP ioctls on every unit in every namespace wait behind it. The wait only matters for units whose first channel sets lockless_xmit. pptp, l2tp, async and sync units pay for it too, even though they can never take the lockless path. Could the wait be skipped for those units? PPPIOCDISCONN already calls synchronize_net() under ppp_mutex through ppp_disconnect_channel(), and this one runs once per CCP negotiation, so the cost is modest. The commit message mentions the wait. It doesn't say that the wait runs under the global mutex or that every unit pays for it. [ ... ] > diff --git a/include/linux/ppp_channel.h b/include/linux/ppp_channel.h > index 15bc3aa4f1715..a0de060623a11 100644 > --- a/include/linux/ppp_channel.h > +++ b/include/linux/ppp_channel.h > @@ -44,6 +44,7 @@ struct ppp_channel { > int speed; /* transfer rate (bytes/second) */ > bool direct_xmit; /* no qdisc, xmit directly */ > bool xmit_offload; /* accepts GSO and CHECKSUM_PARTIAL skbs */ > + bool lockless_xmit; /* concurrent start_xmit, never 0 */ [Severity: Low] Nothing in this patch sets lockless_xmit. With this patch applied on its own, ppp_xmit_lockless() always takes the goto out after this check: if (!chan->lockless_xmit) goto out; So the new path is never used. The next patch in the series, "pppoe: transmit without the PPP channel lock", adds po->chan.lockless_xmit = true in pppoe_connect(), so this is resolved by the end of the series. pptp and l2tp intentionally don't opt in. Would it help to say in the commit message that the first user comes in the next patch? > }; > > #ifdef __KERNEL__ -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261129144319.1489366-1-julius%40bairaktaris.de