Skip to content

Commit 5ae95fa

Browse files
committed
Document Rust's stance on /proc/self/mem
Add documentation to `std::os::unix::io` describing Rust's stance on `/proc/self/mem`, treating it as an external entity which is outside the scope of Rust's safety guarantees.
1 parent 3a8e713 commit 5ae95fa

File tree

1 file changed

+20
-0
lines changed
  • library/std/src/os/unix/io

1 file changed

+20
-0
lines changed

library/std/src/os/unix/io/mod.rs

+20
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,26 @@
4444
//! Like boxes, `OwnedFd` values conceptually own the resource they point to,
4545
//! and free (close) it when they are dropped.
4646
//!
47+
//! ## What about `/proc/self/mem` and similar OS features?
48+
//!
49+
//! Some platforms have a feature known as `/proc/self/mem`, which is a
50+
//! filesystem path that can be opened, producing a file descriptor that, when
51+
//! read from or written to, reads and writes the process's memory. These reads
52+
//! and writes happen outside the control of the Rust compiler, so they do not
53+
//! uphold Rust's memory safety guarantees.
54+
//!
55+
//! Does this mean that all APIs that might allow `/proc/self/mem` to be opened
56+
//! and read from or written to must be `unsafe`? No. Rust's safety guarantees
57+
//! only cover what the program itself can do, and not what entities outside
58+
//! the program can do to it. `/proc/self/mem` is considered to be such an
59+
//! external entity, along with debugggers and people with physical access to
60+
//! the hardware. This is true even in cases where the program is controling
61+
//! the external entity.
62+
//!
63+
//! If you desire to comprehensively prevent programs from reaching out and
64+
//! causing external entities to reach back in and violate memory safety, it's
65+
//! necessary to use *sandboxing*, which is outside the scope of `std`.
66+
//!
4767
//! [`BorrowedFd<'a>`]: crate::os::unix::io::BorrowedFd
4868
4969
#![stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)