• Kuniyuki Iwashima's avatar
    af_unix: Link struct unix_edge when queuing skb. · 42f298c0
    Kuniyuki Iwashima authored
    Just before queuing skb with inflight fds, we call scm_stat_add(),
    which is a good place to set up the preallocated struct unix_vertex
    and struct unix_edge in UNIXCB(skb).fp.
    
    Then, we call unix_add_edges() and construct the directed graph
    as follows:
    
      1. Set the inflight socket's unix_sock to unix_edge.predecessor.
      2. Set the receiver's unix_sock to unix_edge.successor.
      3. Set the preallocated vertex to inflight socket's unix_sock.vertex.
      4. Link inflight socket's unix_vertex.entry to unix_unvisited_vertices.
      5. Link unix_edge.vertex_entry to the inflight socket's unix_vertex.edges.
    
    Let's say we pass the fd of AF_UNIX socket A to B and the fd of B
    to C.  The graph looks like this:
    
      +-------------------------+
      | unix_unvisited_vertices | <-------------------------.
      +-------------------------+                           |
      +                                                     |
      |     +--------------+             +--------------+   |         +--------------+
      |     |  unix_sock A | <---. .---> |  unix_sock B | <-|-. .---> |  unix_sock C |
      |     +--------------+     | |     +--------------+   | | |     +--------------+
      | .-+ |    vertex    |     | | .-+ |    vertex    |   | | |     |    vertex    |
      | |   +--------------+     | | |   +--------------+   | | |     +--------------+
      | |                        | | |                      | | |
      | |   +--------------+     | | |   +--------------+   | | |
      | '-> |  unix_vertex |     | | '-> |  unix_vertex |   | | |
      |     +--------------+     | |     +--------------+   | | |
      `---> |    entry     | +---------> |    entry     | +-' | |
            |--------------|     | |     |--------------|     | |
            |    edges     | <-. | |     |    edges     | <-. | |
            +--------------+   | | |     +--------------+   | | |
                               | | |                        | | |
        .----------------------' | | .----------------------' | |
        |                        | | |                        | |
        |   +--------------+     | | |   +--------------+     | |
        |   |   unix_edge  |     | | |   |   unix_edge  |     | |
        |   +--------------+     | | |   +--------------+     | |
        `-> | vertex_entry |     | | `-> | vertex_entry |     | |
            |--------------|     | |     |--------------|     | |
            |  predecessor | +---' |     |  predecessor | +---' |
            |--------------|       |     |--------------|       |
            |   successor  | +-----'     |   successor  | +-----'
            +--------------+             +--------------+
    
    Henceforth, we denote such a graph as A -> B (-> C).
    
    Now, we can express all inflight fd graphs that do not contain
    embryo sockets.  We will support the particular case later.
    Signed-off-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
    Acked-by: default avatarPaolo Abeni <pabeni@redhat.com>
    Link: https://lore.kernel.org/r/20240325202425.60930-4-kuniyu@amazon.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
    42f298c0
garbage.c 13.2 KB