🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #27262

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

#27262
From: netdev-bot+sashiko
Date: Sat, 05 Dec 2026 06:10
193 lines
15453 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 (1) · Medium: 0 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] This is fixed later in the series, so the baseline decision is
  false.
- [Low] The commit message relies on an ordering: "clear the flag only
  after x25_disconnect() has reset the LCI".

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the patch adds
  a comment and commit-message claim that it is solved: "Process context…

--

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

x25_kill_by_neigh() no longer calls lock_sock() and takes the socket
spinlock instead. Sockets that are not owned by user are disconnected right
away. Owned sockets get X25_KILL_FLAG and are disconnected later by a new
x25_release_cb(). While flagged, they are hidden from __x25_find_socket()
and cannot transmit. NETDEV_DOWN also gets a new sleeping sweep,
x25_kill_by_neigh_sync().

> diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c
> index 802688d5ad568..43c606a6bfa5a 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)
> +{

[ ... ]

> @@ -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);

[Severity: High]
This is a pre-existing issue, not one introduced by this patch. However,
the new comment above x25_kill_by_neigh_sync() and the commit message
both say "a sleeping sweep makes sure no socket still uses the neighbour
on return". Does the sweep actually guarantee that?

x25_route_device_down() removes the routes only after the sweep has
finished. nb stays on x25_neigh_list until NETDEV_UNREGISTER.
x25_connect() holds only lock_sock(sk), not RTNL:

x25_connect()
    rt = x25_get_route(&addr->sx25_addr);
    ...
    x25->neighbour = x25_get_neigh(rt->dev);

Suppose x25_connect() gets rt before x25_route_device_down() runs, and
sets x25->neighbour after the final pass of x25_kill_by_neigh_sync(). The
socket then still holds nb after the sweep returns, and nothing
disconnects it later.

On NETDEV_UNREGISTER, x25_link_device_down() removes nb from the list and
calls dev_put(dev). nb->dev holds no device reference of its own. The
socket keeps nb until the t21 and t23 timers lead to x25_disconnect(),
which takes about 380 seconds with the default timers.

During that window, can a read of /proc/net/x25/socket access a freed
net_device?

x25_seq_socket_show()
    if (!x25->neighbour || !x25->neighbour->dev)
        devname = "???";
    else
        devname = x25->neighbour->dev->name;

The old code had the same ordering: lock_sock() in x25_kill_by_neigh(),
then x25_route_device_down(). Should the new comment and the commit
message be changed so they only claim what the code guarantees?

[ ... ]

> @@ -492,10 +523,25 @@ 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_bit(X25_KILL_FLAG, &x25->flags))
> +		return;
> +
> +	/* Stay hidden from __x25_find_socket() until the LCI is reset */
> +	if (x25->neighbour)
> +		x25_disconnect(sk, ENETUNREACH, 0, 0);

[Severity: High]
x25_release_cb() runs from every release_sock(). That includes the
release_sock() calls that x25_sendmsg(), x25_output() and x25_recvmsg()
make in the middle of the syscall so they can sleep for memory or data.

If x25_kill_sock() flagged the socket while it was owned, can the
disconnect run inside one of those windows? The caller would then
continue with x25->neighbour set to NULL:

x25_sendmsg()
  release_sock(sk)
    x25_release_cb()
      x25_disconnect()      /* neighbour = NULL, lci = 0, state 0 */
      clear_bit(X25_KILL_FLAG, &x25->flags)
  sock_alloc_send_skb()
  lock_sock(sk)
  ...
  if (x25->neighbour->extended)  /* NULL dereference */

The fragment loop in x25_output() has the same problem. It reads
x25->neighbour->extended after its own release_sock()/lock_sock() pair.

In x25_recvmsg(), x25_check_rbuf_owned() is called after
skb_recv_datagram() returns. X25_COND_OWN_RX_BUSY is still set in
x25->condition, so the call reaches x25_write_internal(sk, X25_RR).
x25_release_cb() has already cleared X25_KILL_FLAG, so the new early
return does not fire. x25_write_internal() then dereferences
x25->neighbour->extended.

The next commit in the series, "net/x25: re-check x25->neighbour after
re-acquiring the socket lock", appears to add the missing checks to
x25_sendmsg(), x25_output() and x25_recvmsg(). Could those checks be
folded into this patch, so that this commit does not open these windows
on its own?

> +	clear_bit(X25_KILL_FLAG, &x25->flags);

