Skip to content

Commit 1349aff

Browse files
committed
pkg/qemu: validate VNL more strictly
Signed-off-by: Akihiro Suda <[email protected]>
1 parent 004b75a commit 1349aff

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

pkg/qemu/qemu.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"errors"
66
"fmt"
7+
"io/fs"
78
"os"
89
"os/exec"
910
"path/filepath"
@@ -264,6 +265,16 @@ func Cmdline(cfg Config) (string, []string, error) {
264265
if _, err := os.Stat(vdeSock); err != nil {
265266
return "", nil, fmt.Errorf("cannot use VNL %q: %w", vde.VNL, err)
266267
}
268+
// vdeSock is a directory, unless vde.SwitchPort == 65535 (PTP)
269+
actualSocket := filepath.Join(vdeSock, "ctl")
270+
if vde.SwitchPort == 65535 { // PTP
271+
actualSocket = vdeSock
272+
}
273+
if st, err := os.Stat(actualSocket); err != nil {
274+
return "", nil, fmt.Errorf("cannot use VNL %q: failed to stat %q: %w", vde.VNL, actualSocket, err)
275+
} else if st.Mode()&fs.ModeSocket == 0 {
276+
return "", nil, fmt.Errorf("cannot use VNL %q: %q is not a socket: %w", vde.VNL, actualSocket, err)
277+
}
267278
}
268279
args = append(args, "-netdev", fmt.Sprintf("vde,id=net%d,sock=%s", i+1, vdeSock))
269280
args = append(args, "-device", fmt.Sprintf("virtio-net-pci,netdev=net%d,mac=%s", i+1, vde.MACAddress))

0 commit comments

Comments
 (0)