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

Allow signal injection in ptrace::syscall and ptrace::detach #1083

Merged
merged 1 commit into from Dec 1, 2019

Conversation

frangio
Copy link
Contributor

@frangio frangio commented Jun 9, 2019

Fixes #1049

Should I add tests for this functionality?

By the way, I noticed that the BSD module doesn't have ptrace::syscall. I couldn't find a reason behind this in #949. Should we add it?

@asomers
Copy link
Member

asomers commented Jun 11, 2019

Tests: yes please. Especially for ptrace, which is very difficult to use correctly. I can't figure out a good reason why BSD lacks ptrace::syscall either. Adding that would be appreciated. If you do it, please do it in a separate commit. Also, what about PTRACE_CONT? Can't it inject signals too?

@frangio
Copy link
Contributor Author

frangio commented Jun 11, 2019

Yes, cont and step can also inject signals, but this was already present in the nix API. Not sure why that was done inconsistently.

@frangio
Copy link
Contributor Author

frangio commented Jun 17, 2019

I've added tests now, but restricted them to Linux only, because the functions needed to test it are only available there...

@frangio frangio force-pushed the ptrace-signal-injection branch 2 times, most recently from c1a07b9 to f4dfc96 Compare June 18, 2019 01:41
@frangio
Copy link
Contributor Author

frangio commented Jun 18, 2019

I removed my implementation of ptrace::syscall for BSD. The build had failed and when I looked into it I found that not all BSDs have this part of the ptrace API, and among those who have it it looks like it works differently. I'll open an issue so that someone more knowledgeable in BSD can work on it.

src/sys/ptrace/bsd.rs Outdated Show resolved Hide resolved
src/sys/ptrace/linux.rs Outdated Show resolved Hide resolved
test/sys/test_ptrace.rs Outdated Show resolved Hide resolved

// inject signal
ptrace::syscall(child, Signal::SIGTERM).unwrap();
assert_eq!(waitpid(child, None), Ok(WaitStatus::Signaled(child, Signal::SIGTERM, false)));
Copy link
Member

Choose a reason for hiding this comment

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

So the child sends SIGTERM to itself, and you inject it here? Why two places?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's just how ptrace works. It intercepts signal delivery and allows the tracer to decide whether the child will actually receive the signal or not. The mechanism to do that is signal injection. (It's a bad name, and a bad mechanism tbh.) If you don't inject the signal that was intercepted, it won't be delivered at all.

@frangio
Copy link
Contributor Author

frangio commented Jun 20, 2019

This is very weird, the tests are failing in the CI but not in my machine. I'll keep looking into it.

@frangio
Copy link
Contributor Author

frangio commented Jun 28, 2019

CI is green now!

@asomers
Copy link
Member

asomers commented Jul 1, 2019

Due to an upstream problem with the tempfile crate, you'll have to rebase.

@frangio
Copy link
Contributor Author

frangio commented Jul 1, 2019

@asomers Done!

@MikailBag
Copy link
Contributor

I would like to use signal injection with PTRACE_SYSCALL.
While it is not hard to manually call libc::ptrace, I'd like to see this PR merged.

@frangio
Copy link
Contributor Author

frangio commented Oct 28, 2019

Is there anything pending on my end?

@asomers
Copy link
Member

asomers commented Oct 28, 2019

Sorry that this dropped off of my radar. I should have some time this week to look at it.

Copy link
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

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

Don't forget to add a CHANGELOG entry, too.

test/sys/test_ptrace.rs Show resolved Hide resolved
test/sys/test_ptrace.rs Outdated Show resolved Hide resolved
@frangio
Copy link
Contributor Author

frangio commented Oct 30, 2019

Done! Please let me know if the changelog entry looks ok.

Copy link
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

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

Ok, Looks good! Now it just needs a squash.

@frangio
Copy link
Contributor Author

frangio commented Nov 7, 2019

Should be done!

Copy link
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

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

bors r+

@bors
Copy link
Contributor

bors bot commented Nov 17, 2019

Merge conflict

@asomers
Copy link
Member

asomers commented Nov 24, 2019

I'm sorry, but you'll have to rebase again. And be sure to rebase; don't merge master into your branch.

@frangio
Copy link
Contributor Author

frangio commented Dec 1, 2019

@asomers Done.

Copy link
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

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

bors r+

bors bot added a commit that referenced this pull request Dec 1, 2019
1083: Allow signal injection in ptrace::syscall and ptrace::detach r=asomers a=frangio

Fixes #1049

Should I add tests for this functionality?

By the way, I noticed that the BSD module doesn't have `ptrace::syscall`. I couldn't find a reason behind this in #949. Should we add it?

Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
@bors
Copy link
Contributor

bors bot commented Dec 1, 2019

Build succeeded

@bors bors bot merged commit 7f3ee09 into nix-rust:master Dec 1, 2019
@frangio frangio deleted the ptrace-signal-injection branch December 1, 2019 13:33
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.

Some ptrace functions don't allow signal injection
3 participants