Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I found some surprising behavior on Ubuntu 14.04 when using strace on an executable, which I do not have read permission on. I wonder if this is a bug, or if some standard mandates this obscure behavior.

First let's see what happens when I start an ordinary executable in the background and attach to it. As expected this works:

$ /bin/sleep 100 &
[2] 8078
$ strace -p 8078
Process 8078 attached
restart_syscall(<... resuming interrupted call ...>

Next I try with an executable, which I have no read permissions on:

---x--x--x 1 root root 26280 Sep  3 09:37 sleep*

Attaching to this running process is not permitted:

$ ./sleep 100 &
[1] 8089
$ strace -p 8089
strace: attach: ptrace(PTRACE_ATTACH, ...): Operation not permitted

This is also what I would expect. Granting execute permission without read permission wouldn't do much good, if I could simply attach a debugger to the process and effectively have read permissions on the executable that way.

But if I start the executable under an already traced process, I am permitted to do so:

$ strace ./sleep 100
execve("./sleep", ["./sleep", "100"], [/* 69 vars */]) = 0
brk(0)                                  = 0x9b7a000

This is unexpected for me. Is this a security bug, or is it a feature mandated by a standard?

share|improve this question
1  
@StéphaneChazelas: The point is that he can ptrace it, by simply using it as argument to strace. The root cause seems to be that on execve calls, read permissions of the executed file are not checked again if the process is already traced. His question is whether that is a security bug or a mandated feature (if the latter, I'd still consider it a security bug, just a security bug of the specification). –  celtschk Sep 3 at 9:05
    
@celtschk, sorry, I read the question too quickly. –  Stéphane Chazelas Sep 3 at 9:15
    
The EPERM seems to come from get_dumpable() (used also to check whether core dumping is allowed, thus "dumpable") called from __ptrace_may_access() called from ptrace_attach() on kernel/ptrace.c. –  ninjalj Sep 3 at 10:06
    
When a program is running, will sufficient information be available to the debugger to generate a runnable executable containing its code, or will the program loader discard things like relocation fixups which would be needed to make a program actually work? –  supercat 2 days ago
    
@supercat As far as I know, the debugger has access to single step through all the user mode code being executed, including the relocation code. With that level of access it shouldn't be too difficult to reproduce a working executable. –  kasperd 2 days ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.