mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net v2 0/2] net/x25: don't call lock_sock() from softirq in x25_kill_by_neigh()
@ 2026-11-27  6:28 Martin Schiller
  2026-11-27  6:28 ` [PATCH net v2 1/2] " Martin Schiller
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Martin Schiller @ 2026-11-27  6:28 UTC (permalink / raw)
  To: Martin Schiller, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Willem de Bruijn, Simon Horman, Lin Ma,
	Duoming Zhou, Xiyu Yang, Xin Tan
  Cc: linux-x25, netdev, Nguyen Ngoc Thang, Shuai Liu,
	Krystian Kaniewski, syzbot+300375dfd44665f063a6,
	syzbot+9faa82ae2e94c5c7d2ef, linux-kernel

x25_kill_by_neigh() takes lock_sock() on all sockets of a neighbour,
but it also runs in softirq context when the link layer reports a
disconnect or the peer restarts the link. syzbot hits this on mainline,
net, net-next and the LTS trees. A plain "ip link set lapb0 down" with a
connected peer is enough: LAPB sends a DISC, and the peer clears its
calls from softirq.

Patch 1 is v2 of Nguyen Ngoc Thang's fix [1]. Sockets that are not
owned are cleared right away under the socket spinlock, owned sockets
are flagged and cleared from a new release_cb, and NETDEV_DOWN still
waits for owners. v2 addresses the AI review of v1 [2]: a flagged
socket no longer matches incoming frames and no longer transmits, so a
new call on its LCI after a restart reaches the listener, and child
sockets do not inherit the flag.

Patch 2 fixes a pre-existing NULL pointer dereference in x25_sendmsg(),
x25_output() and x25_recvmsg() after they retake the socket lock. The
same review pointed out the first two, Krystian Kaniewski found the
x25_recvmsg() case. It is independent of patch 1.

Deferring the whole cleanup to a workqueue [3][4] also avoids the
splat, but the restart is then confirmed while the old calls are still
bound to their LCIs. [5] had the same design as v1. Both have been
withdrawn in favour of this series.

Tested in QEMU (single CPU) with lockdep and DEBUG_ATOMIC_SLEEP, using
two lapbether devices on a veth pair. A sender stalled in x25_sendmsg()
via userfaultfd keeps the calling socket owned during the link event:

                                       unpatched  v1    v2    wq [4]
  1  link loss, calls idle             splat      ok    ok    ok
  2  link loss, caller owned           -          FAIL  ok    FAIL
  3  restart, caller owned, then a
     CALL REQUEST on the caller's LCI  -          FAIL  ok    FAIL
  4  ip link set lapb0 down            splat      ok    ok    ok

In test 2, the old call brings the link back up (SABM) before it is
cleared. In test 3, the new call does not reach the listener, and the
old call sends a DATA packet on the reused LCI.

Tests 2 and 3 were not run unpatched, as that kernel would sleep in
softirq. v1 was also tested by Thang with the PREEMPT_RT config and the
C reproducer of [6]; the changes in v2 add no locking.

Changes in v2:
- skip flagged sockets in __x25_find_socket()
- no transmission from flagged sockets in x25_kick() and
  x25_write_internal()
- clear the flag in x25_make_new()
- add the current syzbot report
- new patch 2

The changes on top of v1, patch 2 and the tests were prepared with the
help of an AI assistant (Claude, Anthropic).

[1] https://lore.kernel.org/all/20261001150118.128470-1-ngocthang2710.1999@gmail.com/
[2] https://lore.kernel.org/all/179121364205.434549.10310203820251738113@kernel.org/
[3] https://lore.kernel.org/all/tencent_F7C2DC0FA42B5866E5C39A9E70D3C52C2609@qq.com/
[4] https://lore.kernel.org/all/tencent_8BA4FF587EE5579AB67149C5062618DC7109@qq.com/
[5] https://lore.kernel.org/all/00f667e3-a158-4fb5-84a3-9ecda4718ce8@mail.kernel.org/
[6] https://lore.kernel.org/all/6aa7e6d0.4c28b7d0.c1bba.001c.GAE@google.com/

---
Martin Schiller (1):
      net/x25: re-check x25->neighbour after re-acquiring the socket lock

Nguyen Ngoc Thang (1):
      net/x25: don't call lock_sock() from softirq in x25_kill_by_neigh()

 include/net/x25.h  |  1 +
 net/x25/af_x25.c   | 76 +++++++++++++++++++++++++++++++++++++++++++++++++-----
 net/x25/x25_out.c  |  9 ++++++-
 net/x25/x25_subr.c |  4 +++
 4 files changed, 82 insertions(+), 8 deletions(-)
---
base-commit: c5de2ce2fccdb7d3b48946179634eaa3d7ce2e7e
change-id: 20261124-x25-kill-by-neigh-2b70f6d19961

Best regards,
-- 
Martin Schiller <ms@dev.tdt.de>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net v2 1/2] net/x25: don't call lock_sock() from softirq in x25_kill_by_neigh()
  2026-11-27  6:28 [PATCH net v2 0/2] net/x25: don't call lock_sock() from softirq in x25_kill_by_neigh() Martin Schiller
@ 2026-11-27  6:28 ` Martin Schiller
  2026-11-27  6:28 ` [PATCH net v2 2/2] net/x25: re-check x25->neighbour after re-acquiring the socket lock Martin Schiller
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Martin Schiller @ 2026-11-27  6:28 UTC (permalink / raw)
  To: Martin Schiller, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Willem de Bruijn, Simon Horman, Lin Ma,
	Duoming Zhou, Xiyu Yang, Xin Tan
  Cc: linux-x25, netdev, Nguyen Ngoc Thang, Shuai Liu,
	Krystian Kaniewski, syzbot+300375dfd44665f063a6,
	syzbot+9faa82ae2e94c5c7d2ef, linux-kernel

From: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>

x25_kill_by_neigh() is reached from the receive path when the link layer
goes away or the peer restarts:

  net_rx_action()
    lapbeth_napi_poll()
      x25_lapb_receive_frame()
        x25_link_terminated() / x25_link_control()
          x25_kill_by_neigh()
            lock_sock()

lock_sock() may sleep, which is not allowed in softirq context:

  BUG: sleeping function called from invalid context at net/core/sock.c:3832
  in_atomic(): 0, irqs_disabled(): 0, non_block: 0, pid: 29, name: ktimers/1
  RCU nest depth: 2, expected: 0
  ...
   lock_sock_nested+0x56/0x130 net/core/sock.c:3832
   x25_kill_by_neigh+0x134/0x2a0 net/x25/af_x25.c:1778
   x25_lapb_receive_frame+0x1b0/0xfb0 net/x25/x25_dev.c:138

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 keeps the
serialization against x25_sendmsg()/x25_recvmsg()/x25_connect() that
commit 7781607938c8 ("net/x25: Fix null-ptr-deref caused by
x25_disconnect") added lock_sock() for. Sockets that already have the
flag set are skipped, so the rescan loop always terminates.

NETDEV_DOWN runs in process context and the device may be freed right
after, so keep waiting for socket owners there as before: a sleeping
sweep makes sure no socket still uses the neighbour on return.

Until its owner releases it, a flagged socket still holds the LCI of a
call that no longer exists, while x25_link_control() may already have
confirmed the restart and the peer may reuse that LCI. Skip flagged
sockets in __x25_find_socket(), so that frames for a reused LCI no
longer end up in the old socket's backlog, and keep flagged sockets from
transmitting in x25_kick() and x25_write_internal(). The deferred
x25_disconnect() only changes local state, so the old call is gone on
the wire before the restart is answered, as it was before.

x25_connect() accepts a listening socket, so a listener can carry the
flag. Clear it in x25_make_new(), which copies the listener's flags.

Fixes: 7781607938c8 ("net/x25: Fix null-ptr-deref caused by x25_disconnect")
Reported-by: syzbot+9faa82ae2e94c5c7d2ef@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=9faa82ae2e94c5c7d2ef
Reported-by: syzbot+300375dfd44665f063a6@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=300375dfd44665f063a6
Signed-off-by: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
[ms: hide flagged sockets from __x25_find_socket() and from
 transmission, clear the flag in x25_make_new(), add the current
 syzbot report]
Signed-off-by: Martin Schiller <ms@dev.tdt.de>
---
 include/net/x25.h  |  1 +
 net/x25/af_x25.c   | 66 +++++++++++++++++++++++++++++++++++++++++++++++++-----
 net/x25/x25_out.c  |  3 ++-
 net/x25/x25_subr.c |  4 ++++
 4 files changed, 67 insertions(+), 7 deletions(-)

diff --git a/include/net/x25.h b/include/net/x25.h
index 414f3fd99345455dd30f0cc827736fbce61fd99a..ed8ba01fa3cb396f80344a23f4de8d23d5e4a010 100644
--- a/include/net/x25.h
+++ b/include/net/x25.h
@@ -118,6 +118,7 @@ enum {
 #define X25_Q_BIT_FLAG		0
 #define X25_INTERRUPT_FLAG	1
 #define X25_ACCPT_APPRV_FLAG	2
+#define X25_KILL_FLAG		3
 
 /**
  *	struct x25_route - x25 routing entry
diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c
index f45c9ec7d2c68354838b1bfa34ea4ca08120dc8d..a5d3a86918a0f4f337af4566dde4b43a907d1b49 100644
--- a/net/x25/af_x25.c
+++ b/net/x25/af_x25.c
@@ -200,6 +200,32 @@ static void x25_remove_socket(struct sock *sk)
 	write_unlock_bh(&x25_list_lock);
 }
 
+/*
+ * Process context only: wait for owners that x25_kill_by_neigh() deferred,
+ * so no socket still uses nb once the device goes away.
+ */
+static void x25_kill_by_neigh_sync(struct x25_neigh *nb)
+{
+	struct sock *s;
+
+again:
+	write_lock_bh(&x25_list_lock);
+
+	sk_for_each(s, &x25_list) {
+		if (x25_sk(s)->neighbour == nb) {
+			sock_hold(s);
+			write_unlock_bh(&x25_list_lock);
+			lock_sock(s);
+			if (x25_sk(s)->neighbour == nb)
+				x25_disconnect(s, ENETUNREACH, 0, 0);
+			release_sock(s);
+			sock_put(s);
+			goto again;
+		}
+	}
+	write_unlock_bh(&x25_list_lock);
+}
+
 /*
  *	Handle device status changes.
  */
@@ -222,6 +248,7 @@ static int x25_device_event(struct notifier_block *this, unsigned long event,
 			nb = x25_get_neigh(dev);
 			if (nb) {
 				x25_link_terminated(nb);
+				x25_kill_by_neigh_sync(nb);
 				x25_neigh_put(nb);
 			}
 			x25_route_device_down(dev);
@@ -311,7 +338,8 @@ static struct sock *__x25_find_socket(unsigned int lci, struct x25_neigh *nb)
 	struct sock *s;
 
 	sk_for_each(s, &x25_list)
-		if (x25_sk(s)->lci == lci && x25_sk(s)->neighbour == nb) {
+		if (x25_sk(s)->lci == lci && x25_sk(s)->neighbour == nb &&
+		    !test_bit(X25_KILL_FLAG, &x25_sk(s)->flags)) {
 			sock_hold(s);
 			goto found;
 		}
@@ -492,10 +520,20 @@ static int x25_listen(struct socket *sock, int backlog)
 	return rc;
 }
 
+/* Finish a link teardown that hit while the socket was owned by user. */
+static void x25_release_cb(struct sock *sk)
+{
+	struct x25_sock *x25 = x25_sk(sk);
+
+	if (test_and_clear_bit(X25_KILL_FLAG, &x25->flags) && x25->neighbour)
+		x25_disconnect(sk, ENETUNREACH, 0, 0);
+}
+
 static struct proto x25_proto = {
 	.name	  = "X25",
 	.owner	  = THIS_MODULE,
 	.obj_size = sizeof(struct x25_sock),
+	.release_cb = x25_release_cb,
 };
 
 static struct sock *x25_alloc_socket(struct net *net, int kern)
@@ -610,6 +648,7 @@ static struct sock *x25_make_new(struct sock *osk)
 	x25->cudmatchlength = ox25->cudmatchlength;
 
 	clear_bit(X25_INTERRUPT_FLAG, &x25->flags);
+	clear_bit(X25_KILL_FLAG, &x25->flags);
 	x25_init_timers(sk);
 out:
 	return sk;
@@ -1761,6 +1800,23 @@ static struct notifier_block x25_dev_notifier = {
 	.notifier_call = x25_device_event,
 };
 
+/* May run in softirq, so lock_sock() is not an option. */
+static void x25_kill_sock(struct sock *sk, struct x25_neigh *nb)
+{
+	struct x25_sock *x25 = x25_sk(sk);
+
+	local_bh_disable();
+	bh_lock_sock(sk);
+	if (x25->neighbour == nb) {
+		if (sock_owned_by_user(sk))
+			set_bit(X25_KILL_FLAG, &x25->flags);
+		else
+			x25_disconnect(sk, ENETUNREACH, 0, 0);
+	}
+	bh_unlock_sock(sk);
+	local_bh_enable();
+}
+
 void x25_kill_by_neigh(struct x25_neigh *nb)
 {
 	struct sock *s;
@@ -1769,13 +1825,11 @@ void x25_kill_by_neigh(struct x25_neigh *nb)
 	write_lock_bh(&x25_list_lock);
 
 	sk_for_each(s, &x25_list) {
-		if (x25_sk(s)->neighbour == nb) {
+		if (x25_sk(s)->neighbour == nb &&
+		    !test_bit(X25_KILL_FLAG, &x25_sk(s)->flags)) {
 			sock_hold(s);
 			write_unlock_bh(&x25_list_lock);
-			lock_sock(s);
-			if (x25_sk(s)->neighbour == nb)
-				x25_disconnect(s, ENETUNREACH, 0, 0);
-			release_sock(s);
+			x25_kill_sock(s, nb);
 			sock_put(s);
 			goto again;
 		}
diff --git a/net/x25/x25_out.c b/net/x25/x25_out.c
index f8922b0e23a4f17c1f5f74aa24806a35325e92dd..f710d015fcc2ffd6a6922a0c29876bb248125666 100644
--- a/net/x25/x25_out.c
+++ b/net/x25/x25_out.c
@@ -140,7 +140,8 @@ void x25_kick(struct sock *sk)
 	int modulus;
 	struct x25_sock *x25 = x25_sk(sk);
 
-	if (x25->state != X25_STATE_3)
+	if (x25->state != X25_STATE_3 ||
+	    test_bit(X25_KILL_FLAG, &x25->flags))
 		return;
 
 	/*
diff --git a/net/x25/x25_subr.c b/net/x25/x25_subr.c
index 159708d9ad20cb2e6db24ead67daf1e9d6258f64..dba3b8eb10b0f21402592fe5775e1670f68ed4ee 100644
--- a/net/x25/x25_subr.c
+++ b/net/x25/x25_subr.c
@@ -120,6 +120,10 @@ void x25_write_internal(struct sock *sk, int frametype)
 	 */
 	int len = X25_MAX_L2_LEN + X25_EXT_MIN_LEN;
 
+	/* The call has already been cleared by a link failure or restart */
+	if (test_bit(X25_KILL_FLAG, &x25->flags))
+		return;
+
 	/*
 	 *	Adjust frame size.
 	 */

-- 
2.47.3


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net v2 2/2] net/x25: re-check x25->neighbour after re-acquiring the socket lock
  2026-11-27  6:28 [PATCH net v2 0/2] net/x25: don't call lock_sock() from softirq in x25_kill_by_neigh() Martin Schiller
  2026-11-27  6:28 ` [PATCH net v2 1/2] " Martin Schiller
