crc-org / vfkit

Apache License 2.0
130 stars 24 forks source link

unix socket path length problems #194

Open cfergeau opened 1 week ago

cfergeau commented 1 week ago

unix socket paths have a very limited length, 104 bytes on macos, 108 on linux

Podman is currently hitting this limit with vfkit:

  time="2024-08-20T10:16:30-05:00" level=info msg="Using unix socket /var/folders/l0/3hgwcpld7h3gzm5s82dm48_w0000gn/T/podman/30247524d8c0-gvproxy.sock"
  Error: dial unixgram /var/folders/l0/3hgwcpld7h3gzm5s82dm48_w0000gn/T/podman_test2150468280/Library/Application Support/vfkit/net-5639-2529860791.sock->/var/folders/l0/3hgwcpld7h3gzm5s82dm48_w0000gn/T/podman/30247524d8c0-gvproxy.sock: bind: invalid argument

This path is generated in https://github.com/crc-org/vfkit/blob/966a9282673dbe36c7fa1b0f2c09750839501d43/pkg/vf/virtionet.go#L21-L41

cfergeau commented 1 week ago

We should also report a proper error when the path length is too long

cfergeau commented 1 week ago

Possible solutions:

cfergeau commented 1 week ago

Tentative patch for the 2nd option is

diff --git a/pkg/vf/virtionet.go b/pkg/vf/virtionet.go
index 72fd73c..28e257d 100644
--- a/pkg/vf/virtionet.go
+++ b/pkg/vf/virtionet.go
@@ -19,20 +19,12 @@ type VirtioNet struct {
    localAddr *net.UnixAddr
 }

-func localUnixSocketPath() (string, error) {
-   homeDir, err := os.UserHomeDir()
+func localUnixSocketPath(dir string) (string, error) {
+   tmpFile, err := os.CreateTemp(dir, fmt.Sprintf("vfkit-%d-*.sock", os.Getpid()))
    if err != nil {
        return "", err
    }
-   dir := filepath.Join(homeDir, "Library", "Application Support", "vfkit")
-   if err := os.MkdirAll(dir, 0755); err != nil {
-       return "", err
-   }
-   tmpFile, err := os.CreateTemp(dir, fmt.Sprintf("net-%d-*.sock", os.Getpid()))
-   if err != nil {
-       return "", err
-   }
-   // slightly racy, but this is in a directory only user-writable
+   // slightly racy, but hopefully this is in a directory only user-writable
    defer tmpFile.Close()
    defer os.Remove(tmpFile.Name())

@@ -44,7 +36,7 @@ func (dev *VirtioNet) connectUnixPath() error {
        Name: dev.UnixSocketPath,
        Net:  "unixgram",
    }
-   localSocketPath, err := localUnixSocketPath()
+   localSocketPath, err := localUnixSocketPath(filepath.Dir(dev.UnixSocketPath))
    if err != nil {
        return err
    }

(not even compile tested)