[Severity: Low]
The commit message says "clear the flag only after x25_disconnect() has
reset the LCI", and the comment above relies on that order. Is the order
guaranteed for the lockless reader in __x25_find_socket()?

On the writer side, x25_disconnect() resets x25->lci with a plain store.
It clears x25->neighbour under read_lock_bh(&x25_list_lock). The
clear_bit() here then has no release ordering.

On the reader side, __x25_find_socket() holds only the read side of
x25_list_lock, which does not exclude x25_disconnect(). It does plain
loads of lci and neighbour, followed by an unordered test_bit():

    if (x25_sk(s)->lci == lci && x25_sk(s)->neighbour == nb &&
        !test_bit(X25_KILL_FLAG, &x25_sk(s)->flags)) {

On weakly ordered architectures such as arm64 or powerpc, can a lookup
see the flag as cleared while still seeing the old lci and neighbour?
If so, a frame for a new call that reused the LCI would match the old
socket. That socket is in X25_STATE_0, so x25_process_rx_frame() would
drop the frame.

Would either of these close the gap?

  - clear_bit_unlock() (or smp_mb__before_atomic()) here, paired with
    test_bit_acquire() in __x25_find_socket()
  - doing the LCI reset and the flag clear under
    write_lock_bh(&x25_list_lock)

> +}
> +
>  static struct proto x25_proto = {
>  	.name	  = "X25",
>  	.owner	  = THIS_MODULE,
>  	.obj_size = sizeof(struct x25_sock),
> +	.release_cb = x25_release_cb,
>  };

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201-x25-kill-by-neigh-v3-0-7f05bdff15b1%40dev.tdt.de
Technical Details
Message-ID: <179645102314.3146.15283327188436489540@kernel.org>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377849-linux-kernel-netdev=dewy.ru
References: <20261201-x25-kill-by-neigh-v3-1-7f05bdff15b1@dev.tdt.de>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377849-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v3 1/2] net/x25: don't call lock_sock() from softirq in x25_kill_by_neigh()
Date: Sat, 05 Dec 2026 06:10:23 +0000
Organization: Usenet Network
Message-ID: <179645102314.3146.15283327188436489540@kernel.org>
References: <20261201-x25-kill-by-neigh-v3-1-7f05bdff15b1@dev.tdt.de>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network; logging-data="2966208"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:nej6LjkX0UcRqX86tHxLkMsoJZs= sha256:DvIlDQuj7ysXrk/ZoBK2W7yyXJ+/qmsxj/UyzTwuP/Y= sha1:QUYYYtsf8uiHPF1Ww7mXLTW4IAQ= sha256:8alluB3u5bOB8CPS1OQvZEYKQWnAsfBkZndmEL3PdPo=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id A9B6D117D82; Sat,  5 Dec 2026 09:10:44 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.541
X-Spam-Status: No, score=-3.541 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rNWauomwE4xG; Sat,  5 Dec 2026 09:10:41 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-377849-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 3054A117D62; Sat,  5 Dec 2026 09:10:32 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id E7A492FDE6; Sat,  5 Dec 2026 06:10:26 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796451025; b=Do8nwf89LkNxoIrXnmG4khm8Wek9fsyZOxv3TkWq6WjZA5N1HQJJHMniTtUW3Gn4mpBi rhkOjCZeW0AWfl7W3uBw3nd6EOuhNoHPlHRnDnStx4vT9L1vuB5/Ga/i0M14as7w/KRwQ Y/cTZ6LxAxvRSeIDzlSvEF1TdvPRx+zMazu6fa24yVftIHKEElDndT3vvOtU7uox2tCBj 3WSyNMlKjTTQauOEQVK9XqbpBavIGC6wxvMa6YR4wuvcrb61MJtdXV3RvV09Gx1y7gwcv d275rXA0P0GDAPragS7oLcbsQJd+o/A2Au4jGxEydYGc0uB5B1sJPmqPGrqlGf7dIjQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796451025; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=tA5VzWcGFIN033vJPXh2PLhabItBIndc0RY+nefzdpE=; b=mc1A248DQ9xpmJg16PuGdlLlpGqmRWRMxc8vLDRuSxNKjF+6t+uFIvkGxJSIHbkXcjMy BZUPeFPBvEGvefasLf+h9PZ3H2mHWe0rkuHXcF2qV6UPhNtkaGanOL0Rmmnz7dIXoXgXa RIfkAM5YbeRpm/GtXBLzbB94/pRg8wwbYBkPjahGJkLz1xaGRw74A0Vb6IJW274VgUyuj nUNcDjEZlCjAn4nI0hCcsv/V4HhgObz5LvrO+pf6Es4hGaBcLmMNbRT5/5NyS5R9hATJF 12nyhEhNwnkB9ghFE83XsZ7DAPLFiGYz70mUcOLfQGRiLJl2OrC7Vh1hQfKPYgs4Maw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=j1j8V7M5; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C3398606A33D; Sat,  5 Dec 2026 06:10:25 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=j1j8V7M5
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796451025; b=Umq45M923YsjDyUl2poe9WlOuzeBjwM3cXjJkxX5nsnaDJWj7UJrjxntvhCi0OYRTWF8 YNHu9t7cW8bv7oaYcZKEvraGhDiHW6OQqb9kRBbPNJ+/ccKprAzUtxviZ5KIMCc/AiPg9 M8y0JQ34mJ9mNIAphRtsuwhFObiyBrfbahhKGEs9oYbcJqFajflc/9Vcswe4lf+hCvvec m+mpasGT8oNsQSbWNedLnEPCTK+7uSoIsisFNNf8jLPBtJTtyepUvWR5gXM5Q435Zsnyi e9DvXAc4wmJbwFMhNkH55E+YB8z/pKWzljz/mtmxX0vP1Bdr4xFNhFFAsiySXqTvuiQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796451025; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=tA5VzWcGFIN033vJPXh2PLhabItBIndc0RY+nefzdpE=; b=v3Z0Pacq0ZK/7KNfo8eYCPb3Rf1c7EEJEFVF3a2mVBP5NIv7sZsCctktD1/05ZKXHyFe +FeSauqy4isYe0FLDRxbCWCExBVHjm2MV8vCE67XBPttPoIy2Z6/nMbPJbfiEZIFX05cS YV4hAfiNS66jE4ieXLlmXViTo4kAgyfAwt4XwqVy2aG6V6O8yEDJQl5xr9ZfaMXIQbWQ1 aJjWJ41jU/ypIkmcELYhqIQ9EuS4/ZE6CVDfOiEGN6Ted6Z6UNG5zphgsoGGul6p+ShQ+ C9vDAgmgK1Iw2y2h8YxmeYiF/Vl1fBW9rzSvugrtE8kGcGtzCVRI+Uv6D9vm5P/PvCA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=j1j8V7M5; arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E24A5606A322; Sat,  5 Dec 2026 06:10:24 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DD521F0092B; Sat,  5 Dec 2026 06:10:23 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796451024; bh=tA5VzWcGFIN033vJPXh2PLhabItBIndc0RY+nefzdpE=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=j1j8V7M5jnH08XkTgCzj9BFxOLAA4CvGAh88WS6Qkg61duwaX3vS1tbMqF6SX0uWF y+/2cJ4XrhLRca4jY1WuW5n01quVLTA+/eiePIMsVX+8E4d/MKagtNxv1heay/3QO0 mjvXNC2/HYFinqsLMuMXe6MpWvchLUxeM7WYq1VeNY7xwMD6hjTetK410ex65HK9kc nAaphNy5dnFWjAiVE6n9nTkx90Xy0fAGNoEX9oXK8q+0VXWGifqIXWdbB5f0vRvero 7qJuUGdOUlkQWZj3Ba3fOqRqetQsDMG+ES9LSyMntHVyrfBFjmkXaXQi0kfgPvjt3b HXqD8D454Auvg==
X-Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, willemb@google.com, horms@kernel.org, linma@zju.edu.cn, duoming@zju.edu.cn, xiyuyang19@fudan.edu.cn, tanxin.ctf@gmail.com, bigeasy@linutronix.de, clrkwllms@kernel.org, rostedt@goodmis.org, linux-x25@vger.kernel.org, netdev@vger.kernel.org, ngocthang2710.1999@gmail.com, 847807867@qq.com, krystianmkaniewski@gmail.com, syzbot+300375dfd44665f063a6@syzkaller.appspotmail.com, syzbot+9faa82ae2e94c5c7d2ef@syzkaller.appspotmail.com, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev
X-In-Reply-To: <20261201-x25-kill-by-neigh-v3-1-7f05bdff15b1@dev.tdt.de>
X-sashiko-severity: High
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list