Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Could not attach to pid:#### this could be caused by a kernel security setting, try writing "0" to /proc/sys/kernel/yama/ptrace_scope #3098

Closed
Anjana-Prabhakar opened this issue Mar 13, 2020 · 6 comments

Comments

@Anjana-Prabhakar
Copy link

Please direct general questions to:

Please review the Wiki before filing an issue.
Helpful pages include:

Please answer these questions before submitting your issue. Thanks!

What version of Go, VS Code & VS Code Go extension are you using?

  • Run go version to get version of Go
    • go version go1.13.4 linux/amd64
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders
    • 1.43.0
      78a4c91400152c0f27ba4d363eb56d2835f9903a
      x64
  • Check your installed extensions to get the version of the VS Code Go extension
    • 0.13,1
  • Run go env GOOS GOARCH to get the operating system and processor arhcitecture details
    • linux
      amd64

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file.
Share all the settings with the go. or ["go"] prefixes.
The command output was: bash: syntax error near unexpected token (' the output to Preferences: Open Settingswascommand not found`
On opening settings,json file,

"go.formatTool": "goimports",
    "go.useLanguageServer": true

Describe the bug

A clear and concise description of what the bug.
A clear and concise description of what you expected to happen.
I have a go application tendermint running which creates blocks of a blockchain. On running debug using the attach option as shown below:

 "name":"attach to process",
            "type": "go",
            "request": "attach",
            "mode": "local",
            "processId": 30834,
            "trace":"log"

i get an error Could not attach to pid:30834 this could be caused by a kernel security setting, try writing "0" to /proc/sys/kernel/yama/ptrace_scope

Steps to reproduce the behavior:

  1. Run Tendermint single node application
make install
tendermint init
tendermint node --proxy_app=kvstore
  1. Click on 'debug with attach'
  2. See error
2020-3-13, 07:00:16.821 UTC
[07:00:16.821 UTC] From client: initialize({"clientID":"vscode","clientName":"Visual Studio Code","adapterID":"go","pathFormat":"path","linesStartAt1":true,"columnsStartAt1":true,"supportsVariableType":true,"supportsVariablePaging":true,"supportsRunInTerminalRequest":true,"locale":"en-gb"})
[07:00:16.822 UTC] InitializeRequest
[07:00:16.822 UTC] To client: {"seq":0,"type":"response","request_seq":1,"command":"initialize","success":true,"body":{"supportsConfigurationDoneRequest":true,"supportsSetVariable":true}}
[07:00:16.822 UTC] InitializeResponse
[07:00:16.822 UTC] From client: attach({"name":"attach to process","type":"go","request":"attach","mode":"local","processId":30834,"trace":"log","packagePathToGoModPathMap":{"/home/ethereum/go/src/github.com/tendermint/tendermint/state":"/home/ethereum/go/src/github.com/tendermint/tendermint","/home/ethereum/go/src/github.com/tendermint/tendermint/node":"/home/ethereum/go/src/github.com/tendermint/tendermint","/home/ethereum/go/src/github.com/tendermint/tendermint/consensus":"/home/ethereum/go/src/github.com/tendermint/tendermint","/home/ethereum/go/src/github.com/tendermint/tendermint/.vscode":"/home/ethereum/go/src/github.com/tendermint/tendermint",".":"","/tmp":""},"env":{"GOPATH":"/home/ethereum/go","ELECTRON_RUN_AS_NODE":"1","USER":"ethereum","SSH_AGENT_PID":"2461","HOME":"/home/ethereum","QT4_IM_MODULE":"xim","GNOME_SHELL_SESSION_MODE":"ubuntu","GTK_MODULES":"gail:atk-bridge","DBUS_SESSION_BUS_ADDRESS":"unix:path=/run/user/1000/bus","PULSE_SCRIPT":"/etc/xrdp/pulse/default.pa","LOGNAME":"ethereum","GTK_IM_MODULE":"ibus","XDG_SESSION_ID":"c2","PATH":"/home/ethereum/.local/bin:/sbin:/bin:/usr/bin:/usr/local/bin:/snap/bin:/usr/local/go/bin:/usr/local/go/bin:/usr/local/go/bin:/usr/local/go/bin:/home/ethereum/go/bin:/home/ethereum/.local/bin","XRDP_SOCKET_PATH":"/var/run/xrdp/sockdir","XDG_RUNTIME_DIR":"/run/user/1000","DISPLAY":":10.0","LANG":"en_IN","XDG_CURRENT_DESKTOP":"Unity","XMODIFIERS":"@im=ibus","UID":"1000","SSH_AUTH_SOCK":"/run/user/1000/keyring/ssh","SHELL":"/bin/bash","QT_ACCESSIBILITY":"1","XRDP_SESSION":"1","GPG_AGENT_INFO":"/run/user/1000/gnupg/S.gpg-agent:0:1","QT_IM_MODULE":"xim","PWD":"/home/ethereum","XDG_DATA_DIRS":"/usr/share/gnome:/usr/share/ubuntu:/usr/local/share:/usr/share:/var/lib/snapd/desktop","XDG_CONFIG_DIRS":"/etc/xdg/xdg-ubuntu:/etc/xdg","CLUTTER_IM_MODULE":"xim","GNOME_DESKTOP_SESSION_ID":"this-is-deprecated","XDG_MENU_PREFIX":"gnome-","SESSION_MANAGER":"local/ethereum:@/tmp/.ICE-unix/2393,unix/ethereum:/tmp/.ICE-unix/2393","GIO_LAUNCHED_DESKTOP_FILE":"/usr/share/applications/code.desktop","GIO_LAUNCHED_DESKTOP_FILE_PID":"29849","GJS_DEBUG_OUTPUT":"stderr","GJS_DEBUG_TOPICS":"JS ERROR;JS LOG","NO_AT_BRIDGE":"1","CHROME_DESKTOP":"code-url-handler.desktop","VSCODE_NLS_CONFIG":"{\"locale\":\"en-gb\",\"availableLanguages\":{},\"_languagePackSupport\":true}","VSCODE_NODE_CACHED_DATA_DIR":"/home/ethereum/.config/Code/CachedData/c47d83b293181d9be64f27ff093689e8e7aed054","VSCODE_LOGS":"/home/ethereum/.config/Code/logs/20200311T163535","VSCODE_IPC_HOOK":"/run/user/1000/vscode-faaa7b3a-1.42.1-main.sock","VSCODE_PID":"29849","GL_DEBUG":"linters_output","GOPACKAGESPRINTGOLISTERRORS":"1","GOROOT":"/usr/local/go","LESSCLOSE":"/bin/lesspipe %s %s","LESSOPEN":"| /bin/lesspipe %s","LS_COLORS":"","SHLVL":"1","_":"/usr/share/code/code","AMD_ENTRYPOINT":"vs/workbench/services/extensions/node/extensionHostProcess","PIPE_LOGGING":"true","VERBOSE_LOGGING":"true","VSCODE_IPC_HOOK_EXTHOST":"/tmp/vscode-ipc-972dcaf6-f8a8-4cde-809e-d3edf9f6a5f2.sock","VSCODE_HANDLES_UNCAUGHT_ERRORS":"true","VSCODE_LOG_STACK":"false","APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL":"true","GOPROXY":"https://proxy.golang.org,direct"},"apiVersion":2,"dlvLoadConfig":{"followPointers":true,"maxVariableRecurse":1,"maxStringLen":64,"maxArrayValues":64,"maxStructFields":-1},"showGlobalVariables":true,"cwd":"/home/ethereum/go/src/github.com/tendermint/tendermint","dlvToolPath":"/home/ethereum/go/bin/dlv","currentFile":false,"__sessionId":"020b22be-94c2-4395-a521-18db82ebc783"})
[07:00:16.822 UTC] Current working directory: /home/ethereum/go/src/github.com/tendermint
[07:00:16.822 UTC] Running: /home/ethereum/go/bin/dlv attach 30834 --headless=true --listen=127.0.0.1:40048 --api-version=2 --wd=/home/ethereum/go/src/github.com/tendermint/tendermint
[07:00:16.829 UTC] To client: {"seq":0,"type":"event","event":"output","body":{"category":"stdout","output":"API server listening at: 127.0.0.1:40048\n"}}
[07:00:16.830 UTC] To client: {"seq":0,"type":"event","event":"output","body":{"category":"stderr","output":"Could not attach to pid 30834: this could be caused by a kernel security setting, try writing \"0\" to /proc/sys/kernel/yama/ptrace_scope\n"}}
[07:00:16.831 UTC] [Error] Process exiting with code: 1
[07:00:16.832 UTC] To client: {"seq":0,"type":"response","request_seq":2,"command":"attach","success":false,"message":"Failed to continue: Check the debug console for details.","body":{"error":{"id":3000,"format":"Failed to continue: Check the debug console for details.","showUser":true}}}
[07:00:16.832 UTC] Sending TerminatedEvent as delve is closed
[07:00:16.832 UTC] To client: {"seq":0,"type":"event","event":"terminated"}
[07:00:16.854 UTC] From client: disconnect({"restart":false})
[07:00:16.854 UTC] DisconnectRequest
[07:00:16.854 UTC] HaltRequest

Screenshots or recordings

If applicable, add screenshots or recordings to help explain your problem.

@hyangah
Copy link
Contributor

hyangah commented Mar 17, 2020

This is because Yama blocks ptrace attach. https://www.kernel.org/doc/Documentation/security/Yama.txt

Please try to do what the error message says

Could not attach to pid:30834 this could be caused by a kernel security setting, try writing "0" to /proc/sys/kernel/yama/ptrace_scope

E.g. echo 0 > /proc/sys/kernel/yama/ptrace_scope

@hyangah
Copy link
Contributor

hyangah commented Apr 3, 2020

@Anjana-Prabhakar did you manage to solve the problem?

@stamblerre @ramya-rao-a can you mark this as needs more info? Thanks!

@Anjana-Prabhakar
Copy link
Author

Anjana-Prabhakar commented Apr 4, 2020 via email

@festum
Copy link

festum commented May 27, 2020

I have this same issue. tried echo 0|sudo tee /proc/sys/kernel/yama/ptrace_scope then stuck with could not attach to pid 74570: could not open debug info.

config:

{
	"version": "0.2.0",
	"configurations": [
		{
			"name": "Attach",
			"type": "go",
			"request": "attach",
			"mode": "local",
			"processId":74570,
		}
	]
}

@hyangah
Copy link
Contributor

hyangah commented May 27, 2020

@festum As the error message indicates, that is a different issue. Is your binary compiled with optimization disabled?
go-delve/delve#1698 (comment)

@vscodebot
Copy link

vscodebot bot commented Jun 3, 2020

This issue has been closed automatically because it needs more information and has not had recent activity. Thank you for your contributions.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants