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 based on 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. 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. v3 addresses the AI review of v2 [6]: the flag is only cleared once the socket's LCI has been reset, and transmissions in process context and the backlog processing take the socket spinlock, so that an owner cannot send frames of the old call after the restart has been confirmed. Patch 2 fixes a pre-existing NULL pointer dereference in x25_sendmsg(), x25_output() and x25_recvmsg() after they retake the socket lock. The AI review of v1 [2] pointed out the first two, Krystian Kaniewski found the x25_recvmsg() case and reproduced all three at runtime [7]. It does not depend on patch 1. The AI review of v2 also notes [8] that a reconnect on the same socket while x25_output() waits would pass the new check; that is a separate, pre-existing issue that this series does not address. 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 v3 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. With v3, lockdep reports nothing in these tests, including the new uses of the socket spinlock. Krystian tested v2 with the syzbot reproducers of both reports, also with the PREEMPT_RT config of the second one [7], and Shuai Liu tested and reviewed v2; their tags are kept for patch 2 only, as patch 1 changed. The two races fixed in v3 are not covered by a test. Changes in v3: - clear X25_KILL_FLAG only after x25_disconnect() has reset the LCI - take the socket spinlock around transmissions in process context and around the backlog processing - update the comments of __x25_find_socket() and x25_new_lci() - patch 2: describe the runtime reproduction, add Tested-by and Reviewed-by - Link to v2: https://lore.kernel.org/all/2026…@dev.tdt.de/ 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/2026…@gmail.com/ [2] https://lore.kernel.org/all/1791…@kernel.org/ [3] https://lore.kernel.org/all/tenc…@qq.com/ [4] https://lore.kernel.org/all/tenc…@qq.com/ [5] https://lore.kernel.org/all/00f6…@mail.kernel.org/ [6] https://lore.kernel.org/all/1795…@kernel.org/ [7] https://lore.kernel.org/all/5ad2…@gmail.com/ [8] https://netdev-ai.bots.linux.dev/sashiko/#/patchset/2026…%40dev.tdt.de --- 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 | 123 +++++++++++++++++++++++++++++++++++++++++++++++------ net/x25/x25_in.c | 7 ++- net/x25/x25_out.c | 9 +++- net/x25/x25_subr.c | 4 ++ 5 files changed, 129 insertions(+), 15 deletions(-) --- base-commit: d73525e6950b982fb67c74a1a64163529305a003 change-id: 20261124-x25-kill-by-neigh-2b70f6d19961 Best regards,
-- Martin Schiller <m…@dev.tdt.de>