@ 2026-11-27  6:28 ` Martin Schiller
  2026-11-27  6:33 ` [PATCH net v2 0/2] net/x25: don't call lock_sock() from softirq in x25_kill_by_neigh() netdev-bot+sinfo
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Martin Schiller @ 2026-11-27  6:28 UTC (permalink / raw)
  To: Martin Schiller, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Willem de Bruijn, Simon Horman, Lin Ma,
	Duoming Zhou, Xiyu Yang, Xin Tan
  Cc: linux-x25, netdev, Nguyen Ngoc Thang, Shuai Liu,
	Krystian Kaniewski, syzbot+300375dfd44665f063a6,
	syzbot+9faa82ae2e94c5c7d2ef, linux-kernel

x25_sendmsg(), x25_output() and x25_recvmsg() release the socket lock
while they wait for memory or data, and use x25->neighbour once they
own the socket again. The call may have been cleared in the meantime:
x25_disconnect() drops the neighbour reference and sets x25->neighbour
to NULL, for example when a CLEAR REQUEST from the peer or a link
failure is processed in softirq context while the socket is not owned.

sock_alloc_send_skb() only notices this if the disconnect happened
before its error checks. A disconnect during the allocation, or before
lock_sock() returns, leads to a NULL pointer dereference when
x25_sendmsg() builds the packet header or in the fragmentation loop of
x25_output(). In x25_recvmsg(), x25_disconnect() leaves x25->condition
alone, so if the receiver was busy, x25_check_rbuf() sends an RR
through x25_write_internal(), which dereferences x25->neighbour too.

