Bug 1973947 - revert removal of remove_dir_all crate a=pascalc

Bug 1959801 removed the `remove_dir_all` crate. However, there was a regression we didn't discover until Firefox 140 reached stable: third-party DLL injection on Windows caused problems for the call sites that had had usages of `remove_dir_all::remove_dir_all` replaced with `std::fs::remove_dir_all`!

DLL injection by third parties were causing these crashes because they incorrectly detour calls to `NtOpenFile`, crashing with Rust's current usage of it in `std::fs::remove_dir_all`. The issue has been reported upstream as [rust#143078], and a mitigation is in place in Rust's Nightly release channel. At time of writing this patch message, the fix is projected to become available in a stable Rust toolchain with version 1.90—roughly 11 weeks away.

[rust#143078]: https://github.com/rust-lang/rust/issues/143078#issue-3181510282

After considering multiple mitigation options, this patch represents the decision of some stakeholders (@gstoll, @dmeehan, @yjuglaret, @gsvelto, @leggert, @ErichDonGubler) to mitigate the issue by directly backing out the patch for bug 1959801. The current plan is to eventually remove `remove_dir_all` again, once Rust 1.90 becomes the minimum supported version for `mozilla-central` (see bugs linked against bug 1973947 for more details), thus guaranteeing that our usage of `std::fs::remove_dir_all` is robust against this issue.

We may or may not engage with third parties to fix DLL injection; it has
not been decided at this time.

Original Revision: https://phabricator.services.mozilla.com/D256027

Differential Revision: https://phabricator.services.mozilla.com/D256040
This commit is contained in:
Erich Gubler
2025-07-04 06:39:50 +00:00
committed by pchevrel@mozilla.com
parent 8d72490175
commit f04e931425
11 changed files with 587 additions and 2 deletions

View File

@@ -22,6 +22,7 @@ swgl = { path = "../wr/swgl" }
wr_malloc_size_of = { path = "../wr/wr_malloc_size_of" }
gecko-profiler = { path = "../../tools/profiler/rust-api" }
static_prefs = { path = "../../modules/libpref/init/static_prefs" }
remove_dir_all = "0.5.3"
[dependencies.webrender]
path = "../wr/webrender"

View File

@@ -4,7 +4,7 @@
use std::cell::RefCell;
use std::ffi::OsString;
use std::fs::{create_dir_all, read_dir, read_to_string, File, remove_dir_all};
use std::fs::{create_dir_all, read_dir, read_to_string, File};
use std::io::{Error, ErrorKind};
use std::io::{Read, Write};
use std::path::{Path, PathBuf};
@@ -345,7 +345,7 @@ pub fn remove_disk_cache(prof_path: &nsAString) -> Result<(), Error> {
if let Some(cache_path) = get_cache_path_from_prof_path(prof_path) {
if cache_path.exists() {
let start = Instant::now();
remove_dir_all(&cache_path)?;
remove_dir_all::remove_dir_all(&cache_path)?;
info!("removed all disk cache shaders in {:?}", start.elapsed());
}
}