Skip to content

Commit ce1151c

Browse files
authored
Rollup merge of rust-lang#97837 - sunfishcode:sunfishcode/proc-self-mem, r=m-ou-se
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.
2 parents 2807f28 + 6959441 commit ce1151c

File tree

1 file changed

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

1 file changed

+19
-0
lines changed

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

+19
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,25 @@
5454
//! Like boxes, `OwnedFd` values conceptually own the resource they point to,
5555
//! and free (close) it when they are dropped.
5656
//!
57+
//! ## `/proc/self/mem` and similar OS features
58+
//!
59+
//! Some platforms have special files, such as `/proc/self/mem`, which
60+
//! provide read and write access to the process's memory. Such reads
61+
//! and writes happen outside the control of the Rust compiler, so they do not
62+
//! uphold Rust's memory safety guarantees.
63+
//!
64+
//! This does not mean that all APIs that might allow `/proc/self/mem`
65+
//! to be opened and read from or written must be `unsafe`. Rust's safety guarantees
66+
//! only cover what the program itself can do, and not what entities outside
67+
//! the program can do to it. `/proc/self/mem` is considered to be such an
68+
//! external entity, along with debugging interfaces, and people with physical access to
69+
//! the hardware. This is true even in cases where the program is controlling
70+
//! the external entity.
71+
//!
72+
//! If you desire to comprehensively prevent programs from reaching out and
73+
//! causing external entities to reach back in and violate memory safety, it's
74+
//! necessary to use *sandboxing*, which is outside the scope of `std`.
75+
//!
5776
//! [`BorrowedFd<'a>`]: crate::os::unix::io::BorrowedFd
5877
5978
#![stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)