Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #128334

Merged
merged 58 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
22364f8
This pattern using lazy protected Reserved IM prevents spurious writes
Vanille-N Jul 9, 2024
2de6e7f
Implement fix for reservedim_spurious_write: ignore IM on protected
Vanille-N Jul 9, 2024
22996ad
Apply suggestions
Vanille-N Jul 9, 2024
68aed4a
Second byte is not involved in the example; use a Cell<()> instead
Vanille-N Jul 10, 2024
78f6386
Clarify comment in tests/fail/tree_borrows/reservedim_spurious_write.rs
Vanille-N Jul 12, 2024
fd81880
Leave a trace of the current suboptimal status of foreign_write
Vanille-N Jul 12, 2024
e1e5b8a
Preparing for merge from rustc
Jul 16, 2024
547ade5
Merge from rustc
Jul 16, 2024
451035f
Auto merge of #3751 - rust-lang:rustup-2024-07-16, r=RalfJung
bors Jul 16, 2024
b3736d6
Auto merge of #3742 - Vanille-N:master, r=RalfJung
bors Jul 16, 2024
e5544dc
Preparing for merge from rustc
Jul 20, 2024
424d79c
Merge from rustc
Jul 20, 2024
0c1448d
Auto merge of #3755 - rust-lang:rustup-2024-07-20, r=RalfJung
bors Jul 20, 2024
69b9eab
Add `O_NOFOLLOW` flag support
newpavlov Jul 22, 2024
06a14f1
Fix test
newpavlov Jul 22, 2024
fc8af31
Auto merge of #3744 - newpavlov:nofollow, r=RalfJung
bors Jul 22, 2024
56d672e
Add `pread` and `pwrite` shims
newpavlov Jul 22, 2024
b7b2305
Auto merge of #3743 - newpavlov:pread_pwrite, r=RalfJung
bors Jul 22, 2024
c646256
Preparing for merge from rustc
Jul 24, 2024
675a5ba
Merge from rustc
Jul 24, 2024
0b22f0c
Auto merge of #3761 - rust-lang:rustup-2024-07-24, r=RalfJung
bors Jul 24, 2024
a0088d7
Allow getpid in isolation mode, add gettid support
Mandragorian Jul 20, 2024
12cb742
Auto merge of #3756 - Mandragorian:gettid_support, r=RalfJung
bors Jul 24, 2024
c45f464
show warning when Stacked Borrows skips a reborrow due to 'extern type'
RalfJung Jun 22, 2024
f1ae48c
Auto merge of #3701 - RalfJung:extern-type-reborrow, r=saethlin
bors Jul 24, 2024
6da04f9
Preparing for merge from rustc
Jul 25, 2024
4a26aa4
Merge from rustc
Jul 25, 2024
35e70f3
Auto merge of #3762 - rust-lang:rustup-2024-07-25, r=saethlin
bors Jul 25, 2024
b549035
Preparing for merge from rustc
Jul 26, 2024
4bd2757
Merge from rustc
Jul 26, 2024
f98fdfc
Auto merge of #3765 - rust-lang:rustup-2024-07-26, r=RalfJung
bors Jul 26, 2024
7bc7e67
better diagnostics for Tree Borrows + int2ptr casts
RalfJung Jul 26, 2024
5e1f8e2
diagnostics: add a macro to make things a bit easier to read
RalfJung Jul 26, 2024
bf4d4c0
Auto merge of #3766 - RalfJung:tree-borrows-int2ptr, r=RalfJung
bors Jul 26, 2024
a52b1d6
Let insert_fd takes in FileDescription instead of FileDescriptor
tiif Jul 26, 2024
adbb89e
Auto merge of #3763 - tiif:global-fd-id, r=oli-obk
bors Jul 26, 2024
80a32f8
Preparing for merge from rustc
Jul 27, 2024
00e89d3
Merge from rustc
Jul 27, 2024
822286f
fix clippy
RalfJung Jul 27, 2024
a6796c1
Auto merge of #3768 - rust-lang:rustup-2024-07-27, r=RalfJung
bors Jul 27, 2024
5b38b14
miri: fix offset_from behavior on wildcard pointers
RalfJung Jul 27, 2024
f8ebe8d
improve dangling/oob errors and make them more uniform
RalfJung Jul 27, 2024
e1fc4a9
Don't store `thir::Pat` in error structs
Zalathar Jul 28, 2024
cf87203
Remove spurious backticks detected by `rustdoc::unescaped_backticks`
ojeda Jul 28, 2024
dc815df
Warn on `rustdoc::unescaped_backticks` for `core/alloc/std/test/proc_…
ojeda Jul 28, 2024
41cf837
CI: move RFL job forward to v6.11-rc1
ojeda Jul 28, 2024
db05b0f
Encapsulate the printing of `WitnessPat`
Zalathar Jul 28, 2024
ae0ec73
Make `thir::Pat` not implement `fmt::Display` directly
Zalathar Jul 28, 2024
6e24719
handle no_std targets on std builds
onur-ozkan Jul 25, 2024
4c87e84
allow running `x doc` on std for no_std targets
onur-ozkan Jul 25, 2024
d3aed2c
remove the requirement of `Builder` arg in `doc::Std::new` function
onur-ozkan Jul 26, 2024
f56d58e
ignore `crates` if running unit tests
onur-ozkan Jul 26, 2024
7e6943d
Rollup merge of #128182 - onur-ozkan:fix-no-std-crates, r=Mark-Simula…
matthiaskrgr Jul 29, 2024
eb8114b
Rollup merge of #128277 - RalfJung:offset_from_wildcard, r=oli-obk
matthiaskrgr Jul 29, 2024
d73decd
Rollup merge of #128304 - Zalathar:thir-pat-display, r=Nadrieril
matthiaskrgr Jul 29, 2024
8f7af88
Rollup merge of #128307 - ojeda:unescaped_backticks, r=GuillaumeGomez
matthiaskrgr Jul 29, 2024
43c50bc
Rollup merge of #128322 - ojeda:rfl-ci-update, r=Kobzol
matthiaskrgr Jul 29, 2024
624f9bd
Rollup merge of #128333 - RalfJung:miri-sync, r=RalfJung
matthiaskrgr Jul 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add O_NOFOLLOW flag support
  • Loading branch information
newpavlov committed Jul 22, 2024
commit 69b9eab4aba6d13c348e09190785fa9c015baae9
29 changes: 26 additions & 3 deletions src/tools/miri/src/shims/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {

let this = self.eval_context_mut();

let path = this.read_pointer(&args[0])?;
let path_raw = this.read_pointer(&args[0])?;
let path = this.read_path_from_c_str(path_raw)?;
let flag = this.read_scalar(&args[1])?.to_i32()?;

let mut options = OpenOptions::new();
Expand Down Expand Up @@ -366,14 +367,36 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
return Ok(-1);
}
}

let o_nofollow = this.eval_libc_i32("O_NOFOLLOW");
if flag & o_nofollow == o_nofollow {
#[cfg(unix)]
{
use std::os::unix::fs::OpenOptionsExt;
options.custom_flags(libc::O_NOFOLLOW);
}
// Strictly speaking, this emulation is not equivalent to the O_NOFOLLOW flag behavior:
// the path could change between us checking it here and the later call to `open`.
// But it's good enough for Miri purposes.
#[cfg(not(unix))]
{
// O_NOFOLLOW only fails when the trailing component is a symlink;
// the entire rest of the path can still contain symlinks.
if path.is_symlink() {
let eloop = this.eval_libc("ELOOP");
this.set_last_error(eloop)?;
return Ok(-1);
}
}
mirror |= o_nofollow;
}

// If `flag` is not equal to `mirror`, there is an unsupported option enabled in `flag`,
// then we throw an error.
if flag != mirror {
throw_unsup_format!("unsupported flags {:#x}", flag & !mirror);
}

let path = this.read_path_from_c_str(path)?;

// Reject if isolation is enabled.
if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {
this.reject_in_isolation("`open`", reject_with)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ use std::os::unix::ffi::OsStrExt;
mod utils;

fn main() {
test_readlink();
test_nofollow_symlink();
}

fn test_readlink() {
let bytes = b"Hello, World!\n";
let path = utils::prepare_with_content("miri_test_fs_link_target.txt", bytes);
let expected_path = path.as_os_str().as_bytes();
Expand Down Expand Up @@ -49,3 +54,18 @@ fn main() {
assert_eq!(res, -1);
assert_eq!(Error::last_os_error().kind(), ErrorKind::NotFound);
}

fn test_nofollow_symlink() {
let bytes = b"Hello, World!\n";
let path = utils::prepare_with_content("test_nofollow_symlink_target.txt", bytes);

let symlink_path = utils::prepare("test_nofollow_symlink.txt");
std::os::unix::fs::symlink(&path, &symlink_path).unwrap();

let symlink_cpath = CString::new(symlink_path.as_os_str().as_bytes()).unwrap();

let ret = unsafe { libc::open(symlink_cpath.as_ptr(), libc::O_NOFOLLOW | libc::O_CLOEXEC) };
assert_eq!(ret, -1);
let err = io::Error::last_os_error().raw_os_error().unwrap();
assert_eq!(err, libc::ELOOP);
}
9 changes: 9 additions & 0 deletions src/tools/miri/tests/pass-dep/libc/libc-fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fn main() {
test_sync_file_range();
test_isatty();
test_read_and_uninit();
test_nofollow_not_symlink();
}

fn test_file_open_unix_allow_two_args() {
Expand Down Expand Up @@ -423,3 +424,11 @@ fn test_read_and_uninit() {
remove_file(&path).unwrap();
}
}

fn test_nofollow_not_symlink() {
let bytes = b"Hello, World!\n";
let path = utils::prepare_with_content("test_nofollow_not_symlink.txt", bytes);
let cpath = CString::new(path.as_os_str().as_bytes()).unwrap();
let ret = unsafe { libc::open(cpath.as_ptr(), libc::O_NOFOLLOW | libc::O_CLOEXEC) };
assert!(ret >= 0);
}