Skip to content

Commit 194c2e0

Browse files
cgwalterssunfishcode
authored andcommitted
procfs: Don't try to validate the uid/gid of /proc
I typically develop inside a https://github.com/containers/toolbox/ container. In this scenario: ``` $ ls -ald /proc dr-xr-xr-x. 526 nobody nobody 0 Jan 12 14:47 /proc $ ``` And that's expected and normal; the real root uid from outside the user namespace is mapped to `nobody`; distinct from the uid 0 inside the userns. Honestly, I am still somewhat skeptical of the value of all of these checks. We're already validating that `/proc`'s filesystem magic is `PROC_SUPER_MAGIC` - that seems really more than sufficient.
1 parent 9b99d3b commit 194c2e0

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/io/procfs.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const PROC_ROOT_INO: u64 = 1;
3535

3636
// Identify an entry within "/proc", to determine which anomalies to
3737
// check for.
38+
#[derive(Debug)]
3839
enum Kind {
3940
Proc,
4041
Pid,
@@ -72,9 +73,13 @@ fn check_proc_entry_with_stat(
7273
Kind::File => check_proc_file(&entry_stat, proc_stat)?,
7374
}
7475

75-
// Check the ownership of the directory.
76-
if (entry_stat.st_uid, entry_stat.st_gid) != (uid, gid) {
77-
return Err(io::Error::NOTSUP);
76+
// Check the ownership of the directory. We can't do that for the toplevel /proc
77+
// though, because in e.g. a user namespace scenario, root outside the container
78+
// may be mapped to another uid like `nobody`.
79+
if !matches!(kind, Kind::Proc) {
80+
if (entry_stat.st_uid, entry_stat.st_gid) != (uid, gid) {
81+
return Err(io::Error::NOTSUP);
82+
}
7883
}
7984

8085
// "/proc" directories are typically mounted r-xr-xr-x.

tests/io/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ mod isatty;
2020
mod mmap;
2121
#[cfg(not(windows))]
2222
mod poll;
23+
#[cfg(all(feature = "procfs", any(target_os = "android", target_os = "linux")))]
24+
mod procfs;
2325
#[cfg(not(windows))]
2426
mod prot;
2527
#[cfg(not(windows))]

tests/io/procfs.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use io_lifetimes::raw::AsRawFilelike;
2+
3+
#[test]
4+
fn test_proc_self() {
5+
// Verify that this API works at all
6+
let fd = rustix::io::proc_self_fd().unwrap();
7+
assert_ne!(fd.as_raw_filelike(), 0);
8+
}

0 commit comments

Comments
 (0)