Skip to content

Commit 856f841

Browse files
committed
Make ptrace::write unsafe on Linux
It always should've been unsafe, because it dereferences a user-provided pointer.
1 parent 465a8f7 commit 856f841

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
3434
- Changed `fallocate` return type from `c_int` to `()` (#[1201](https://github.com/nix-rust/nix/pull/1201))
3535
- Enabled `sys::ptrace::setregs` and `sys::ptrace::getregs` on x86_64-unknown-linux-musl target
3636
(#[1198](https://github.com/nix-rust/nix/pull/1198))
37+
- On Linux, `ptrace::write` is now an `unsafe` function. Caveat programmer.
38+
(#[1245](https://github.com/nix-rust/nix/pull/1245))
3739

3840
### Fixed
3941

src/sys/ptrace/linux.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,15 @@ pub fn read(pid: Pid, addr: AddressType) -> Result<c_long> {
425425
}
426426

427427
/// Writes a word into the processes memory at the given address
428-
pub fn write(pid: Pid, addr: AddressType, data: *mut c_void) -> Result<()> {
429-
unsafe {
430-
ptrace_other(Request::PTRACE_POKEDATA, pid, addr, data).map(drop)
431-
}
428+
///
429+
/// # Safety
430+
///
431+
/// The `data` argument is passed directly to `ptrace(2)`. Read that man page
432+
/// for guidance.
433+
pub unsafe fn write(
434+
pid: Pid,
435+
addr: AddressType,
436+
data: *mut c_void) -> Result<()>
437+
{
438+
ptrace_other(Request::PTRACE_POKEDATA, pid, addr, data).map(drop)
432439
}

0 commit comments

Comments
 (0)