linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Martin Schiller <ms@dev.tdt.de>
To: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	linux-x25@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, Duoming Zhou <duoming@zju.edu.cn>,
	Lin Ma <linma@zju.edu.cn>,
	syzbot+9faa82ae2e94c5c7d2ef@syzkaller.appspotmail.com
Subject: Re: [PATCH net] net/x25: don't call lock_sock() from softirq in x25_kill_by_neigh()
Date: Mon, 23 Nov 2026 08:57:40 +0100 (CET)	[thread overview]
Message-ID: <mid:11> (raw)
In-Reply-To: <20261001150118.128470-1-ngocthang2710.1999@gmail.com>

Hi Thang,

On Thu, 01 Oct 2026 17:01:18 +0200, Nguyen Ngoc Thang wrote:
> Take the socket spinlock instead, the same way the x25 timers and 
> receive
> path already do. If the socket is not owned by user, disconnect it 
> right
> away. If it is, mark it with X25_KILL_FLAG and let a new release_cb do
> the disconnect when the owner releases the socket.

This is the approach I'd like to take, rather than deferring the whole
cleanup to a workqueue as proposed since. syzbot still hits the bug,
now also as https://syzkaller.appspot.com/bug?extid=300375dfd44665f063a6

The two new findings of the AI review hold up in practice. I tested
with two lapbether devices on a veth pair and a sender stalled in
x25_sendmsg() via userfaultfd, so that the socket is owned when the
link event arrives:

- after a RESTART, a CALL REQUEST on the old LCI is queued to the
   flagged socket's backlog and never reaches the listener;
- the flagged socket still transmits: a DATA packet on its old LCI
   after the restart, and after a LAPB disconnect it brings the link
   back up (SABM) before release_cb runs.

Skipping flagged sockets in __x25_find_socket() and returning early
from x25_kick() and x25_write_internal() for them fixes both. Those two
functions cover everything a socket transmits, and the deferred
x25_disconnect() only changes local state. Clearing the flag in
x25_make_new() takes care of the inheritance issue.

The x25_sendmsg()/x25_output() issue is pre-existing and independent;
I have a separate patch for it.

I have these changes on top of your patch, together with the separate
fix, and the series passes the tests above with lockdep and
DEBUG_ATOMIC_SLEEP. Unless you'd like to send the v2 yourself, I'll
post it in a few days, with you as the author of the main patch.

pw-bot: changes-requested

WARNING: multiple messages have this Message-ID (diff)
From: Martin Schiller <ms@dev.tdt.de>
To: Shuai Liu <847807867@qq.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>,
	linux-x25@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	syzbot+300375dfd44665f063a6@syzkaller.appspotmail.com
Subject: Re: [PATCH] x25: defer socket cleanup on link termination to process context
Date: Mon, 23 Nov 2026 09:03:49 +0100 (CET)	[thread overview]
Message-ID: mid:11
Message-ID: <20261123080349.ScmCLanF2bkBAAS6-tg5TvBoHycVT0Ql_ZS-45e_92s@z> (raw)
In-Reply-To: <tencent_8BA4FF587EE5579AB67149C5062618DC7109@qq.com>

Hi Shuai,

On Mon, 23 Nov 2026 04:47:48 +0100, Shuai Liu wrote:
> Changes in v3:
>   - Flush kill_work in NETDEV_CHANGE as well, restoring synchronous
>     socket cleanup for both process-context notifier events (Sashiko)

The NETDEV_CHANGE flush is fine, but I don't agree that the medium
issue from the review is not actionable, and I don't want to take the
workqueue approach.

In your reply to the review you wrote:
> The deferred work runs within microseconds of the event, long before
> the peer can deliver any new frame.

That only holds while no socket on the link is owned by a task. The
worker sleeps in lock_sock() until the owner releases the socket, which
is exactly the case in which the current code sleeps in softirq, and an
owner holds the socket for as long as its send buffer takes to fault
in. Until then, every call on the link keeps its LCI binding.

I tested v3 with two lapbether devices on a veth pair and a sender
stalled in x25_sendmsg() via userfaultfd, so that its socket is owned
when the link event arrives:

- after a LAPB disconnect, the stalled call itself brings the link back
   up (SABM) before it is cleared, so the peer can reach us again while
   the old calls are still bound;
- after a RESTART, a CALL REQUEST on the old LCI, sent two seconds after
   the restart was confirmed, never reaches the listener, and the old
   call sends a DATA packet on that LCI.

Neither involves frames that were in flight before the restart.

> Detaching the sockets synchronously in softirq would require writing
> x25->neighbour / lci / state from BH without lock_sock()

It doesn't. Thang's patch from October [1] uses the pattern that
x25_receive_data() and the x25 timers already use: under
bh_lock_sock(), a socket that is not owned is cleared right away, and an
owned one only gets an atomic flag and is cleared by its owner from
release_cb. Its v2 also skips flagged sockets in __x25_find_socket() and
keeps them from transmitting, which fixes both cases above in the same
test. I'll post it in the next days.

Also, please post new versions as a new thread, with the version in the
subject of the patch itself, not as a reply to the previous posting.

[1] 
https://lore.kernel.org/all/20261001150118.128470-1-ngocthang2710.1999@gmail.com/

pw-bot: changes-requested

  parent reply	other threads:[~2026-11-23  7:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-01 15:01 [PATCH net] net/x25: don't call lock_sock() from softirq in x25_kill_by_neigh() Nguyen Ngoc Thang
2026-10-05 15:20 ` netdev-bot+sashiko
2026-11-23  7:57 ` Martin Schiller [this message]
2026-11-23  8:03   ` [PATCH] x25: defer socket cleanup on link termination to process context Martin Schiller
  -- strict thread matches above, loose matches on Subject: below --
2026-10-11  0:03 [syzbot] [x25?] inconsistent lock state in x25_kill_by_neigh (2) syzbot
2026-10-14 11:14 ` Forwarded: " syzbot
2026-10-14 11:15 ` syzbot
2026-11-16  0:34 ` [PATCH] x25: defer socket cleanup on link termination to process context Shuai Liu
2026-11-18 18:35   ` netdev-bot+sashiko
2026-11-19  1:24     ` Shuai Liu
2026-11-23  1:40       ` netdev-bot+sashiko
2026-11-23  3:47         ` Shuai Liu

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='mid:11' \
    --to=ms@dev.tdt.de \
    --cc=davem@davemloft.net \
    --cc=duoming@zju.edu.cn \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linma@zju.edu.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-x25@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=ngocthang2710.1999@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=syzbot+9faa82ae2e94c5c7d2ef@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;
as well as URLs for NNTP newsgroup(s).