[PATCH] x25: defer socket cleanup on link termination to process context

From
Shuai Liu <hidden>
Date
2026-11-16 00:34:43
Also in
lkml
Reply to
syzbot, 2026-10-11
x25_kill_by_neigh() walks all sockets bound to a neighbour and calls
lock_sock() and x25_disconnect() on each one.  It is invoked from
x25_link_terminated() and x25_link_control(), which both run in softirq
context when the LAPB link goes down or a restart frame arrives, e.g.
from the lapbether NAPI poll path.

lock_sock() takes a mutex in its slow path, so calling it from softirq
sleeps in atomic context:

  BUG: sleeping function called from invalid context at net/core/sock.c:3839
    in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 14, name: ksoftirqd/0
    ...
    lock_sock_nested+0x66/0x70
    x25_kill_by_neigh+0x90/0x110
    x25_link_terminated+0x18/0x50
    x25_lapb_receive_frame+0x1c2/0x1f0

and lockdep flags the sk_lock-AF_X25 usage violation because the same
lock is registered in process context by x25_bind():

  WARNING: inconsistent lock state
  inconsistent {SOFTIRQ-ON-W} -> {IN-SOFTIRQ-W} usage.
    ksoftirqd/0/14 [HC0[0]:SC1[1]:HE1:SE0] takes:
    ...
    x25_kill_by_neigh+0x90/0x110
    x25_link_terminated+0x18/0x50
    x25_lapb_receive_frame+0x1c2/0x1f0

Defer the neighbour socket cleanup to a per-neighbour work item so it
always runs in process context.  The work holds a reference on the
neighbour so the deferred cleanup cannot race with neighbour teardown.
x25_kill_by_neigh() is idempotent, so repeated scheduling is harmless.

Reported-by: <redacted>
Closes: https://syzkaller.appspot.com/bug?extid=300375dfd44665f063a6
Signed-off-by: Shuai Liu <redacted>
---
 include/net/x25.h  |  2 ++
 net/x25/x25_link.c | 18 +++++++++++++++---
 2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/include/net/x25.h b/include/net/x25.h
index 414f3fd993454..cb51be81351b8 100644
--- a/include/net/x25.h
+++ b/include/net/x25.h
@@ -13,6 +13,7 @@
 #include <linux/x25.h>
 #include <linux/slab.h>
 #include <linux/refcount.h>
+#include <linux/workqueue.h>
 #include <net/sock.h>
 
 #define	X25_ADDR_LEN			16
@@ -143,6 +144,7 @@ struct x25_neigh {
 	struct sk_buff_head	queue;
 	unsigned long		t20;
 	struct timer_list	t20timer;
+	struct work_struct	kill_work;
 	unsigned long		global_facil_mask;
 	refcount_t		refcnt;
 };
diff --git a/net/x25/x25_link.c b/net/x25/x25_link.c
index d1e8cd81c2143..150ccd78cba64 100644
--- a/net/x25/x25_link.c
+++ b/net/x25/x25_link.c
@@ -58,6 +58,14 @@ static inline void x25_stop_t20timer(struct x25_neigh *nb)
 	timer_delete(&nb->t20timer);
 }
 
+static void x25_kill_by_neigh_work(struct work_struct *work)
+{
+	struct x25_neigh *nb = container_of(work, struct x25_neigh, kill_work);
+
+	x25_kill_by_neigh(nb);
+	x25_neigh_put(nb);
+}
+
 /*
  *	This handles all restart and diagnostic frames.
  */
@@ -82,7 +90,8 @@ void x25_link_control(struct sk_buff *skb, struct x25_neigh *nb,
 			break;
 		case X25_LINK_STATE_3:
 			/* clear existing virtual calls */
-			x25_kill_by_neigh(nb);
+			x25_neigh_hold(nb);
+			schedule_work(&nb->kill_work);
 
 			x25_transmit_restart_confirmation(nb);
 			break;
@@ -97,7 +106,8 @@ void x25_link_control(struct sk_buff *skb, struct x25_neigh *nb,
 			break;
 		case X25_LINK_STATE_3:
 			/* clear existing virtual calls */
-			x25_kill_by_neigh(nb);
+			x25_neigh_hold(nb);
+			schedule_work(&nb->kill_work);
 
 			x25_transmit_restart_request(nb);
 			nb->state = X25_LINK_STATE_2;
@@ -254,7 +264,8 @@ void x25_link_terminated(struct x25_neigh *nb)
 	x25_stop_t20timer(nb);
 
 	/* Out of order: clear existing virtual calls (X.25 03/93 4.6.3) */
-	x25_kill_by_neigh(nb);
+	x25_neigh_hold(nb);
+	schedule_work(&nb->kill_work);
 }
 
 /*
@@ -269,6 +280,7 @@ void x25_link_device_up(struct net_device *dev)
 
 	skb_queue_head_init(&nb->queue);
 	timer_setup(&nb->t20timer, x25_t20timer_expiry, 0);
+	INIT_WORK(&nb->kill_work, x25_kill_by_neigh_work);
 
 	dev_hold(dev);
 	nb->dev      = dev;
-- 
2.43.0
Thread (2 messages) 2 messages, 2 authors, last reply 1d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help