Re: [PATCH] net/x25: fix invalid lock_sock() usage in x25_kill_by_neigh()

From: Krystian Kaniewski

Date: Tue Nov 24 2026 - 07:32:22 EST


On Tue, 24 Nov 2026 09:58:44 +0000, netdev-bot+sashiko@xxxxxxxxxx wrote:
> - [Medium] When the new softirq path finds a socket owned by a task, it
> only sets a flag and leaves the dead call usable until release_sock().

Agreed. While a task owns the socket, the flagged call keeps its LCI
binding until release_sock(). __x25_find_socket() still returns it, so
frames that arrive after the restart go to its backlog and are processed
in the old state before x25_release_cb() runs. The owner can also still
transmit on the old LCI, and after a LAPB disconnect this brings the
link back up.

This patch follows the same design as Thang's patch from October [1].
In that thread Martin confirmed both effects in a test on 23 November
and announced a v2 which skips flagged sockets in __x25_find_socket()
and returns early from x25_kick() and x25_write_internal() for them.
That covers this finding, so please drop this patch in favour of his
series. I will not send a v2 of it.

> Pre-existing issues:
> - [High] This problem wasn't introduced by this patch, but it is still
> reachable after it.

Agreed as well. x25_disconnect() clears x25->neighbour since commit
4becb7ee5b3d ("net/x25: Fix x25_neigh refcnt leak when x25
disconnect"), and x25_sendmsg() and x25_output() dereference it after
they take the socket lock again. Martin wrote that he has a separate
fix for this.

x25_recvmsg() has the same kind of window, and the review did not
report it. If x25_disconnect() runs after skb_recv_datagram() has
dequeued a packet and before lock_sock() returns, x25_recvmsg() then
calls x25_check_rbuf() on a socket without a neighbour.
x25_disconnect() does not clear x25->condition, so with
X25_COND_OWN_RX_BUSY still set and sk_rmem_alloc below half of
sk_rcvbuf, x25_check_rbuf() sends an RR through x25_write_internal(),
which dereferences x25->neighbour. I found this by reading the code and
have not reproduced it, but it may be worth covering in the same fix.

Martin, syzbot tracks this report separately from the one in Thang's
patch (extid 9faa82ae2e94c5c7d2ef). Could you also add the Reported-by
and Closes tags for 300375dfd44665f063a6 to the series, so that syzbot
closes this one too?

I am happy to test the series with the syzbot reproducer once it is
posted.

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

pw-bot: cr

--
Krystian Kaniewski