Re-check x25->neighbour after lock_sock(): fail with -ENOTCONN in
x25_sendmsg() and x25_output(), and skip x25_check_rbuf() in
x25_recvmsg(), which still returns the data it has dequeued. Fragments
already queued by x25_output() have been purged by x25_disconnect() at
that point.

The x25_sendmsg() and x25_output() cases were also pointed out by the
netdev AI review of an earlier version of the x25_kill_by_neigh() fix.
Krystian Kaniewski found the x25_recvmsg() case by code inspection.

Fixes: 4becb7ee5b3d ("net/x25: Fix x25_neigh refcnt leak when x25 disconnect")
Reported-by: Krystian Kaniewski <krystianmkaniewski@gmail.com>
Closes: https://lore.kernel.org/all/02419845-bab8-4e36-9a98-6830761da1b9@gmail.com/
Link: https://lore.kernel.org/all/179121364205.434549.10310203820251738113@kernel.org/
Signed-off-by: Martin Schiller <ms@dev.tdt.de>
---
 net/x25/af_x25.c  | 10 +++++++++-
 net/x25/x25_out.c |  6 ++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c
index a5d3a86918a0f4f337af4566dde4b43a907d1b49..ce22fd657caa911ab79ba510df29ccd1185ce25d 100644
--- a/net/x25/af_x25.c
+++ b/net/x25/af_x25.c
@@ -1212,6 +1212,12 @@ static int x25_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
 	lock_sock(sk);
 	if (!skb)
 		goto out;
