

strace: operation not permitted, ptrace_scope incorrect
source link: https://ma.ttias.be/strace-operation-not-permitted-ptrace_scope-incorrect/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

strace: operation not permitted, ptrace_scope incorrect
Mattias Geniar, October 22, 2019
Follow me on Twitter as @mattiasgeniar
When using strace
on a server, you might get this error message when you try to attach to a running process.
$ strace -f -p 13239
strace: attach: ptrace(PTRACE_SEIZE, 13239): Operation not permitted
strace: Could not attach to process. If your uid matches the uid of the target process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try again as the root user. For more details, see /etc/sysctl.d/10-ptrace.conf: Operation not permitted
Alas, it doesn’t work!
Here’s why: your current user doesn’t have permissions to trace a running process. Here are some workarounds.
Strace a new process instead
If you have the ability, you can strace
a new program instead. This might not always be an option, but it works like this.
$ strace -f ./binary
You’d start ./binary
again and strace that process.
Get root access
Alternative, get root level privileges to strace running processes. Makes sense, but might not always be an option in your environment.
Allow users to strace other processes with the same uid
You can also change a setting to allow a user to strace processes that have the same uid. In other words: allow a user to strace a processes from itself.
To do so, it requires a root-level change (aka: a root level admin needs to change this).
Have a look at the file /etc/sysctl.d/10-ptrace.conf
$ cat /etc/sysctl.d/10-ptrace.conf # The PTRACE system is used for debugging. With it, a single user process # can attach to any other dumpable process owned by the same user. In the # case of malicious software, it is possible to use PTRACE to access # credentials that exist in memory (re-using existing SSH connections, # extracting GPG agent information, etc). # # A PTRACE scope of "0" is the more permissive mode. A scope of "1" limits # PTRACE only to direct child processes (e.g. "gdb name-of-program" and # "strace -f name-of-program" work, but gdb's "attach" and "strace -fp $PID" # do not). The PTRACE scope is ignored when a user has CAP_SYS_PTRACE, so # "sudo strace -fp $PID" will work as before. For more details see: # https://wiki.ubuntu.com/SecurityTeam/Roadmap/KernelHardening#ptrace # # For applications launching crash handlers that need PTRACE, exceptions can # be registered by the debugee by declaring in the segfault handler # specifically which process will be using PTRACE on the debugee: # prctl(PR_SET_PTRACER, debugger_pid, 0, 0, 0); # # In general, PTRACE is not needed for the average running Ubuntu system. # To that end, the default is to set the PTRACE scope to "1". This value # may not be appropriate for developers or servers with only admin accounts. kernel.yama.ptrace_scope = 1
If you change kernel.yama.ptrace_scope
to 0 and reboot the system, you’ll now be allowed to strace processes of your own uid.
Recommend
-
42
The ptrace(2) (“process trace”) system call is usually associated with debugging. It’s the primary mechanism through which native debuggers monitor debuggees on unix-like systems. It’s also the usual appr...
-
92
写在前面的话 ptrace(2)这个系统调用一般都跟调试离不开关系,它不仅是类Unix系统中本地调试器监控实现的主要机制,而且它还是strace系统调用常用的实现方法。ptrace()系统调用函数提供了一个进程(the “tracer”)监察和控制...
-
24
A year ago, Benjamin "Mako" Hill gave a groundbreaking lecture explaining how Big Tech companies had managed to monopolize all the benefits of free software licenses, using a combination of dirty tricks to ensure that the tools that were nominal...
-
33
Poor man’s Table of Content: How does one use ptrace ? How can this be put into Redox? Introduction I got selected for RSoC the second time i...
-
39
利用ptrace和memfd_create混淆程序名和参数 ...
-
7
macOS Operation Not Permitted?2021-08-15Mac197 words 1 min read 5 times readSome permission related issue on macOS.File lock issueFor so...
-
20
How to solve delete file "Operation not permitted" on LinuxSometimes it is necessary to prevent all users including root from deleting a file. This is often done by changing the file attributes on a Linux file system. The tool used to change...
-
13
[解決済み] php:*-alpine のdocker buildで、`make: /bin/sh: Operation not permitted` エラーが発生する はじめに(何が問題か) 以下のようなDockerfileをビルドすると、 FROM php...
-
9
adb push error: remote couldn't create file: Operation not permitted January 02, 2022...
-
12
Micheal Mathews December 29, 2020 7 minute read...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK