Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: nicolas.dichtel@6wind.com
Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
	edumazet@kernel.org, willemb@google.com, andrew+netdev@lunn.ch,
	jchapman@katalix.com, horms@kernel.org, qingfang.deng@linux.dev,
	netdev@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH net v3] pppox: drop queued packets on channel handoff
Date: Sat, 05 Dec 2026 17:54:42 +0000	[thread overview]
Message-ID: <179649328278.3146.6698236366190635617@kernel.org> (raw)
In-Reply-To: <20261201173520.3359805-1-nicolas.dichtel@6wind.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · Low: 0

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

- [Medium] A deferred purge callback from an earlier binding can empty
  the receive queue of a later, still-readable PPPoE connection.
- [Medium] `po->purge_pending` is the only signal that `po->purge_rcu`
  may be passed to call_rcu() again, but it is published without…

--

pppox: drop queued packets on channel handoff

This patch removes the synchronize_net() and the drain to ppp_input()
from PPPIOCGCHAN. In their place it takes a socket reference and queues
an RCU callback that purges the receive queue. If a purge from an
earlier binding is still pending, PPPIOCGCHAN waits for a grace period
and purges synchronously, and pppox_exit() now calls rcu_barrier().

> diff --git a/drivers/net/ppp/pppox.c b/drivers/net/ppp/pppox.c
> index a6f72c813bef9..605054013a34d 100644
> --- a/drivers/net/ppp/pppox.c
> +++ b/drivers/net/ppp/pppox.c
> @@ -64,6 +64,17 @@ EXPORT_SYMBOL(register_pppox_proto);
>  EXPORT_SYMBOL(unregister_pppox_proto);
>  EXPORT_SYMBOL(pppox_unbind_sock);
>  
> +static void pppox_purge_rcv_queue(struct rcu_head *head)
> +{
> +	struct pppox_sock *po = container_of(head, struct pppox_sock,
> +					     purge_rcu);
> +	struct sock *sk = &po->sk;
> +
> +	skb_queue_purge(&sk->sk_receive_queue);

[Severity: Medium]
Can this callback drop frames that belong to a later connection on the
same socket?

pppox_purge_rcv_queue() empties sk_receive_queue every time it runs. It
does not check whether the socket is still in the binding that queued
the callback. Consider this sequence:

1. connect(sid=A), then PPPIOCGCHAN. pppox_ioctl() sets PPPOX_BOUND and
   purge_pending = true, then calls call_rcu().

2. Before the callback runs, userspace calls connect(sid=0) and then
   connect(sid=B). A PADT or flush that sets PPPOX_DEAD before the
   reconnect works too. pppoe_connect() then does:

drivers/net/ppp/pppoe.c:pppoe_connect() {
    ...
	if (stage_session(po->pppoe_pa.sid)) {
		pppox_unbind_sock(sk);
		...
		synchronize_net();
		...
		sk->sk_state = PPPOX_NONE;
	}
    ...
		sk->sk_state = PPPOX_CONNECTED;
    ...
}

   pppoe_connect() never touches purge_rcu or purge_pending. Its
   synchronize_net() also does not wait for callbacks queued earlier to
   run. With CONFIG_RCU_LAZY, call_rcu() can wait several seconds before
   starting the grace period.

3. The new session is CONNECTED but not BOUND, so pppoe_rcv_core()
   queues its frames with sock_queue_rcv_skb(). pppoe_recvmsg() only
   returns -EIO for BOUND sockets, so userspace can read these frames.

4. The stale callback then runs and drops the new session's frames.

The purge_pending branch in pppox_ioctl() only helps when PPPIOCGCHAN
is issued a second time. It does nothing for the window between the
reconnect and the rebind.

The new comment says the purge is meant to "drop the packets queued
before the handoff". The commit message only describes the case where
the socket is "reconnected and bound again within a grace period".

Before this patch, the drain ran synchronously in the same PPPIOCGCHAN
that set PPPOX_BOUND, so it could not reach a later connection. Is it
intended that a pending purge can now empty the queue of a reconnected,
still readable session?

> +	WRITE_ONCE(po->purge_pending, false);

[Severity: Medium]
Is purge_pending ordered strongly enough to make reusing purge_rcu
safe?

rcu_do_batch() clears the callback pointer just before calling the
callback:

kernel/rcu/tree.c:rcu_do_batch() {
    ...
		f = rhp->func;
		debug_rcu_head_callback(rhp);
		WRITE_ONCE(rhp->func, (rcu_callback_t)0L);
		f(rhp);
    ...
}

When the queue is empty, skb_queue_purge() in pppox_purge_rcv_queue()
returns with no barrier at all. When it is not empty, the spin_lock and
spin_unlock pair does not order an earlier store before a later one. So
the func = 0 store and the purge_pending = false store are unordered.

The callback does not take lock_sock(). That means the socket lock held
in pppox_ioctl() does not serialize against it. On another CPU, a
PPPIOCGCHAN on a reconnected socket can run:

		if (READ_ONCE(po->purge_pending)) {
			...
		} else {
			WRITE_ONCE(po->purge_pending, true);
			sock_hold(sk);
			call_rcu(&po->purge_rcu, pppox_purge_rcv_queue);
		}

call_rcu() then writes head->func with a plain store in
rcu_do_enqueue().

On weakly ordered architectures such as arm64 or POWER, can the
func = 0 store from rcu_do_batch() become visible after the new
head->func store? That would leave a queued rcu_head with a NULL func,
and the next rcu_do_batch() would call it.

Hitting this needs a PPPIOCGCHAN, a reconnect through pppoe_connect(),
and a second PPPIOCGCHAN that races with the running callback on
another CPU. It cannot happen on x86.

Would one of these close the race?

  - smp_store_release() in the callback paired with smp_load_acquire()
    in pppox_ioctl()
  - test_and_set_bit_lock() paired with clear_bit_unlock()

> +	sock_put(sk);
> +}

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201173520.3359805-1-nicolas.dichtel%406wind.com

      reply	other threads:[~2026-12-05 17:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 17:34 [PATCH net v3] pppox: drop queued packets on channel handoff Nicolas Dichtel
2026-12-05 17:54 ` netdev-bot+sashiko [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=179649328278.3146.6698236366190635617@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=jchapman@katalix.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nicolas.dichtel@6wind.com \
    --cc=pabeni@redhat.com \
    --cc=qingfang.deng@linux.dev \
    --cc=stable@vger.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