# Strace attach problem

**URL:** <https://linux-tips.com/t/strace-attach-problem/99>\
**Category:** Kernel\
**Created:** [March 3, 2015, 3:06pm UTC](https://linux-tips.com/t/strace-attach-problem/99 "2015-03-03T15:06:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Greg](https://linux-tips.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@Greg](https://linux-tips.com/u/Greg)\
**Post date:** [March 3, 2015, 3:06pm UTC](https://linux-tips.com/t/strace-attach-problem/99/1 "2015-03-03T15:06:25Z")

</div>

I’m using `strace` regularly and I’m a very big fan of this little utility.

But I can not use strace to trace my program in one of the server which I’m connecting remotely. It gives following error:

```
$ strace -p 3184
strace: attach: ptrace(PTRACE_ATTACH, ...): Operation not permitted

```

How can I solve this problem?

---

<div class="post-metadata">

**Author:** ![demirten](https://linux-tips.com/user_avatar/linux-tips.com/demirten/32/64_2.png) [@demirten](https://linux-tips.com/u/demirten)\
**Post date:** [March 3, 2015, 4:11pm UTC](https://linux-tips.com/t/strace-attach-problem/99/2 "2015-03-03T16:11:41Z")

</div>

In good old days we don’t have much malwares in Linux systems. But when the popularity of Linux increased, similarly malwares and trojans also increased too.

In a traditional Unix like system, `ptrace` system call allows any process can trace and take control of other processes which has ability to send signal to it. This system call exists from **4.3BSD** and **SVr4**.

As a negative effect of this system call, if a malware exists in your system, it can take full control of all other running processes which has permission to send signal and capture sensitive information from your system.

This is not a bug, it is a design issue. It is also possible to prevent your program being traced by using Linux specific `prctl` call and clear `PR_SET_DUMPABLE` flag, which OpenSSH agent in your system already does.

But, not many programmers aware of this behaviour. So, when looking at the Linux distributions perspective, it is good to activate additional protection mechanism on `ptrace` system call to make more secure system without need to change of any software code.

Newer Linux kernels has the Yama security module. When the Yama is built into the kernel, its behaviour can be changed through `/proc/sys/kernel/yama/ptrace_scope` file.

If you’re trying to use strace to attach another process which is also belongs to you but you’re not a parent of it and the value in `ptrace_scope` file greater than **0** , it is normal to get “Operation not permitted” error.

Some recent Linux distributions sets `ptrace_scope` value to **1** in default. You can still use strace in this scenario with starting the programs with strace like below:

```
$ strace ./my_prog

```

but you can not attach a process which is already started and has different parent of your newly executed strace.

You can learn other values of `ptrace_scope` and vulnerabilities of current implementation from: [https://www.kernel.org/doc/Documentation/security/Yama.txt](https://www.kernel.org/doc/Documentation/security/Yama.txt)