+
+	/* The call may have been cleared while the socket was unlocked */
+	rc = -ENOTCONN;
+	if (!x25->neighbour)
+		goto out_kfree_skb;
+
 	X25_SKB_CB(skb)->flags = msg->msg_flags;
 
 	skb_reserve(skb, X25_MAX_L2_LEN + X25_EXT_MIN_LEN);
@@ -1397,7 +1403,9 @@ static int x25_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
 		msg->msg_namelen = sizeof(*sx25);
 	}
 
-	x25_check_rbuf(sk);
+	/* The call may have been cleared while the socket was unlocked */
+	if (x25->neighbour)
+		x25_check_rbuf(sk);
 	rc = copied;
 out_free_dgram:
 	skb_free_datagram(sk, skb);
diff --git a/net/x25/x25_out.c b/net/x25/x25_out.c
index f710d015fcc2ffd6a6922a0c29876bb248125666..89858a3fdf428b3eae5f9c8ba54fee82f73fd0d9 100644
--- a/net/x25/x25_out.c
+++ b/net/x25/x25_out.c
@@ -78,6 +78,12 @@ int x25_output(struct sock *sk, struct sk_buff *skb)
 				return err;
 			}
 
+			/* The call may have been cleared while unlocked */
+			if (!x25->neighbour) {
+				kfree_skb(skbn);
+				return -ENOTCONN;
+			}
+
 			skb_reserve(skbn, frontlen);
 
 			len = max_len > skb->len ? skb->len : max_len;

