mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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
Subject: Re: [PATCH net-next 1/3] ppp: transmit data frames without the unit and channel locks
Date: Mon, 30 Nov 2026 15:46:36 +0000	[thread overview]
Message-ID: <179605359638.3146.9210576638379871377@kernel.org> (raw)
In-Reply-To: <20261129144319.1489366-2-julius@bairaktaris.de>

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

  reply	other threads:[~2026-11-30 15:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 14:43 [PATCH net-next 0/3] " Julius Bairaktaris
2026-11-29 14:43 ` [PATCH net-next 1/3] " Julius Bairaktaris
2026-11-30 15:46   ` netdev-bot+sashiko [this message]
2026-11-29 14:43 ` [PATCH net-next 2/3] pppoe: transmit without the PPP channel lock Julius Bairaktaris
2026-11-30 15:46   ` netdev-bot+sashiko
2026-11-29 14:43 ` [PATCH net-next 3/3] selftests: net: ppp: send on PPPoE from every CPU at once Julius Bairaktaris
2026-11-30 15:46   ` netdev-bot+sashiko

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=179605359638.3146.9210576638379871377@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=26031212468@stu.xidian.edu.cn \
    --cc=andrew+netdev@lunn.ch \
    --cc=bigeasy@linutronix.de \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=gnault@redhat.com \
    --cc=horms@kernel.org \
    --cc=julius@bairaktaris.de \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-ppp@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=qingfang.deng@linux.dev \
    --cc=shuah@kernel.org \
    --cc=willemb@google.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®