gitlab.com/Raven-IO/raven-delve@v1.22.4/service/debugger/debugger_linux.go (about) 1 package debugger 2 3 import ( 4 "fmt" 5 "os" 6 "syscall" 7 ) 8 9 func init() { 10 attachErrorMessage = attachErrorMessageLinux 11 } 12 13 //lint:file-ignore ST1005 errors here can be capitalized 14 15 func attachErrorMessageLinux(pid int, err error) error { 16 fallbackerr := fmt.Errorf("could not attach to pid %d: %s", pid, err) 17 if serr, ok := err.(syscall.Errno); ok { 18 switch serr { 19 case syscall.EPERM: 20 bs, err := os.ReadFile("/proc/sys/kernel/yama/ptrace_scope") 21 if err == nil && len(bs) >= 1 && bs[0] != '0' { 22 // Yama documentation: https://www.kernel.org/doc/Documentation/security/Yama.txt 23 return fmt.Errorf("Could not attach to pid %d: this could be caused by a kernel security setting, try writing \"0\" to /proc/sys/kernel/yama/ptrace_scope", pid) 24 } 25 fi, err := os.Stat(fmt.Sprintf("/proc/%d", pid)) 26 if err != nil { 27 return fallbackerr 28 } 29 if fi.Sys().(*syscall.Stat_t).Uid != uint32(os.Getuid()) { 30 return fmt.Errorf("Could not attach to pid %d: current user does not own the process", pid) 31 } 32 } 33 } 34 return fallbackerr 35 }