mirror of
https://github.com/openai/codex.git
synced 2026-11-13 14:46:14 +00:00
Request read control when updating Windows sandbox ACLs (#40475)
## Why `SetSecurityInfo` can reject a directory handle opened with only `WRITE_DAC`. ## What changed - Request `READ_CONTROL` alongside `WRITE_DAC` when opening or creating a no-reparse sandbox directory. - Add a Windows regression test that provisions and locks a plain sandbox directory through the handle-based ACL path. GitOrigin-RevId: bd50dc54d4cc80e9609323ddb4ecc7e4780a31fb
This commit is contained in:
1 parent
333beecd41
commit
3a211471d2
3 files changed
+36
-1
No files matched your search
@@ -1035,6 +1035,10 @@ fn run_setup_full(payload: &Payload, log: &mut dyn Write, sbx_dir: &Path) -> Res
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
#[path = "win_acl_tests.rs"]
|
||||||
|
mod acl_tests;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::Payload;
|
use super::Payload;
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ use windows_sys::Win32::Storage::FileSystem::FILE_ATTRIBUTE_NORMAL;
|
|||||||
use windows_sys::Win32::Storage::FileSystem::FILE_SHARE_DELETE;
|
use windows_sys::Win32::Storage::FileSystem::FILE_SHARE_DELETE;
|
||||||
use windows_sys::Win32::Storage::FileSystem::FILE_SHARE_READ;
|
use windows_sys::Win32::Storage::FileSystem::FILE_SHARE_READ;
|
||||||
use windows_sys::Win32::Storage::FileSystem::FILE_SHARE_WRITE;
|
use windows_sys::Win32::Storage::FileSystem::FILE_SHARE_WRITE;
|
||||||
|
use windows_sys::Win32::Storage::FileSystem::READ_CONTROL;
|
||||||
use windows_sys::Win32::Storage::FileSystem::WRITE_DAC;
|
use windows_sys::Win32::Storage::FileSystem::WRITE_DAC;
|
||||||
use windows_sys::Win32::System::IO::IO_STATUS_BLOCK;
|
use windows_sys::Win32::System::IO::IO_STATUS_BLOCK;
|
||||||
use windows_sys::Win32::System::IO::IO_STATUS_BLOCK_0;
|
use windows_sys::Win32::System::IO::IO_STATUS_BLOCK_0;
|
||||||
@@ -115,9 +116,10 @@ pub(super) fn open_or_create_no_reparse(path: &Path) -> Result<OwnedHandle> {
|
|||||||
};
|
};
|
||||||
let mut handle = 0;
|
let mut handle = 0;
|
||||||
let status = unsafe {
|
let status = unsafe {
|
||||||
|
// SetSecurityInfo can reject a WRITE_DAC-only directory handle.
|
||||||
NtCreateFile(
|
NtCreateFile(
|
||||||
&mut handle,
|
&mut handle,
|
||||||
WRITE_DAC,
|
READ_CONTROL | WRITE_DAC,
|
||||||
&object_attributes,
|
&object_attributes,
|
||||||
&mut io_status_block,
|
&mut io_status_block,
|
||||||
ptr::null(),
|
ptr::null(),
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
use super::DELETE;
|
||||||
|
use super::FILE_GENERIC_EXECUTE;
|
||||||
|
use super::FILE_GENERIC_READ;
|
||||||
|
use super::FILE_GENERIC_WRITE;
|
||||||
|
use super::GRANT_ACCESS;
|
||||||
|
use super::SetupMode;
|
||||||
|
use super::lock_sandbox_dir;
|
||||||
|
use super::resolve_sid;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn provision_only_locks_plain_directory_via_handle() {
|
||||||
|
let temp = tempfile::tempdir().expect("tempdir");
|
||||||
|
let sandbox_bin = temp.path().join(".sandbox-bin");
|
||||||
|
let real_user = std::env::var("USERNAME").unwrap_or_else(|_| "Administrators".to_string());
|
||||||
|
let real_sid = resolve_sid(&real_user).expect("resolve real user SID");
|
||||||
|
|
||||||
|
lock_sandbox_dir(
|
||||||
|
&sandbox_bin,
|
||||||
|
&real_user,
|
||||||
|
&real_sid,
|
||||||
|
GRANT_ACCESS,
|
||||||
|
FILE_GENERIC_READ | FILE_GENERIC_EXECUTE,
|
||||||
|
FILE_GENERIC_READ | FILE_GENERIC_WRITE | FILE_GENERIC_EXECUTE | DELETE,
|
||||||
|
SetupMode::ProvisionOnly,
|
||||||
|
)
|
||||||
|
.expect("lock sandbox bin via no-reparse handle");
|
||||||
|
|
||||||
|
assert!(sandbox_bin.is_dir());
|
||||||
|
}
|
||||||
Reference in new issue
Block a user