linux/net/unix
Kuniyuki Iwashima 4a4263dfea af_unix: Unify scc_index when finalising SCC in __unix_walk_scc().
Commit bfdb01283e ("af_unix: Assign a unique index to SCC.")
changed Tarjan's algorithm to update lowlink with lowlink,
which is called lowpoint (unix_vertex.scc_index).

unix_vertex_dead() assumes all vertices in an SCC share the same
lowpoint, but this is not always true if an SCC has two or more
back edges, depending on the order of DFS.

For example, the graph below has two back edges from B to A
and from C to B.

  A --> B --> C
  ^    | ^    |
  `----' `----'

If DFS walks through A -> B -> C -> B (-> C -> B) -> A (-> B -> A),
each index and scc_index will be updated as follows.

  A --> B --> C    C = (3, 3)  (index, scc_index)
                   B = (2, 2)
                   A = (1, 1)

  A ... B ... C    C = (3, 2)<-.
         ^    |    B = (2, 2) -'
         `----'    A = (1, 1)

  A ... B ... C    C = (3, 2)
  ^    | .    .    B = (2, 1)<-.
  `----'  ....     A = (1, 1) -'

Then, unix_vertex_dead() thinks that B is passed to another
SCC with scc_index 2, and the SCC is not garbage-collected.

This does not happen if DFS walks in a different order below
or starts from B.

    1      3
  A --> B --> C
  ^    | ^    |
  `----' `----'
     2      4

Let's unify scc_index across the SCC when finalising it.

Note that updating v->index was previously done in unix_scc_dead(),
when called from __unix_walk_scc(), just to save one loop.  Since
__unix_walk_scc() now iterates over the SCC anyway, the update is
moved back to __unix_walk_scc() and 'fast' argument is dropped.

Fixes: 4090fa373f ("af_unix: Replace garbage collection algorithm.")
Reported-by: James Burton <jamesburton@meta.com>
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20260912030852.1467872-2-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2026-09-15 16:45:05 -07:00
..
af_unix.c Nothing too exciting, usual stream of fixes. 2026-09-10 14:07:48 -07:00
af_unix.h af_unix: Give up GC if MSG_PEEK intervened. 2026-03-12 13:37:18 -07:00
diag.c vfs-7.1-rc1.kino 2026-04-13 12:19:01 -07:00
garbage.c af_unix: Unify scc_index when finalising SCC in __unix_walk_scc(). 2026-09-15 16:45:05 -07:00
Kconfig af_unix: Add a prompt to CONFIG_AF_UNIX_OOB 2024-12-19 19:16:15 -08:00
Makefile af_unix: Remove CONFIG_UNIX_SCM. 2024-01-31 16:41:16 -08:00
sysctl_net_unix.c net: Const qualify network templated ctl_tables Arrays 2026-08-13 13:12:24 +02:00
unix_bpf.c bpf, sockmap: Fix af_unix null-ptr-deref in proto update 2026-04-15 17:22:58 -07:00