Skip to content

Commit a2d100e

Browse files
vmagrometa-codesync[bot]
authored andcommitted
[S597085][antlir2][isolate] fallback to bind-mounting /proc
Summary: If we get an `EPERM` while mounting `/proc`, try to fall back to a bind mount. A small number of RPM scriptlets might choke on this, but this will give the build a better chance of succeeding. Test Plan: ```name="Happy path where new /proc works" ❯ buck2 test fbcode//antlir/antlir2/features/rpm/... Buck UI: https://www.internalfb.com/buck2/8114d14c-ada3-49e2-8596-bc048b4a369e Test UI: https://www.internalfb.com/intern/testinfra/testrun/9851624322928450 Tests finished: Pass 67. Fail 0. Fatal 0. Skip 0. Omit 0. Infra Failure 0. Build failure 0 ``` Since I can't reproduce the `EPERM` failure mode on my devserver, just change the code to pretend that it failed: ``` ❯ hg diff diff --git a/fbcode/antlir/antlir2/antlir2_isolate/isolate_unshare/isolate_unshare_preexec/src/isolation.rs b/fbcode/antlir/antlir2/antlir2_isolate/isolate_unshare/isolate_unshare_preexec/src/isolation.rs --- a/fbcode/antlir/antlir2/antlir2_isolate/isolate_unshare/isolate_unshare_preexec/src/isolation.rs +++ b/fbcode/antlir/antlir2/antlir2_isolate/isolate_unshare/isolate_unshare_preexec/src/isolation.rs @@ -334,27 +334,27 @@ Err(e) => Err(e), }?; - match nix::mount::mount( - None::<&str>, + // match nix::mount::mount( + // None::<&str>, + // &newroot.open_dir("proc")?.abspath(), + // Some("proc"), + // MsFlags::MS_NOSUID | MsFlags::MS_NOEXEC | MsFlags::MS_NODEV, + // None::<&str>, + // ) { + // Ok(()) => Ok(()), + // Err(e) if e == nix::errno::Errno::EPERM => { + warn!("got EPERM while mounting /proc - attempting a bind mount instead"); + mount( + Some("/proc"), &newroot.open_dir("proc")?.abspath(), - Some("proc"), - MsFlags::MS_NOSUID | MsFlags::MS_NOEXEC | MsFlags::MS_NODEV, None::<&str>, - ) { - Ok(()) => Ok(()), - Err(e) if e == nix::errno::Errno::EPERM => { - warn!("got EPERM while mounting /proc - attempting a bind mount instead"); - mount( - Some("/proc"), - &newroot.open_dir("proc")?.abspath(), - None::<&str>, - MsFlags::MS_BIND | MsFlags::MS_REC, - None::<&str>, - ) - .context("while bind-mounting /proc") - } - Err(e) => Err(e).context("while mounting /proc"), - }?; + MsFlags::MS_BIND | MsFlags::MS_REC, + None::<&str>, + ) + .context("while bind-mounting /proc")?; + // } + // Err(e) => Err(e).context("while mounting /proc"), + // }?; nix::unistd::chroot(&newroot.abspath())?; if let Some(wd) = working_directory { ❯ buck2 test fbcode//antlir/antlir2/features/rpm/... Buck UI: https://www.internalfb.com/buck2/bb147ef3-a7dd-4180-8e7f-b7aebf135cb0 Test UI: https://www.internalfb.com/intern/testinfra/testrun/15762598833571210 Tests finished: Pass 67. Fail 0. Fatal 0. Skip 0. Omit 0. Infra Failure 0. Build failure 0 ``` Reviewed By: vjt Differential Revision: D89734817 fbshipit-source-id: 2c9f94d7b471f6f74534c41f935d27659a1d8dff
1 parent 9899a02 commit a2d100e

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

antlir/antlir2/antlir2_isolate/isolate_unshare/isolate_unshare_preexec/BUCK

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ rust_binary(
2121
"rustix",
2222
"serde_json",
2323
"tokio",
24+
"tracing",
25+
"tracing-subscriber",
2426
"//antlir/antlir2/antlir2_isolate/isolate_cfg:isolate_cfg",
2527
"//antlir/antlir2/antlir2_path:antlir2_path",
2628
"//antlir/util/cli/json_arg:json_arg",

antlir/antlir2/antlir2_isolate/isolate_unshare/isolate_unshare_preexec/src/isolation.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use nix::sched::unshare;
2525
use nix::unistd::Gid;
2626
use nix::unistd::Uid;
2727
use nix::unistd::User;
28+
use tracing::warn;
2829

2930
/// MS_NOSYMFOLLOW (since Linux 5.10)
3031
/// Do not follow symbolic links when resolving paths. Symbolic links can still
@@ -332,14 +333,28 @@ pub(crate) fn setup_isolation(isol: &IsolationContext) -> Result<()> {
332333
Err(e) if e.kind() == ErrorKind::AlreadyExists => Ok(()),
333334
Err(e) => Err(e),
334335
}?;
335-
nix::mount::mount(
336+
337+
match nix::mount::mount(
336338
None::<&str>,
337339
&newroot.open_dir("proc")?.abspath(),
338340
Some("proc"),
339341
MsFlags::MS_NOSUID | MsFlags::MS_NOEXEC | MsFlags::MS_NODEV,
340342
None::<&str>,
341-
)
342-
.context("while mounting /proc")?;
343+
) {
344+
Ok(()) => Ok(()),
345+
Err(nix::errno::Errno::EPERM) => {
346+
warn!("got EPERM while mounting /proc - attempting a bind mount instead");
347+
mount(
348+
Some("/proc"),
349+
&newroot.open_dir("proc")?.abspath(),
350+
None::<&str>,
351+
MsFlags::MS_BIND | MsFlags::MS_REC,
352+
None::<&str>,
353+
)
354+
.context("while bind-mounting /proc")
355+
}
356+
Err(e) => Err(e).context("while mounting /proc"),
357+
}?;
343358

344359
nix::unistd::chroot(&newroot.abspath())?;
345360
if let Some(wd) = working_directory {

antlir/antlir2/antlir2_isolate/isolate_unshare/isolate_unshare_preexec/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ struct Main {
4040
}
4141

4242
fn main() {
43+
tracing_subscriber::fmt()
44+
.with_writer(std::io::stderr)
45+
.init();
4346
let args = Subcommand::parse();
4447
if let Err(e) = match args {
4548
Subcommand::Main(args) => do_main(args),

0 commit comments

Comments
 (0)