Skip to content

fix(ci): bump url past RUSTSEC-2026-0592 and deflake tmpdir reclaim test - #128

Merged
johayang-amd merged 1 commit into
ROCm:mainfrom
ltsabadz:fix/main-ci-url-advisory-and-tmpdir-flake
Nov 25, 2026
Merged

johayang-amd merged 1 commit into
ROCm:mainfrom
ltsabadz:fix/main-ci-url-advisory-and-tmpdir-flake

Conversation

@ltsabadz

Copy link
Copy Markdown
Collaborator

Motivation

Technical Details

  • Bump url to 2.5.9, which also needs form_urlencoded 1.2.3. Only Cargo.lock changes.
  • The test releases the lock and takes it again right away. If another test starts a process at that moment, that process can hold the lock for a few milliseconds. The test now retries for up to 2 seconds, which still catches a real leak.

Security impact: none. No product code changes.

Test Plan

On Linux x86_64: cargo deny, cargo audit, cargo fmt, cargo clippy, and the axis-sandbox tests.

Test Result

All pass. Not run on macOS or Windows.

url 2.5.8 is flagged by RUSTSEC-2026-0592 (stack overflow in
Url::origin() on nested blob: URLs), failing the dependency audit on
every PR. Bump to 2.5.9, which needs form_urlencoded 1.2.3.

claim_tmpdir_is_free_once_only_a_spawned_command_has_descriptors could
fail when another test forked while the claim was held: the child keeps
the flock'd open file description until its exec closes it. Retry the
reclaim briefly; a descriptor the sleep really inherited still holds the
lock past the deadline.

Co-authored-by: Cursor <[email protected]>

@johayang-amd johayang-amd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Luka, this unblocks Dependency audit for every open PR and fixes the flaky test from #107. The retry still catches a real leak, since the sleep 30 child would keep the lock past the deadline.

Nit, not blocking: a child that another test forks without exec keeps the lock until it exits, not until an exec, so the comment is slightly narrower than what the retry covers.

@johayang-amd

Copy link
Copy Markdown
Collaborator

The retry is in the right place, but the same race is still in five places, and claim_tmpdir_is_free_once_only_a_spawned_command_has_descriptors still fails on this branch: its second iteration starts with an unretried claim right after the first iteration drops reclaimed (landlock.rs:2020). The other spots are the reclaims after drop(held) and drop(claim) in the two tests above it (Nightly failed on the second one on 11-22), and the one-second loop in parent_death_monitor_does_not_keep_the_tmpdir_claim in linux/mod.rs. A forked child that never execs also keeps the lock until it exits, so a fixed two-second window is not always enough.

Suggestion: one test-only reclaim_tmpdir that retries only while the lock is held, for up to 5 s, used at all five sites. A real leak (the sleep 30 or the monitor keeping the descriptor) still fails it. Patch on top of 8ff92e9:

Patch (2 files, +31 −22)
diff --git a/crates/axis-sandbox/src/linux/landlock.rs b/crates/axis-sandbox/src/linux/landlock.rs
index 7f829c0..1431ada 100644
--- a/crates/axis-sandbox/src/linux/landlock.rs
+++ b/crates/axis-sandbox/src/linux/landlock.rs
@@ -1123,6 +1123,29 @@ fn normalize_existing_or_absolute_path(path: &Path) -> Result<PathBuf, String> {
     normalize_absolute_path(&resolved)
 }
 
