Skip to content

os/exec: TestFindExecutableVsNoexec fail in lxd container #59087

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

Closed
zhsj opened this issue Mar 17, 2023 · 6 comments
Closed

os/exec: TestFindExecutableVsNoexec fail in lxd container #59087

zhsj opened this issue Mar 17, 2023 · 6 comments
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done. Testing An issue that has been verified to require only test changes, not just a test failure.
Milestone

Comments

@zhsj
Copy link
Contributor

zhsj commented Mar 17, 2023

What version of Go are you using (go version)?

$ go version
1.20.2

Does this issue reproduce with the latest release?

yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/zsj/.cache/go-build"
GOENV="/home/zsj/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/zsj/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/zsj/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn"
GOROOT="/usr/lib/go-1.20"
GOSUMDB="sum.golang.google.cn"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.20/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.2"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1236278361=/tmp/go-build -gno-record-gcc-switches"

What did you do?

go test -v os/exec -run TestFindExecutableVsNoexec

What did you expect to see?

no fatal

What did you see instead?

lp_linux_test.go:71: remount /tmp/TestFindExecutableVsNoexec2830811350/001 with noexec failed: permission denied

If I run following command, it's indeed no permission to remount.

# mount -t tmpfs tmpfs /tmp/t
# mount -t tmpfs tmpfs -o remount /tmp/t
mount: /tmp/t: cannot remount tmpfs read-write, is write-protected.

So I think the test need to be skipped when the second mount is failed.

@bcmills
Copy link
Contributor

bcmills commented Mar 17, 2023

Sounds like the test should be skipped if syscall.Mount returns EROFS.

(At HEAD, I think it could just call testenv.SyscallIsNotSupported.)

@bcmills bcmills added Testing An issue that has been verified to require only test changes, not just a test failure. help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Mar 17, 2023
@bcmills bcmills added this to the Backlog milestone Mar 17, 2023
@zhsj
Copy link
Contributor Author

zhsj commented Mar 20, 2023

Hmm, I attempt to use testenv.SyscallIsNotSupported, but get stuck with cycle import.

testenv uses os/exec. TestFindExecutableVsNoexec is to test an unexported function in os/exec.

Any suggestions?

@bcmills
Copy link
Contributor

bcmills commented Mar 20, 2023

Ideally, rewrite the test to use the exported API. That should at least be possible by invoking exec.LookPath in a subprocess with an appropriate PATH variable, and IIRC there are already a bunch of test helpers in os/exec for running the test binary itself as various commands.

@zhsj
Copy link
Contributor Author

zhsj commented Mar 20, 2023

The second remount seems failed with EACCES.

mount("tmpfs", "/tmp/t", 0x55be2658f240, MS_REMOUNT, NULL) = -1 EACCES (Permission denied)

Probably it's denied by some lxd apparmor/seccomp things. However I'm just using the lxd default options.

@bcmills
Copy link
Contributor

bcmills commented Mar 20, 2023

testenv.SyscallIsNotSupported should handle EACCES via the errors.Is(err, fs.ErrPermission) check:
https://cs.opensource.google/go/go/+/master:src/syscall/syscall_unix.go;l=120-121;drc=75c2e97c3c11050847fc221480e1939f29c911e5

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/481620 mentions this issue: os/exec: skip remount in TestFindExecutableVsNoexec on EROFS

@golang golang locked and limited conversation to collaborators Apr 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done. Testing An issue that has been verified to require only test changes, not just a test failure.
Projects
None yet
Development

No branches or pull requests

3 participants