-- 
2.47.3


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net v2 0/2] net/x25: don't call lock_sock() from softirq in x25_kill_by_neigh()
  2026-11-27  6:28 [PATCH net v2 0/2] net/x25: don't call lock_sock() from softirq in x25_kill_by_neigh() Martin Schiller
  2026-11-27  6:28 ` [PATCH net v2 1/2] " Martin Schiller
  2026-11-27  6:28 ` [PATCH net v2 2/2] net/x25: re-check x25->neighbour after re-acquiring the socket lock Martin Schiller
@ 2026-11-27  6:33 ` netdev-bot+sinfo
  2026-11-27  6:43   ` Martin Schiller
  2026-11-27 11:48 ` Martin Schiller
  2026-11-27 13:30 ` Krystian Kaniewski
  4 siblings, 1 reply; 7+ messages in thread
From: netdev-bot+sinfo @ 2026-11-27  6:33 UTC (permalink / raw)
  To: Martin Schiller
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Willem de Bruijn, Simon Horman, Lin Ma, Duoming Zhou, Xiyu Yang,
	Xin Tan, linux-x25, netdev, Nguyen Ngoc Thang, Shuai Liu,
	Krystian Kaniewski, syzbot+300375dfd44665f063a6,
	syzbot+9faa82ae2e94c5c7d2ef, linux-kernel

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net v2 0/2] net/x25: don't call lock_sock() from softirq in x25_kill_by_neigh()
  2026-11-27  6:33 ` [PATCH net v2 0/2] net/x25: don't call lock_sock() from softirq in x25_kill_by_neigh() netdev-bot+sinfo
@ 2026-11-27  6:43   ` Martin Schiller
  0 siblings, 0 replies; 7+ messages in thread
