From b9459a80c7d178d6c5b199dcab77749cb3686741 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Tue, 21 Oct 2025 03:13:58 +0900 Subject: [PATCH] container/init: check use constants for open flags These bits are arch-specific. Signed-off-by: Ophestra --- container/init_test.go | 76 +++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/container/init_test.go b/container/init_test.go index c3f2197..c0cfcfc 100644 --- a/container/init_test.go +++ b/container/init_test.go @@ -1029,8 +1029,8 @@ func TestInitEntrypoint(t *testing.T) { /* end apply */ call("mount", stub.ExpectArgs{"host", "host", "", uintptr(0x4c000), ""}, nil, nil), call("unmount", stub.ExpectArgs{"host", 2}, nil, nil), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, syscall.EINTR), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, stub.UniqueError(37)), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, syscall.EINTR), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, stub.UniqueError(37)), call("fatalf", stub.ExpectArgs{"cannot open intermediate root: %v", []any{stub.UniqueError(37)}}, nil, nil), }, }, nil}, @@ -1088,8 +1088,8 @@ func TestInitEntrypoint(t *testing.T) { /* end apply */ call("mount", stub.ExpectArgs{"host", "host", "", uintptr(0x4c000), ""}, nil, nil), call("unmount", stub.ExpectArgs{"host", 2}, nil, nil), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, syscall.EINTR), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, nil), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, syscall.EINTR), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, nil), call("chdir", stub.ExpectArgs{"/sysroot"}, nil, stub.UniqueError(35)), call("fatalf", stub.ExpectArgs{"cannot enter sysroot: %v", []any{stub.UniqueError(35)}}, nil, nil), }, @@ -1148,8 +1148,8 @@ func TestInitEntrypoint(t *testing.T) { /* end apply */ call("mount", stub.ExpectArgs{"host", "host", "", uintptr(0x4c000), ""}, nil, nil), call("unmount", stub.ExpectArgs{"host", 2}, nil, nil), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, syscall.EINTR), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, nil), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, syscall.EINTR), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, nil), call("chdir", stub.ExpectArgs{"/sysroot"}, nil, nil), call("pivotRoot", stub.ExpectArgs{".", "."}, nil, stub.UniqueError(33)), call("fatalf", stub.ExpectArgs{"cannot pivot into sysroot: %v", []any{stub.UniqueError(33)}}, nil, nil), @@ -1209,8 +1209,8 @@ func TestInitEntrypoint(t *testing.T) { /* end apply */ call("mount", stub.ExpectArgs{"host", "host", "", uintptr(0x4c000), ""}, nil, nil), call("unmount", stub.ExpectArgs{"host", 2}, nil, nil), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, syscall.EINTR), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, nil), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, syscall.EINTR), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, nil), call("chdir", stub.ExpectArgs{"/sysroot"}, nil, nil), call("pivotRoot", stub.ExpectArgs{".", "."}, nil, nil), call("fchdir", stub.ExpectArgs{1 << 35}, nil, stub.UniqueError(31)), @@ -1271,8 +1271,8 @@ func TestInitEntrypoint(t *testing.T) { /* end apply */ call("mount", stub.ExpectArgs{"host", "host", "", uintptr(0x4c000), ""}, nil, nil), call("unmount", stub.ExpectArgs{"host", 2}, nil, nil), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, syscall.EINTR), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, nil), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, syscall.EINTR), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, nil), call("chdir", stub.ExpectArgs{"/sysroot"}, nil, nil), call("pivotRoot", stub.ExpectArgs{".", "."}, nil, nil), call("fchdir", stub.ExpectArgs{1 << 35}, nil, nil), @@ -1334,8 +1334,8 @@ func TestInitEntrypoint(t *testing.T) { /* end apply */ call("mount", stub.ExpectArgs{"host", "host", "", uintptr(0x4c000), ""}, nil, nil), call("unmount", stub.ExpectArgs{"host", 2}, nil, nil), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, syscall.EINTR), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, nil), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, syscall.EINTR), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, nil), call("chdir", stub.ExpectArgs{"/sysroot"}, nil, nil), call("pivotRoot", stub.ExpectArgs{".", "."}, nil, nil), call("fchdir", stub.ExpectArgs{1 << 35}, nil, nil), @@ -1398,8 +1398,8 @@ func TestInitEntrypoint(t *testing.T) { /* end apply */ call("mount", stub.ExpectArgs{"host", "host", "", uintptr(0x4c000), ""}, nil, nil), call("unmount", stub.ExpectArgs{"host", 2}, nil, nil), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, syscall.EINTR), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, nil), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, syscall.EINTR), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, nil), call("chdir", stub.ExpectArgs{"/sysroot"}, nil, nil), call("pivotRoot", stub.ExpectArgs{".", "."}, nil, nil), call("fchdir", stub.ExpectArgs{1 << 35}, nil, nil), @@ -1463,8 +1463,8 @@ func TestInitEntrypoint(t *testing.T) { /* end apply */ call("mount", stub.ExpectArgs{"host", "host", "", uintptr(0x4c000), ""}, nil, nil), call("unmount", stub.ExpectArgs{"host", 2}, nil, nil), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, syscall.EINTR), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, nil), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, syscall.EINTR), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, nil), call("chdir", stub.ExpectArgs{"/sysroot"}, nil, nil), call("pivotRoot", stub.ExpectArgs{".", "."}, nil, nil), call("fchdir", stub.ExpectArgs{1 << 35}, nil, nil), @@ -1529,8 +1529,8 @@ func TestInitEntrypoint(t *testing.T) { /* end apply */ call("mount", stub.ExpectArgs{"host", "host", "", uintptr(0x4c000), ""}, nil, nil), call("unmount", stub.ExpectArgs{"host", 2}, nil, nil), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, syscall.EINTR), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, nil), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, syscall.EINTR), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, nil), call("chdir", stub.ExpectArgs{"/sysroot"}, nil, nil), call("pivotRoot", stub.ExpectArgs{".", "."}, nil, nil), call("fchdir", stub.ExpectArgs{1 << 35}, nil, nil), @@ -1603,8 +1603,8 @@ func TestInitEntrypoint(t *testing.T) { /* end apply */ call("mount", stub.ExpectArgs{"host", "host", "", uintptr(0x4c000), ""}, nil, nil), call("unmount", stub.ExpectArgs{"host", 2}, nil, nil), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, syscall.EINTR), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, nil), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, syscall.EINTR), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, nil), call("chdir", stub.ExpectArgs{"/sysroot"}, nil, nil), call("pivotRoot", stub.ExpectArgs{".", "."}, nil, nil), call("fchdir", stub.ExpectArgs{1 << 35}, nil, nil), @@ -1710,8 +1710,8 @@ func TestInitEntrypoint(t *testing.T) { /* end apply */ call("mount", stub.ExpectArgs{"host", "host", "", uintptr(0x4c000), ""}, nil, nil), call("unmount", stub.ExpectArgs{"host", 2}, nil, nil), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, syscall.EINTR), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, nil), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, syscall.EINTR), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, nil), call("chdir", stub.ExpectArgs{"/sysroot"}, nil, nil), call("pivotRoot", stub.ExpectArgs{".", "."}, nil, nil), call("fchdir", stub.ExpectArgs{1 << 35}, nil, nil), @@ -1818,8 +1818,8 @@ func TestInitEntrypoint(t *testing.T) { /* end apply */ call("mount", stub.ExpectArgs{"host", "host", "", uintptr(0x4c000), ""}, nil, nil), call("unmount", stub.ExpectArgs{"host", 2}, nil, nil), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, syscall.EINTR), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, nil), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, syscall.EINTR), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, nil), call("chdir", stub.ExpectArgs{"/sysroot"}, nil, nil), call("pivotRoot", stub.ExpectArgs{".", "."}, nil, nil), call("fchdir", stub.ExpectArgs{1 << 35}, nil, nil), @@ -1927,8 +1927,8 @@ func TestInitEntrypoint(t *testing.T) { /* end apply */ call("mount", stub.ExpectArgs{"host", "host", "", uintptr(0x4c000), ""}, nil, nil), call("unmount", stub.ExpectArgs{"host", 2}, nil, nil), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, syscall.EINTR), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, nil), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, syscall.EINTR), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, nil), call("chdir", stub.ExpectArgs{"/sysroot"}, nil, nil), call("pivotRoot", stub.ExpectArgs{".", "."}, nil, nil), call("fchdir", stub.ExpectArgs{1 << 35}, nil, nil), @@ -2041,8 +2041,8 @@ func TestInitEntrypoint(t *testing.T) { /* end apply */ call("mount", stub.ExpectArgs{"host", "host", "", uintptr(0x4c000), ""}, nil, nil), call("unmount", stub.ExpectArgs{"host", 2}, nil, nil), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, syscall.EINTR), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, nil), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, syscall.EINTR), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, nil), call("chdir", stub.ExpectArgs{"/sysroot"}, nil, nil), call("pivotRoot", stub.ExpectArgs{".", "."}, nil, nil), call("fchdir", stub.ExpectArgs{1 << 35}, nil, nil), @@ -2143,8 +2143,8 @@ func TestInitEntrypoint(t *testing.T) { /* end apply */ call("mount", stub.ExpectArgs{"host", "host", "", uintptr(0x4c000), ""}, nil, nil), call("unmount", stub.ExpectArgs{"host", 2}, nil, nil), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, syscall.EINTR), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, nil), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, syscall.EINTR), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, nil), call("chdir", stub.ExpectArgs{"/sysroot"}, nil, nil), call("pivotRoot", stub.ExpectArgs{".", "."}, nil, nil), call("fchdir", stub.ExpectArgs{1 << 35}, nil, nil), @@ -2236,8 +2236,8 @@ func TestInitEntrypoint(t *testing.T) { /* end apply */ call("mount", stub.ExpectArgs{"host", "host", "", uintptr(0x4c000), ""}, nil, nil), call("unmount", stub.ExpectArgs{"host", 2}, nil, nil), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, syscall.EINTR), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, nil), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, syscall.EINTR), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, nil), call("chdir", stub.ExpectArgs{"/sysroot"}, nil, nil), call("pivotRoot", stub.ExpectArgs{".", "."}, nil, nil), call("fchdir", stub.ExpectArgs{1 << 35}, nil, nil), @@ -2331,8 +2331,8 @@ func TestInitEntrypoint(t *testing.T) { /* end apply */ call("mount", stub.ExpectArgs{"host", "host", "", uintptr(0x4c000), ""}, nil, nil), call("unmount", stub.ExpectArgs{"host", 2}, nil, nil), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, syscall.EINTR), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, nil), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, syscall.EINTR), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, nil), call("chdir", stub.ExpectArgs{"/sysroot"}, nil, nil), call("pivotRoot", stub.ExpectArgs{".", "."}, nil, nil), call("fchdir", stub.ExpectArgs{1 << 35}, nil, nil), @@ -2433,8 +2433,8 @@ func TestInitEntrypoint(t *testing.T) { /* end apply */ call("mount", stub.ExpectArgs{"host", "host", "", uintptr(0x4c000), ""}, nil, nil), call("unmount", stub.ExpectArgs{"host", 2}, nil, nil), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, syscall.EINTR), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, nil), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, syscall.EINTR), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, nil), call("chdir", stub.ExpectArgs{"/sysroot"}, nil, nil), call("pivotRoot", stub.ExpectArgs{".", "."}, nil, nil), call("fchdir", stub.ExpectArgs{1 << 35}, nil, nil), @@ -2572,8 +2572,8 @@ func TestInitEntrypoint(t *testing.T) { /* end apply */ call("mount", stub.ExpectArgs{"host", "host", "", uintptr(0x4c000), ""}, nil, nil), call("unmount", stub.ExpectArgs{"host", 2}, nil, nil), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, syscall.EINTR), - call("open", stub.ExpectArgs{"/", 0x10000, uint32(0)}, 1<<35, nil), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, syscall.EINTR), + call("open", stub.ExpectArgs{"/", syscall.O_DIRECTORY | syscall.O_RDONLY, uint32(0)}, 1<<35, nil), call("chdir", stub.ExpectArgs{"/sysroot"}, nil, nil), call("pivotRoot", stub.ExpectArgs{".", "."}, nil, nil), call("fchdir", stub.ExpectArgs{1 << 35}, nil, nil),