Skip to content

Commit

Permalink
lxd/instance/drivers: Use shorter socket path in deviceAttachPath
Browse files Browse the repository at this point in the history
Signed-off-by: hamistao <pedro.ribeiro@canonical.com>
  • Loading branch information
hamistao committed Jun 10, 2024
1 parent 3353ddb commit 0dd71dd
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lxd/instance/drivers/driver_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -2185,7 +2185,15 @@ func (d *qemu) deviceAttachPath(deviceName string, configCopy map[string]string,
return fmt.Errorf("Failed to connect to QMP monitor: %w", err)
}

addr, err := net.ResolveUnixAddr("unix", virtiofsdSockPath)
// Open a file descriptor to the socket file through O_PATH to avoid acessing the file descriptor to the sockfs inode.
socketFile, err := os.OpenFile(virtiofsdSockPath, unix.O_PATH|unix.O_CLOEXEC, 0)
if err != nil {
return fmt.Errorf("Failed to open device socket file %q: %w", virtiofsdSockPath, err)
}

shortPath := fmt.Sprintf("/dev/fd/%d", socketFile.Fd())

addr, err := net.ResolveUnixAddr("unix", shortPath)
if err != nil {
return err
}
Expand Down

0 comments on commit 0dd71dd

Please sign in to comment.