Re: [PATCH net v3 1/2] net/x25: don't call lock_sock() from softirq in x25_kill_by_neigh()

From: sashiko-bot

Date: Wed Dec 02 2026 - 07:02:20 EST


Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] net/x25: missing X25_KILL_FLAG check in
x25_process_rx_frame()
--

commit c78b5f40e4fa8e2412e3a3fc71a271972e1bbfc0
Author: Nguyen Ngoc Thang <ngocthang2710.1999@xxxxxxxxx>

net/x25: don't call lock_sock() from softirq in x25_kill_by_neigh()

This commit replaces lock_sock() in x25_kill_by_neigh() with the socket
spinlock, deferring x25_disconnect() via X25_KILL_FLAG and a proto
release_cb when the socket is owned by user context.

> diff --git a/net/x25/x25_in.c b/net/x25/x25_in.c
> index e47ebd8acd21b..297acfdbfb05d 100644
> --- a/net/x25/x25_in.c
> +++ b/net/x25/x25_in.c
> @@ -450,7 +450,12 @@ int x25_process_rx_frame(struct sock *sk, struct sk_buff *skb)
>
> int x25_backlog_rcv(struct sock *sk, struct sk_buff *skb)
> {
> - int queued = x25_process_rx_frame(sk, skb);
> + int queued;
> +
> + /* Serialize against x25_kill_sock() like the softirq receive path */
> + spin_lock_bh(&sk->sk_lock.slock);
> + queued = x25_process_rx_frame(sk, skb);
> + spin_unlock_bh(&sk->sk_lock.slock);
>
> if (!queued)
> kfree_skb(skb);

[Severity: Medium]
Should x25_process_rx_frame() also bail out when X25_KILL_FLAG is set?

When a socket is owned by user context, x25_kill_sock() only sets
X25_KILL_FLAG and leaves x25->state and x25->neighbour intact until
x25_release_cb() runs. However, release_sock() drains sk->sk_backlog via
__release_sock() -> x25_backlog_rcv() -> x25_process_rx_frame() before
invoking sk->sk_prot->release_cb():

net/x25/x25_in.c:x25_process_rx_frame() {
struct x25_sock *x25 = x25_sk(sk);
int queued = 0, frametype, ns, nr, q, d, m;

if (x25->state == X25_STATE_0)
return 0;

Because x25_process_rx_frame() does not check X25_KILL_FLAG, frames
queued on sk->sk_backlog before X25_KILL_FLAG was set still run the
state machine for the dead call. For example, a backlogged
X25_CLEAR_REQUEST or X25_CLEAR_CONFIRMATION frame calls
x25_disconnect(sk, 0, ...), clearing x25->neighbour and setting
sk->sk_err = 0, so x25_release_cb() then skips
x25_disconnect(sk, ENETUNREACH, 0, 0) and clears X25_KILL_FLAG, losing
ENETUNREACH (and without commit a2f4e558b645 ("net/x25: re-check
x25->neighbour after re-acquiring the socket lock"), allowing
x25_recvmsg() -> x25_check_rbuf_owned() -> x25_write_internal() to
dereference a NULL x25->neighbour).

--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201-x25-kill-by-neigh-v3-0-7f05bdff15b1@xxxxxxxxxx?part=1