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

unix socket path length problems #194

Open
cfergeau opened this issue Sep 18, 2024 · 4 comments · May be fixed by #195
Open

unix socket path length problems #194

cfergeau opened this issue Sep 18, 2024 · 4 comments · May be fixed by #195
Assignees

Comments

@cfergeau
Copy link
Collaborator

cfergeau commented Sep 18, 2024

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

func localUnixSocketPath() (string, error) {
homeDir, err := os.UserHomeDir()
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
defer tmpFile.Close()
defer os.Remove(tmpFile.Name())
return tmpFile.Name(), nil
}

@cfergeau
Copy link
Collaborator Author

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

@cfergeau
Copy link
Collaborator Author

Possible solutions:

  • allow to override the path the socket goes to with a local variable
  • put the vfkit socket in the same directory as the socket it's connecting to

@cfergeau
Copy link
Collaborator Author

cfergeau commented Sep 18, 2024

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)

cfergeau added a commit to cfergeau/vfkit that referenced this issue Sep 20, 2024
With unixgram sockets, we need to specify a client endpoint, which is a
path on the filesystem with a maximum length of 104 bytes on macOS.
When using -device virtio-net,unixSocketPath=/tmp/vnet.sock, we
need to create a client endpoint before connecting to /tmp/vnet.sock.
It's currently put into `/Users/user/Library/Application Support`, which
is already fairly long. Depending on the username, the 104 bytes are
easily exceeded, this has been causing problems to podman machine.

This commit will create the client endpoint in the same directory as the
server endpoint, which gives more control to the user of vfkit wrt where
this socket is going.

This fixes crc-org#194

Signed-off-by: Christophe Fergeau <[email protected]>
@nirs
Copy link
Contributor

nirs commented Sep 30, 2024

If the socket is created by vfkit, it can be under ~/.vfkit/. The is no need to hope that the directory is user writable, vfkit can enforce this on startup and fail to start if the permissions are unexpected.

@lstocchi lstocchi assigned cfergeau and unassigned lstocchi Oct 15, 2024
cfergeau added a commit to cfergeau/vfkit that referenced this issue Oct 28, 2024
With unixgram sockets, we need to specify a client endpoint, which is a
path on the filesystem with a maximum length of 104 bytes on macOS.
When using -device virtio-net,unixSocketPath=/tmp/vnet.sock, we
need to create a client endpoint before connecting to /tmp/vnet.sock.
It's currently put into `/Users/user/Library/Application Support`, which
is already fairly long. Depending on the username, the 104 bytes are
easily exceeded, this has been causing problems to podman machine.

This commit will create the client endpoint in the same directory as the
server endpoint, which gives more control to the user of vfkit wrt where
this socket is going.

This fixes crc-org#194

Signed-off-by: Christophe Fergeau <[email protected]>
cfergeau added a commit to cfergeau/vfkit that referenced this issue Oct 28, 2024
With unixgram sockets, we need to specify a client endpoint, which is a
path on the filesystem with a maximum length of 104 bytes on macOS.
When using -device virtio-net,unixSocketPath=/tmp/vnet.sock, we
need to create a client endpoint before connecting to /tmp/vnet.sock.
It's currently put into `/Users/user/Library/Application Support`, which
is already fairly long. Depending on the username, the 104 bytes are
easily exceeded, this has been causing problems to podman machine.

This commit will create the client endpoint in the same directory as the
server endpoint, which gives more control to the user of vfkit wrt where
this socket is going.

This fixes crc-org#194

Signed-off-by: Christophe Fergeau <[email protected]>
cfergeau added a commit to cfergeau/vfkit that referenced this issue Oct 28, 2024
With unixgram sockets, we need to specify a client endpoint, which is a
path on the filesystem with a maximum length of 104 bytes on macOS.
When using -device virtio-net,unixSocketPath=/tmp/vnet.sock, we
need to create a client endpoint before connecting to /tmp/vnet.sock.
It's currently put into `/Users/user/Library/Application Support`, which
is already fairly long. Depending on the username, the 104 bytes are
easily exceeded, this has been causing problems to podman machine.

This commit will create the client endpoint in the same directory as the
server endpoint, which gives more control to the user of vfkit wrt where
this socket is going.

This fixes crc-org#194

Signed-off-by: Christophe Fergeau <[email protected]>
cfergeau added a commit to cfergeau/vfkit that referenced this issue Oct 29, 2024
With unixgram sockets, we need to specify a client endpoint, which is a
path on the filesystem with a maximum length of 104 bytes on macOS.
When using -device virtio-net,unixSocketPath=/tmp/vnet.sock, we
need to create a client endpoint before connecting to /tmp/vnet.sock.
It's currently put into `/Users/user/Library/Application Support`, which
is already fairly long. Depending on the username, the 104 bytes are
easily exceeded, this has been causing problems to podman machine.

This commit will create the client endpoint in the same directory as the
server endpoint, which gives more control to the user of vfkit wrt where
this socket is going.

This fixes crc-org#194

Signed-off-by: Christophe Fergeau <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants