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/2026…%40dev.tdt.de