ptrace attach fails on a phone, works on emulator

731 views
Skip to first unread message

Richard Quirk

unread,
May 28, 2011, 7:57:25 PM5/28/11
to android-ndk
Should the following work on a non-rooted, stock Froyo-running device?
I'm forking off a child process and attaching to the original parent
process using ptrace.

pid = fork();
if (pid == 0) {
pid = getppid(); /* get parent process id */
if (ptrace(PTRACE_ATTACH, pid, NULL, NULL) < 0) {
int i = errno;
__android_log_print(ANDROID_LOG_INFO, "whatever",
"child: could not attach %d (%d)", pid, i);
}
}

On an emulator running 2.2 I'm able to attach to the parent process
correctly, but on a regular phone it fails and gives errno==1,
"Operation Not Permitted".

The uid and gid are the same for both processes (of course, after a
fork..), and the child process has ptrace capabilities, or at least
prctl(PR_CAPBSET_READ, CAP_SYS_PTRACE, 0, 0, 0) as written in [1]
returns 1.

Any ideas on what else I can check?

[1] https://bug598155.bugzilla.mozilla.org/attachment.cgi?id=477044

fadden

unread,
Jun 2, 2011, 5:12:45 PM6/2/11
to android-ndk
On May 28, 4:57 pm, Richard Quirk <richard.qu...@gmail.com> wrote:
> Should the following work on a non-rooted, stock Froyo-running device?
[...]
> On an emulator running 2.2 I'm able to attach to the parent process
> correctly, but on a regular phone it fails and gives errno==1,
> "Operation Not Permitted".
>
> The uid and gid are the same for both processes (of course, after a
> fork..), and the child process has ptrace capabilities, or at least
> prctl(PR_CAPBSET_READ, CAP_SYS_PTRACE, 0, 0, 0) as written in [1]
> returns 1.


This doesn't work in stock 2.2 froyo; you have to be root.

Some changes were made to allow this to work in gingerbread.

Chris Stratton

unread,
Jun 3, 2011, 2:13:38 AM6/3/11
to andro...@googlegroups.com
On Thursday, June 2, 2011 5:12:45 PM UTC-4, fadden wrote:

> On an emulator running 2.2 I'm able to attach to the parent process
> correctly, but on a regular phone it fails and gives errno==1,
> "Operation Not Permitted".

This doesn't work in stock 2.2 froyo; you have to be root.

Some changes were made to allow this to work in gingerbread.

How did gdbserver work then?  I recall hearing about some problems, but thought the solution was recompile gdbserver, not 'root the device' ?


Reply all
Reply to author
Forward
0 new messages