From: Martin Schiller @ 2026-11-27  6:43 UTC (permalink / raw)
  To: netdev-bot+sinfo
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Willem de Bruijn, Simon Horman, Lin Ma, Duoming Zhou, Xiyu Yang,
	Xin Tan, linux-x25, netdev, Nguyen Ngoc Thang, Shuai Liu,
	Krystian Kaniewski, syzbot+300375dfd44665f063a6,
	syzbot+9faa82ae2e94c5c7d2ef, linux-kernel

On Fri, 27 Nov 2026 07:33:54 +0100, netdev-bot wrote:
> - Whether the issue was actually triggered, or is only theoretical
>   (e.g. found by LLM and not proven at runtime). If it was triggered
>   please include the symptoms, like the stack trace or kernel messages.

Patch 1 fixes a triggered issue. syzbot hits it with its reproducers,
see the two reports in the Closes: tags. It also reproduces in QEMU
with two lapbether devices on a veth pair: when the link goes down
with a call up, an unpatched kernel with lockdep and
DEBUG_ATOMIC_SLEEP reports (trimmed):

  WARNING: inconsistent lock state
  inconsistent {SOFTIRQ-ON-W} -> {IN-SOFTIRQ-W} usage.
  x25test/26 [HC0[0]:SC1[1]:HE1:SE0] takes:
  ffff888000a81218 (sk_lock-AF_X25){+.?.}-{0:0}, at: x25_kill_by_neigh+0x50/0x99
  ...
  BUG: sleeping function called from invalid context at net/core/sock.c:3908
  in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 26, name: x25test
  Call Trace:
   <IRQ>
   ? lock_sock_nested+0x3e/0x6c
   ? x25_kill_by_neigh+0x50/0x99
   ? x25_lapb_receive_frame+0x2d9/0x2f7
   ...
   ? lapbeth_napi_poll+0x30/0x47
   ? __napi_poll.constprop.0+0x1f/0x107
   ? net_rx_action+0x134/0x26c
   ? handle_softirqs+0x14c/0x2e5

With the series applied, these splats are gone; the tests are
described in the cover letter.

Patch 2 is theoretical. The x25_sendmsg() and x25_output() cases were
found by the netdev AI review of v1, the x25_recvmsg() case by Krystian
by code inspection. The window, a CLEAR or a link failure handled in
softirq while the socket lock is dropped, is narrow, and I have not
reproduced it at runtime.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net v2 0/2] net/x25: don't call lock_sock() from softirq in x25_kill_by_neigh()
  2026-11-27  6:28 [PATCH net v2 0/2] net/x25: don't call lock_sock() from softirq in x25_kill_by_neigh() Martin Schiller
                   ` (2 preceding siblings ...)
  2026-11-27  6:33 ` [PATCH net v2 0/2] net/x25: don't call lock_sock() from softirq in x25_kill_by_neigh() netdev-bot+sinfo
@ 2026-11-27 11:48 ` Martin Schiller
  2026-11-27 13:30 ` Krystian Kaniewski
  4 siblings, 0 replies; 7+ messages in thread
From: Martin Schiller @ 2026-11-27 11:48 UTC (permalink / raw)
  To: Martin Schiller, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Willem de Bruijn, Simon Horman, Lin Ma,
	Duoming Zhou, Xiyu Yang, Xin Tan
  Cc: linux-x25, netdev, Nguyen Ngoc Thang, Shuai Liu,
	Krystian Kaniewski, syzbot+300375dfd44665f063a6,
	syzbot+9faa82ae2e94c5c7d2ef, linux-kernel

