Skip to content
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

runtime: when ptrace_scope is 2 or 3, certain tests in runtime-gdb_test.go fail #69932

Closed
fuowang opened this issue Oct 18, 2024 · 2 comments
Closed
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@fuowang
Copy link
Contributor

fuowang commented Oct 18, 2024

Go version

go version go1.23.2 linux/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/root/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/root/go'
GOPRIVATE=''
GOPROXY='https://goproxy.cn,direct'
GOROOT='/usr/lib/golang'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN=''
GOTOOLDIR='/usr/lib/golang/pkg/tool/linux_arm64'
GOVCS=''
GOVERSION='go1.23.2'
GCCGO='gccgo'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/usr/lib/golang/src/go.mod'
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 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3558252436=/tmp/go-build -gno-record-gcc-switches'

What did you do?

The ptrace_scope kernel parameter controls the level of restrictions on process tracing with ptrace in Linux.
It determines which processes can be traced by others.

The values are:
0 - Default attach security permissions.
1 - Restricted attach. Only child processes plus normal permissions.
2 - Admin-only attach. Only executables with CAP_SYS_PTRACE.
3 - No attach. No process may call ptrace at all. Irrevocable.

This parameter enhances security by limiting unauthorized access to process memory and control.
When kernel parameter ptrace_scope is set to 2 or 3, certain test cases within runtime-gdb_test.go will fail.

Steps 1. cat /proc/sys/kernel/yama/ptrace_scope
Steps 2. whoami && id -u
Steps 3. cd /usr/lib/golang/src/runtime && go test ./runtime-gdb_test.go --count=1

What did you see happen?

  1. The value of ptrace_scope is 0 or 1. Non-root and root user.
    The test passes.
    图片
    图片
    图片
    图片

  2. The value of ptrace_scope is 2. Non-root user.

2.1 The failed test cases are: TestGdbBacktrace, TestGdbPanic, TestGdbPython, TestGdbInfCallstack, TestGdbPythonCgo
图片

=== CONT  TestGdbBacktrace
    runtime-gdb_test.go:471: gdb output:
        Loading Go Runtime support.
        Breakpoint 1 at 0x67878: file /tmp/go-build257553814/main.go, line 17.
        warning: Could not trace the inferior process.
        Error: 
        warning: ptrace: Operation not permitted
        During startup program exited with code 127.
        No stack.
        The program is not being run.
    runtime-gdb_test.go:489: could not find '#0.*main\.eee' in backtrace
--- FAIL: TestGdbBacktrace (1.32s)
=== CONT  TestGdbPanic
    runtime-gdb_test.go:685: gdb output:
        Loading Go Runtime support.
        warning: Could not trace the inferior process.
        Error: 
        warning: ptrace: Operation not permitted
        During startup program exited with code 127.
        No stack.
    runtime-gdb_test.go:699: could not find '(#.* .* in )?main\.crash' in backtrace
--- FAIL: TestGdbPanic (1.32s)
=== CONT  TestGdbPython
    runtime-gdb_test.go:303: gdb output:
        Loading Go Runtime support.
        Loaded  Script                                                                 
        Yes     /usr/lib/golang/src/runtime/runtime-gdb.py                             
        Breakpoint 1 at 0x9dff4: file /tmp/go-build363570173/main.go, line 26.
        warning: Could not trace the inferior process.
        Error: 
        warning: ptrace: Operation not permitted
        During startup program exited with code 127.
        BEGIN info goroutines
        END
        BEGIN print mapvar
        No symbol "mapvar" in current context.
        END
        BEGIN print slicemap
        No symbol "slicemap" in current context.
        END
        BEGIN print strvar
        No symbol "strvar" in current context.
        END
        BEGIN print chanint
        No symbol "chanint" in current context.
        END
        BEGIN print chanstr
        No symbol "chanstr" in current context.
        END
        BEGIN info locals
        No frame selected.
        END
        BEGIN goroutine 1 bt
        No such goroutine:  1
        END
        BEGIN goroutine all bt
        END
        No breakpoint at main.go:15.
        Breakpoint 2 at 0x9e118: file /tmp/go-build363570173/main.go, line 29.
        The program is not being run.
        BEGIN goroutine 1 bt at the end
        No such goroutine:  1
        END
    runtime-gdb_test.go:335: info goroutines failed: END
        BEGIN print mapvar
        No symbol "mapvar" in current context.
