Lines Matching full:proc
1 //! Utilities for working with `/proc`, where Linux's `procfs` is typically
2 //! mounted. `/proc` serves as an adjunct to Linux's main syscall surface area,
5 //! This module does a considerable amount of work to determine whether `/proc`
36 // Identify an entry within "/proc", to determine which anomalies to check for.
39 Proc, enumerator
45 /// Check a subdirectory of "/proc" for anomalies.
55 /// Check a subdirectory of "/proc" for anomalies, using the provided `Stat`.
66 Kind::Proc => check_proc_root(entry, &entry_stat)?, in check_proc_entry_with_stat()
71 // "/proc" directories are typically mounted r-xr-xr-x. in check_proc_entry_with_stat()
72 // "/proc/self/fd" is r-x------. Allow them to have fewer permissions, but in check_proc_entry_with_stat()
81 // Check that the "/proc/self/fd" directory doesn't have any extraneous in check_proc_entry_with_stat()
87 Kind::Pid | Kind::Proc => { in check_proc_entry_with_stat()
88 // Check that the "/proc" and "/proc/self" directories aren't empty. in check_proc_entry_with_stat()
106 // We use `O_DIRECTORY` for proc directories, so open should fail if we in check_proc_root()
115 // Proc is a non-device filesystem, so check for major number 0. in check_proc_root()
121 // Check that "/proc" is a mountpoint. in check_proc_root()
134 // We use `O_DIRECTORY` for proc directories, so open should fail if we in check_proc_subdir()
140 // Check that subdirectories of "/proc" are not mount points. in check_proc_subdir()
160 // Check that we haven't been linked back to the root of "/proc". in check_proc_nonroot()
196 /// Open a directory in `/proc`, mapping all errors to `io::Errno::NOTSUP`.
204 /// Returns a handle to Linux's `/proc` directory.
206 /// This ensures that `/proc` is procfs, that nothing is mounted on top of it,
207 /// and that it looks normal. It also returns the `Stat` of `/proc`.
212 /// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html
213 fn proc() -> io::Result<(BorrowedFd<'static>, &'static Stat)> { in proc() function
214 static PROC: StaticFd = StaticFd::new(); in proc() variable
219 PROC.get_or_try_init(|| { in proc()
220 // Open "/proc". in proc()
221 let proc = proc_opendirat(cwd(), cstr!("/proc"))?; in proc() localVariable
223 check_proc_entry(Kind::Proc, proc.as_fd(), None).map_err(|_err| io::Errno::NOTSUP)?; in proc()
225 Ok(new_static_fd(proc, proc_stat)) in proc()
230 /// Returns a handle to Linux's `/proc/self` directory.
232 /// This ensures that `/proc/self` is procfs, that nothing is mounted on top of
233 /// it, and that it looks normal. It also returns the `Stat` of `/proc/self`.
238 /// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html
245 let (proc, proc_stat) = proc()?; in proc_self()
249 // Open "/proc/self". Use our pid to compute the name rather than literally in proc_self()
251 let proc_self = proc_opendirat(proc, DecInt::new(pid.as_raw_nonzero().get()))?; in proc_self()
260 /// Returns a handle to Linux's `/proc/self/fd` directory.
262 /// This ensures that `/proc/self/fd` is `procfs`, that nothing is mounted on
268 /// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html
276 let (_, proc_stat) = proc()?; in proc_self_fd()
280 // Open "/proc/self/fd". in proc_self_fd()
298 /// Returns a handle to Linux's `/proc/self/fdinfo` directory.
300 /// This ensures that `/proc/self/fdinfo` is `procfs`, that nothing is mounted
302 /// `/proc/self/fd`.
307 /// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html
313 let (_, proc_stat) = proc()?; in proc_self_fdinfo()
317 // Open "/proc/self/fdinfo". in proc_self_fdinfo()
328 /// Returns a handle to a Linux `/proc/self/fdinfo/<fd>` file.
330 /// This ensures that `/proc/self/fdinfo/<fd>` is `procfs`, that nothing is
336 /// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html
349 /// Returns a handle to a Linux `/proc/self/pagemap` file.
351 /// This ensures that `/proc/self/pagemap` is `procfs`, that nothing is
358 /// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html
366 /// Returns a handle to a Linux `/proc/self/maps` file.
368 /// This ensures that `/proc/self/maps` is `procfs`, that nothing is
374 /// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html
381 /// Returns a handle to a Linux `/proc/self/status` file.
383 /// This ensures that `/proc/self/status` is `procfs`, that nothing is
389 /// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html
396 /// Open a file under `/proc/self`.
404 let (_, proc_stat) = proc()?; in open_and_check_file()
408 // `/proc/<pid>` files [to root:root]. in open_and_check_file()
411 // [to root:root]: https://man7.org/linux/man-pages/man5/proc.5.html in open_and_check_file()