From aad32602777bdcf6b7b76265d5e0245c410fb80b Mon Sep 17 00:00:00 2001 From: Martijn Date: Tue, 10 Nov 2026 16:09:26 +0100 Subject: [PATCH 1/4] chore(linter): Update the Makefile's golangci-lint to v2.15 The lint workflow moved to golangci-lint v2.15 with the Go v1.27.2 update in ee1476e, but the Makefile stayed at v2.9, which can't load a go1.27.3 module, so make lint stopped before linting. Fixes: #1201 Signed-off-by: Martijn --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index afe535844..5dc264ace 100644 --- a/Makefile +++ b/Makefile @@ -87,8 +87,8 @@ CNTR_OPTS ?= run --rm -it # Linking variables LINT_CNTR_OPTS ?= $(CNTR_OPTS) -v $(CURDIR):/app -w /app -#? LINT_CNTR_IMG The linter image to use (default: golangci/golangci-lint:v1.53.3) -LINT_CNTR_IMG ?= golangci/golangci-lint:v2.9 +#? LINT_CNTR_IMG The linter image to use (default: golangci/golangci-lint:v2.15) +LINT_CNTR_IMG ?= golangci/golangci-lint:v2.15 LINT_CNTR_CMD ?= golangci-lint run -v --timeout=5m #? DOCS_CNTR_IMG The mkdocs image to use (default: harbor.nbfc.io/nubificus/urunc/mkdocs:test) From 63059a5a5ef89b79be55378e4558284468bbf7b4 Mon Sep 17 00:00:00 2001 From: Martijn Date: Tue, 10 Nov 2026 16:15:23 +0100 Subject: [PATCH 2/4] refactor(hypervisors): Share the solo5 cli between hvt and spt The hvt and spt tenders take the same command line, and their BuildExecCmd bodies were identical, which dupl reported. Build it in one solo5ExecCmd. What is left of hvt.go and spt.go is the same thin wrapper, so dupl skips those two files. Fixes: #1201 Signed-off-by: Martijn --- .golangci.yml | 3 ++ pkg/unikontainers/hypervisors/hvt.go | 22 +------------ pkg/unikontainers/hypervisors/solo5.go | 43 ++++++++++++++++++++++++++ pkg/unikontainers/hypervisors/spt.go | 20 +----------- 4 files changed, 48 insertions(+), 40 deletions(-) create mode 100644 pkg/unikontainers/hypervisors/solo5.go diff --git a/.golangci.yml b/.golangci.yml index 97c436722..8e711c000 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -39,6 +39,9 @@ linters: - path: _test\.go|tests/e2e/(nerdctl|docker|ctr)\.go linters: - dupl + - path: pkg/unikontainers/hypervisors/(hvt|spt)\.go + linters: + - dupl - path: tests/e2e/.*_test\.go text: "dot-imports" linters: diff --git a/pkg/unikontainers/hypervisors/hvt.go b/pkg/unikontainers/hypervisors/hvt.go index 3e1932b56..a8f839f4d 100644 --- a/pkg/unikontainers/hypervisors/hvt.go +++ b/pkg/unikontainers/hypervisors/hvt.go @@ -24,8 +24,6 @@ import ( const ( HvtVmm VmmType = "hvt" HvtBinary string = "solo5-hvt" - // solo5ArgsSeparator terminates the tender options in a solo5 cli - solo5ArgsSeparator = "--" ) type HVT struct { @@ -76,25 +74,7 @@ func (h *HVT) Ok() error { } func (h *HVT) BuildExecCmd(args types.ExecArgs, ukernel types.Unikernel) ([]string, error) { - hvtMem := BytesToStringMB(args.MemSizeB) - exArgs := []string{h.binaryPath, "--mem=" + hvtMem} - if args.Net.TapDev != "" { - netCli := ukernel.MonitorNetCli(args.Net.TapDev, args.Net.MAC) - exArgs = append(exArgs, netCli...) - } - bArgs := ukernel.MonitorBlockCli() - for _, blockArg := range bArgs { - if blockArg.Path != "" { - exArgs = append(exArgs, "--block:"+blockArg.ID+"="+blockArg.Path) - } - } - extraMonArgs := ukernel.MonitorCli() - exArgs = append(exArgs, extraMonArgs.OtherArgs...) - exArgs = append(exArgs, solo5ArgsSeparator, args.UnikernelPath) - if args.Command != "" { - exArgs = append(exArgs, args.Command) - } - return exArgs, nil + return solo5ExecCmd(h.binaryPath, args, ukernel), nil } // PreExec performs pre-execution setup for HVT. diff --git a/pkg/unikontainers/hypervisors/solo5.go b/pkg/unikontainers/hypervisors/solo5.go new file mode 100644 index 000000000..a5cb16f14 --- /dev/null +++ b/pkg/unikontainers/hypervisors/solo5.go @@ -0,0 +1,43 @@ +// Copyright (c) 2023-2026, Nubificus LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package hypervisors + +import "github.com/urunc-dev/urunc/pkg/unikontainers/types" + +// solo5ArgsSeparator terminates the tender options in a solo5 cli +const solo5ArgsSeparator = "--" + +// solo5ExecCmd builds the command line of a solo5 tender (hvt or spt). Both +// share the cli grammar "[ OPTIONS ] [ -- ] KERNEL [ ARGS ]". +func solo5ExecCmd(binaryPath string, args types.ExecArgs, ukernel types.Unikernel) []string { + exArgs := []string{binaryPath, "--mem=" + BytesToStringMB(args.MemSizeB)} + if args.Net.TapDev != "" { + netCli := ukernel.MonitorNetCli(args.Net.TapDev, args.Net.MAC) + exArgs = append(exArgs, netCli...) + } + bArgs := ukernel.MonitorBlockCli() + for _, blockArg := range bArgs { + if blockArg.Path != "" { + exArgs = append(exArgs, "--block:"+blockArg.ID+"="+blockArg.Path) + } + } + extraMonArgs := ukernel.MonitorCli() + exArgs = append(exArgs, extraMonArgs.OtherArgs...) + exArgs = append(exArgs, solo5ArgsSeparator, args.UnikernelPath) + if args.Command != "" { + exArgs = append(exArgs, args.Command) + } + return exArgs +} diff --git a/pkg/unikontainers/hypervisors/spt.go b/pkg/unikontainers/hypervisors/spt.go index 80b622e78..7844b0d3b 100644 --- a/pkg/unikontainers/hypervisors/spt.go +++ b/pkg/unikontainers/hypervisors/spt.go @@ -74,25 +74,7 @@ func (s *SPT) Ok() error { } func (s *SPT) BuildExecCmd(args types.ExecArgs, ukernel types.Unikernel) ([]string, error) { - sptMem := BytesToStringMB(args.MemSizeB) - exArgs := []string{s.binaryPath, "--mem=" + sptMem} - if args.Net.TapDev != "" { - netCli := ukernel.MonitorNetCli(args.Net.TapDev, args.Net.MAC) - exArgs = append(exArgs, netCli...) - } - bArgs := ukernel.MonitorBlockCli() - for _, blockArg := range bArgs { - if blockArg.Path != "" { - exArgs = append(exArgs, "--block:"+blockArg.ID+"="+blockArg.Path) - } - } - extraMonArgs := ukernel.MonitorCli() - exArgs = append(exArgs, extraMonArgs.OtherArgs...) - exArgs = append(exArgs, solo5ArgsSeparator, args.UnikernelPath) - if args.Command != "" { - exArgs = append(exArgs, args.Command) - } - return exArgs, nil + return solo5ExecCmd(s.binaryPath, args, ukernel), nil } // PreExec performs pre-execution setup. SPT has no special pre-exec requirements. From 8f7319a237ecc6aef8f9a0d0ba137555145d5c85 Mon Sep 17 00:00:00 2001 From: Martijn Date: Tue, 10 Nov 2026 16:18:41 +0100 Subject: [PATCH 3/4] refactor(mount): Compare statfs flags as int64 Statfs_t.Flags is an int64 on amd64 and arm64, and the ST_* constants are untyped, so keep them as int64 instead of converting the flags to uintptr, which gosec reported as G115. Fixes: #1201 Signed-off-by: Martijn --- pkg/unikontainers/mount.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/unikontainers/mount.go b/pkg/unikontainers/mount.go index b0a8f036a..769d7f745 100644 --- a/pkg/unikontainers/mount.go +++ b/pkg/unikontainers/mount.go @@ -276,7 +276,8 @@ func getUnprivilegedMountFlags(path string) (uintptr, error) { // so map each ST_* bit that statfs reports to the MS_* flag used for the // remount explicitly. lockedFlags := []struct { - st, ms uintptr + st int64 + ms uintptr }{ {unix.ST_RDONLY, unix.MS_RDONLY}, {unix.ST_NODEV, unix.MS_NODEV}, @@ -289,7 +290,7 @@ func getUnprivilegedMountFlags(path string) (uintptr, error) { var flags uintptr for _, f := range lockedFlags { - if uintptr(st.Flags)&f.st == f.st { + if st.Flags&f.st == f.st { flags |= f.ms } } From 642bac1f778179336d38ebab5eb66d77bc4b3c1a Mon Sep 17 00:00:00 2001 From: Martijn Date: Tue, 10 Nov 2026 16:20:20 +0100 Subject: [PATCH 4/4] chore(linter): Annotate the gosec false positives in cmd/urunc runcExec hands non-unikernel containers to runc with urunc's own arguments, and prepareXDGRuntimeDir only creates $XDG_RUNTIME_DIR/urunc for a rootless user, so G702 and G703 do not apply there. Fixes: #1201 Signed-off-by: Martijn --- cmd/urunc/utils.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/urunc/utils.go b/cmd/urunc/utils.go index 9bbaa7c9a..6a83db47e 100644 --- a/cmd/urunc/utils.go +++ b/cmd/urunc/utils.go @@ -100,7 +100,7 @@ func runcExec() error { return err } args[0] = binPath - return syscall.Exec(binPath, args, os.Environ()) + return syscall.Exec(binPath, args, os.Environ()) //nolint:gosec // runc gets urunc's own arguments } // newSockPair returns a new SOCK_STREAM unix socket pair. @@ -154,10 +154,10 @@ func ShouldHonorXDGRuntimeDir() bool { // prepareXDGRuntimeDir prepares the XDG_RUNTIME_DIR directory according to the XDG specification. // It creates the directory with proper permissions and sets the sticky bit to prevent auto-pruning. func prepareXDGRuntimeDir(root string) error { - if err := os.MkdirAll(root, 0o700); err != nil { + if err := os.MkdirAll(root, 0o700); err != nil { //nolint:gosec // root is $XDG_RUNTIME_DIR/urunc, the user's own dir return fmt.Errorf("the path in $XDG_RUNTIME_DIR must be writable by the user: %w", err) } - if err := os.Chmod(root, os.FileMode(0o700)|os.ModeSticky); err != nil { + if err := os.Chmod(root, os.FileMode(0o700)|os.ModeSticky); err != nil { //nolint:gosec // as above return fmt.Errorf("you should check permission of the path in $XDG_RUNTIME_DIR: %w", err) } return nil