--- FAIL: TestGdbPython (1.57s)
=== CONT  TestGdbInfCallstack
    runtime-gdb_test.go:767: gdb output:
        Loading Go Runtime support.
        Breakpoint 1 at 0x1200544d8: file /usr/lib/golang/src/runtime/asm_arm64.s, line 1201.
        warning: Could not trace the inferior process.
        Error: 
        warning: ptrace: Operation not permitted
        During startup program exited with code 127.
        No stack.
        The program is not being run.
    runtime-gdb_test.go:783: could not find '#0.*setg_gcc' in backtrace
--- FAIL: TestGdbInfCallstack (1.94s)
=== CONT  TestGdbPythonCgo
    runtime-gdb_test.go:303: gdb output:
        Loading Go Runtime support.
        Loading Go Runtime support.
        Breakpoint 1 at 0x12008e9a4: file /tmp/go-build548209976/main.go, line 27.
        warning: Could not trace the inferior process.
        Error: 
        warning: ptrace: Operation not permitted
        During startup program exited with code 127.
        BEGIN info goroutines
        END
        BEGIN print mapvar
        No symbol "mapvar" in current context.
        END
        BEGIN print slicemap
        No symbol "slicemap" in current context.
        END
        BEGIN print strvar
        No symbol "strvar" in current context.
        END
        BEGIN print chanint
        No symbol "chanint" in current context.
        END
        BEGIN print chanstr
        No symbol "chanstr" in current context.
        END
        BEGIN info locals
        No frame selected.
        END
        BEGIN goroutine 1 bt
        No such goroutine:  1
        END
        BEGIN goroutine all bt
        END
        No breakpoint at main.go:15.
        Breakpoint 2 at 0x12008eac8: file /tmp/go-build548209976/main.go, line 30.
        The program is not being run.
        BEGIN goroutine 1 bt at the end
        No such goroutine:  1
        END
    runtime-gdb_test.go:335: info goroutines failed: END
        BEGIN print mapvar
        No symbol "mapvar" in current context.
--- FAIL: TestGdbPythonCgo (2.21s)

2.2 The abnormal test cases are: TestGdbAutotmpTypes, TestGdbConst
图片

=== CONT  TestGdbAutotmpTypes
    runtime-gdb_test.go:550: gdb output:
        Loading Go Runtime support.
        Breakpoint 1 at 0x6bc84: file /tmp/go-build891356755/main.go, line 9.
        warning: Could not trace the inferior process.
        Error: 
        warning: ptrace: Operation not permitted
        During startup program exited with code 127.
        The program is not being run.
        All types matching regular expression "astruct":
        
        File runtime:
                []main.astruct;
                bucket<string,main.astruct>;
                hash<string,main.astruct>;
                main.astruct;
                typedef hash<string,main.astruct> * map[string]main.astruct;
                typedef noalg.[8]main.astruct noalg.[8]main.astruct;
                noalg.map.bucket[string]main.astruct;
                noalg.map.hdr[string]main.astruct;
--- PASS: TestGdbAutotmpTypes (1.15s)
=== CONT  TestGdbConst
    runtime-gdb_test.go:622: gdb output:
        Loading Go Runtime support.
        Breakpoint 1 at 0x6bb80: file /tmp/go-build216296900/main.go, line 9.
        warning: Could not trace the inferior process.
        Error: 
        warning: ptrace: Operation not permitted
        During startup program exited with code 127.
        $1 = 42
        $2 = 18446744073709551615
        $3 = -1
        $4 = 1 '\001'
        $5 = 8192
--- PASS: TestGdbConst (1.17s)
  1. The value of ptrace_scope is 2. Root user.
    The test passes.
    图片

  2. The value of ptrace_scope is 3. Non-root and root user.
    Same as the second scenario.
    图片
    图片

What did you expect to see?

When the kernel parameter ptrace_scope is set to 2 or 3, certain test cases in runtime-gdb_test.go will fail. We should skip these tests.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Oct 18, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/620857 mentions this issue: runtime: add the checkPtraceScope to skip certain tests

@prattmic prattmic added this to the Backlog milestone Oct 21, 2024
@prattmic prattmic added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 21, 2024
@mknyszek mknyszek moved this to All-But-Submitted in Go Compiler / Runtime Oct 23, 2024
@dmitshur dmitshur modified the milestones: Backlog, Go1.24 Oct 23, 2024
@github-project-automation github-project-automation bot moved this from All-But-Submitted to Done in Go Compiler / Runtime Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Projects
Development

Successfully merging a pull request may close this issue.

5 participants