Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

socketpair_unix: avoid double close(), set FD_CLOEXEC #66

Merged
merged 1 commit into from
Jan 31, 2024

Commits on Jan 31, 2024

  1. sockerpair_unix: avoid double close(), set FD_CLOEXEC

    We were calling the close() syscall multiple time
    with the same fd number, leading to random issues like
    closing containerd stream port.
    
    In newLaunchedPlugin() we have:
    sockets, _ := net.NewSocketPair()
    defer sockets.Close()
    conn, _ := sockets.LocalConn()
    peerFile := sockets.PeerFile()
    defer func() {
      peerFile.Close()
      if retErr != nil {
        conn.Close()
      }
    }()
    cmd.Start()
    
    so we were doing:
    close(local) (in LocalConn())
    cmd.Start()
    close(peer) (peerFile.Close())
    close(local) (sockets.Close())
    close(peer) (sockets.Close())
    
    If the NRI plugin that we launch with cmd.Start() is not cached or
    the system is a bit busy, cmd.Start() gives a large enough window
    for another goroutine to open a file that will get the same fd number
    as local was, thus being closed by accident.
    
    Fix the situation by storing os.Files instead of ints, so that closing
    multiple times just returns an error (that we ignore).
    
    Also set FD_CLOEXEC on the sockets so we don't leak them.
    
    Fixes 1da2cdf
    
    Signed-off-by: Etienne Champetier <[email protected]>
    champtar committed Jan 31, 2024
    Configuration menu
    Copy the full SHA
    5d0b52b View commit details
    Browse the repository at this point in the history