The netdev/contest failure for this series comes from two older
patches for the same bug that are still pending in patchwork: Shuai
Liu's workqueue variant [1] and the syzbot-generated fix [2]. Both
have been withdrawn in favour of this series, so they can be dropped.

[1] https://lore.kernel.org/all/tencent_8BA4FF587EE5579AB67149C5062618DC7109@qq.com/
[2] https://lore.kernel.org/all/00f667e3-a158-4fb5-84a3-9ecda4718ce8@mail.kernel.org/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net v2 0/2] net/x25: don't call lock_sock() from softirq in x25_kill_by_neigh()
  2026-11-27  6:28 [PATCH net v2 0/2] net/x25: don't call lock_sock() from softirq in x25_kill_by_neigh() Martin Schiller
                   ` (3 preceding siblings ...)
  2026-11-27 11:48 ` Martin Schiller
@ 2026-11-27 13:30 ` Krystian Kaniewski
  4 siblings, 0 replies; 7+ messages in thread
From: Krystian Kaniewski @ 2026-11-27 13:30 UTC (permalink / raw)
  To: Martin Schiller, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Willem de Bruijn, Simon Horman, Lin Ma,
	Duoming Zhou, Xiyu Yang, Xin Tan
  Cc: linux-x25, netdev, Nguyen Ngoc Thang, Shuai Liu,
	syzbot+300375dfd44665f063a6, syzbot+9faa82ae2e94c5c7d2ef,
	linux-kernel

Hi Martin,

I tested v2 on net c5de2ce2fccd in QEMU with the syzbot config of
300375dfd44665f063a6. The syz reproducer of that report and both
reproducers of 9faa82ae2e94c5c7d2ef hit the splats without the series
and run clean with it. Link loss, restart and NETDEV_DOWN with idle and
owned calls are clean too, and your tests 2 and 3 pass. The same holds
with the PREEMPT_RT config of 9faa82ae2e94c5c7d2ef.

On the question of the netdev bot: patch 2 fixes a bug that can be hit
at runtime, the x25_recvmsg() case included. The window is narrow, but
a test can hold it open. A second thread owns the socket, stalled in a
userfaultfd copy, while sendmsg() or recvmsg() waits with the lock
dropped, and a CLEAR REQUEST from the peer goes to the backlog. For
x25_sendmsg() and x25_output() an RR in the backlog first frees the
send buffer, and the sender runs at SCHED_FIFO on the owner's CPU, so
it gets its skb before the CLEAR REQUEST is processed. For
x25_recvmsg() the CLEAR REQUEST follows a short DATA packet and the
first fragment of a longer message, and the receive buffer is small,
so the fragment sets X25_COND_OWN_RX_BUSY and x25_disconnect() purges
it again. Without patch 2 all three end in a NULL pointer dereference
(trimmed):

  KASAN: null-ptr-deref in range [0x0000000000000018-0x000000000000001f]
  RIP: 0010:x25_sendmsg+0x8b2/0x1580
  Call Trace:
   __sys_sendto+0x48a/0x4e0
   __x64_sys_sendto+0xe0/0x1c0
   do_syscall_64+0x125/0x7a0

The other two stop in x25_output+0x51f, called from x25_sendmsg(), and
in x25_write_internal+0x26f, called from x25_check_rbuf() in
x25_recvmsg(). With the series send() returns ENOTCONN and recv()
returns the data. I can send the test program if it helps.

Tested-by: Krystian Kaniewski <krystianmkaniewski@gmail.com>
-- 
Krystian Kaniewski

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-27 13:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-27  6:28 [PATCH net v2 0/2] net/x25: don't call lock_sock() from softirq in x25_kill_by_neigh() Martin Schiller
2026-11-27  6:28 ` [PATCH net v2 1/2] " Martin Schiller
2026-11-27  6:28 ` [PATCH net v2 2/2] net/x25: re-check x25->neighbour after re-acquiring the socket lock Martin Schiller
2026-11-27  6:33 ` [PATCH net v2 0/2] net/x25: don't call lock_sock() from softirq in x25_kill_by_neigh() netdev-bot+sinfo
2026-11-27  6:43   ` Martin Schiller
2026-11-27 11:48 ` Martin Schiller
2026-11-27 13:30 ` Krystian Kaniewski

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®