-
Notifications
You must be signed in to change notification settings - Fork 697
Mark nix::sys::ptrace::ptrace as unsafe, add safe variants of some routines #709
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b03011f
Mark nix::sys::ptrace::ptrace as unsafe, add safe variants of source …
marmistrz 843eeb0
Improve the documentation of wrappers.
marmistrz 0fbac87
support delivering a signal with ptrace::cont
marmistrz 5510bf2
Add tests for ptrace::cont
marmistrz 9e0d241
Possibly fix tests failing on qemu architectures.
marmistrz c65b5ba
Add a line break.
marmistrz cf3c2ad
Extra doc
marmistrz 932f6e0
Reword the comment.
marmistrz f4a0099
Update changelog
marmistrz 9ad235c
Refactor the changelog
marmistrz ebcedb3
Merge remote-tracking branch 'upstream/master' into ptrace-noreg
marmistrz 0587977
Deprecate `ptrace`.
marmistrz d8968f4
Merge remote-tracking branch 'upstream/master' into ptrace-noreg
marmistrz abcec0f
Remove the incorrect doc comment.
marmistrz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,14 +3,13 @@ use nix::errno::Errno; | |
use nix::unistd::getpid; | ||
use nix::sys::ptrace; | ||
|
||
use std::{mem, ptr}; | ||
use std::mem; | ||
|
||
#[test] | ||
fn test_ptrace() { | ||
use nix::sys::ptrace::ptrace::PTRACE_ATTACH; | ||
// Just make sure ptrace can be called at all, for now. | ||
// FIXME: qemu-user doesn't implement ptrace on all arches, so permit ENOSYS | ||
let err = ptrace::ptrace(PTRACE_ATTACH, getpid(), ptr::null_mut(), ptr::null_mut()).unwrap_err(); | ||
let err = ptrace::attach(getpid()).unwrap_err(); | ||
assert!(err == Error::Sys(Errno::EPERM) || err == Error::Sys(Errno::ENOSYS)); | ||
} | ||
|
||
|
@@ -47,3 +46,44 @@ fn test_ptrace_setsiginfo() { | |
_ => (), | ||
} | ||
} | ||
|
||
|
||
#[test] | ||
fn test_ptrace_cont() { | ||
use nix::sys::ptrace; | ||
use nix::sys::signal::{raise, Signal}; | ||
use nix::sys::wait::{waitpid, WaitStatus}; | ||
use nix::unistd::fork; | ||
use nix::unistd::ForkResult::*; | ||
|
||
// FIXME: qemu-user doesn't implement ptrace on all arches and gives ENOSYS then. | ||
// use it to filter out the affected platforms | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both of these comments could use proper punctuation and capitalization. |
||
// on valid platforms it will return Errno::EPERM | ||
let err = ptrace::attach(getpid()).unwrap_err(); | ||
if err == Error::Sys(Errno::ENOSYS) { | ||
return; | ||
} | ||
|
||
match fork() { | ||
Ok(Child) => { | ||
ptrace::traceme().unwrap(); | ||
// As recommended by ptrace(2), raise SIGTRAP to pause the child | ||
// until the parent is ready to continue | ||
loop { | ||
raise(Signal::SIGTRAP).unwrap(); | ||
} | ||
|
||
}, | ||
Ok(Parent { child }) => { | ||
assert_eq!(waitpid(child, None), Ok(WaitStatus::Stopped(child, Signal::SIGTRAP))); | ||
ptrace::cont(child, None).unwrap(); | ||
assert_eq!(waitpid(child, None), Ok(WaitStatus::Stopped(child, Signal::SIGTRAP))); | ||
ptrace::cont(child, Signal::SIGKILL).unwrap(); | ||
match waitpid(child, None) { | ||
Ok(WaitStatus::Signaled(pid, Signal::SIGKILL, _)) if pid == child => {} | ||
_ => panic!("The process should have been killed"), | ||
} | ||
}, | ||
Err(_) => panic!("Error: Fork Failed") | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be expanded to report
UnsupportedOperation
for all 4 added specialized functions.Also, what are the specific usecases of
ptrace
that will generate unsafety as Rust defines it (crashing isn't necessarily unsafe)? Since you pulled this out of another PR, I don't know where that discussion went.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And thus break the specialized functions:
ptrace::syscall
callsptrace::ptrace
withrequest=PTRACE_SYSCALL
.ptrace
can dereference arbitrary pointer in the child process memory.