Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed ptrace 'Operation not permitted' #15287

Merged
merged 2 commits into from
Oct 16, 2019

Conversation

yossizap
Copy link
Contributor

This issue is a result of running PT_ATTACH on a forked PID when you're only supposed to PT_ATTACH remote pids. linux_set_options probably always worked for you when testing in fork mode but it wouldn't work in remote attachment since you have to attach first + there's was error handling there.
When using fork_and_ptraceme_for_linux the child sets himself up to be traced for you.

I used GETSIGINFO to check the attachment status since it doesn't have any consequences(same result even if you run it multiple times) and always works on an attached process.

Also went ahead and cleaned up the code around the changes.

closes #14506

// Attaching to a process that has already been started with PTRACE_TRACEME.
// sets errno to "Operation not permitted" which may be misleading.
// GETSIGINFO can be called multiple times and would fail without attachment.
if (-1 == r_debug_ptrace(dbg, PTRACE_GETSIGINFO, ptid, NULL,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing space before ( and piut the == -1 in the right side of the statement

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

// GETSIGINFO can be called multiple times and would fail without attachment.
if (-1 == r_debug_ptrace(dbg, PTRACE_GETSIGINFO, ptid, NULL,
(r_ptrace_data_t)&sig)) {
if (-1 == r_debug_ptrace (dbg, PTRACE_ATTACH, ptid, NULL,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Copy link
Collaborator

@radare radare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@radare radare merged commit f6bda32 into radareorg:master Oct 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

radare2 : debug error
2 participants