+/// Claims the tmpdir right after an earlier claim was dropped. Tests run in
+/// parallel, and a child another test forks while that claim was held keeps
+/// the lock until it execs or exits, so a held lock is retried for a while.
+#[cfg(test)]
+pub(crate) fn reclaim_tmpdir(
+    workspace: &Path,
+    owner: libc::uid_t,
+    refuse_symlinks: bool,
+) -> Result<TmpdirClaim, String> {
+    let deadline = std::time::Instant::now() + std::time::Duration::from_secs(5);
+    loop {
+        match claim_tmpdir_for(workspace, owner, refuse_symlinks) {
+            Err(err)
+                if err.contains("another sandbox in this workspace holds it")
+                    && std::time::Instant::now() < deadline =>
+            {
+                std::thread::sleep(std::time::Duration::from_millis(10));
+            }
+            claim => return claim,
+        }
+    }
+}
+
 #[cfg(test)]
 mod tests {
     use super::*;
@@ -1925,7 +1948,7 @@ mod tests {
 
         // The holder ended without removing it, as a killed AXIS does.
         drop(held);
-        let _claim = claim_tmpdir(dir.path(), None).unwrap();
+        let _claim = reclaim_tmpdir(dir.path(), unsafe { libc::geteuid() }, false).unwrap();
         assert!(!tmpdir.exists());
         create_tmpdir(dir.path()).unwrap();
     }
@@ -1956,7 +1979,7 @@ mod tests {
 
         std::fs::remove_file(&tmpdir).unwrap();
         std::fs::create_dir(&tmpdir).unwrap();
-        let _claim = claim_tmpdir_for(dir.path(), owner.wrapping_add(1), false).unwrap();
+        let _claim = reclaim_tmpdir(dir.path(), owner.wrapping_add(1), false).unwrap();
         assert!(tmpdir.is_dir());
         assert!(
             create_tmpdir(dir.path())
@@ -2017,23 +2040,15 @@ mod tests {
     fn claim_tmpdir_is_free_once_only_a_spawned_command_has_descriptors() {
         let dir = tempfile::tempdir().unwrap();
         for identity in [false, true] {
-            let claim = claim_tmpdir_for(dir.path(), unsafe { libc::geteuid() }, identity).unwrap();
+            let claim = reclaim_tmpdir(dir.path(), unsafe { libc::geteuid() }, identity).unwrap();
             let mut command = std::process::Command::new("/bin/sleep")
                 .arg("30")
                 .spawn()
                 .unwrap();
             drop(claim);
             // Only an inherited lock descriptor could keep the workspace locked
-            // past the deadline. A command another test forks while the claim is
-            // held keeps the lock only until its exec closes the descriptor.
-            let deadline = std::time::Instant::now() + std::time::Duration::from_secs(2);
-            let reclaimed = loop {
-                let reclaimed = claim_tmpdir(dir.path(), None);
-                if reclaimed.is_ok() || std::time::Instant::now() >= deadline {
-                    break reclaimed;
-                }
-                std::thread::sleep(std::time::Duration::from_millis(10));
-            };
+            // past the retry.
+            let reclaimed = reclaim_tmpdir(dir.path(), unsafe { libc::geteuid() }, false);
             let _ = command.kill();
             let _ = command.wait();
             assert!(reclaimed.is_ok(), "{identity}: {reclaimed:?}");
diff --git a/crates/axis-sandbox/src/linux/mod.rs b/crates/axis-sandbox/src/linux/mod.rs
index f62dabd..3a237fa 100644
--- a/crates/axis-sandbox/src/linux/mod.rs
+++ b/crates/axis-sandbox/src/linux/mod.rs
@@ -2931,15 +2931,9 @@ mod tests {
         drop(claim);
 
         // The monitor is still running; only its inherited descriptor could
-        // keep the workspace locked.
-        let deadline = std::time::Instant::now() + std::time::Duration::from_secs(1);
-        let reclaimed = loop {
-            match landlock::claim_tmpdir(workspace.path(), None) {
-                Ok(claim) => break Ok(claim),
-                Err(err) if std::time::Instant::now() >= deadline => break Err(err),
-                Err(_) => std::thread::sleep(std::time::Duration::from_millis(10)),
-            }
-        };
+        // keep the workspace locked past the retry.
+        let reclaimed =
+            landlock::reclaim_tmpdir(workspace.path(), unsafe { libc::geteuid() }, false);
         guard.finish();
         let _ = child.kill();
         let _ = child.wait();

Tested on a 32-core Linux x86-64 host: the whole axis-sandbox lib test binary, this branch and the patch alternately, 60 runs each with the default thread count. fmt and clippy -D warnings are clean.

8ff92e9 With the patch
Runs with a failure 21 / 60 3 / 60
claim_tmpdir_is_free_once_only_a_spawned_command_has_descriptors 15 0
claim_tmpdir_removes_a_leftover_only_while_no_other_sandbox_holds_it 7 0
claim_tmpdir_leaves_a_link_or_another_owners_directory_for_the_create_to_refuse 3 0

The 3 remaining runs are unrelated tests in sandbox::tests (public_create_uses_mxc_linux_backend_by_default and create_names_the_automatic_selection_when_the_native_backend_refuses); they failed about as often on 8ff92e9. If you push this yourself I'll re-approve, since the ruleset needs the last push approved by someone other than the pusher.

aniemela-amd added a commit to aniemela-amd/axis that referenced this pull request Nov 25, 2026
libtest runs cases in one process. While a claim holds an flock'd workspace
fd, another test's Command::spawn forks and duplicates that fd into its
child until exec+CLOEXEC. Immediate reclaim then fails as if another
sandbox still held the workspace.

Retry claim for up to 2s (same approach as ROCm#128). A real inherited
lock from the spawned sleep still fails the deadline. Removes the
wait-for-exec helper (and its clippy collapsible_if).
@johayang-amd
johayang-amd merged commit 341e181 into ROCm:main Nov 25, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants