Skip to content

Commit d55c2d7

Browse files
committed
windows: Enable default security parameters on file creation to avoid named pipe exploit
Fixes #42036 As noted in [this paper][1], the threat model for the exploit is a priveleged Rust process which accepts a file path from a malicious program. With this exploit, the malicious program can pass a named pipe to the priveleged process and gain its elevated priveleges. The fix is to change the default OpenOptions to contain the proper security flags. [The .NET FileStream][2] has this same behavior by default. We're using the `SecurityIdentification` security level which is more permissive, but still blocks the exploit. This is technically a breaking change. If someone were using a named pipe to impersonate a program *on purpose*, they would have to add `.security_qos_flags(0)` to their `OpenOptions` to keep working. [1]: http://www.blakewatts.com/namedpipepaper.html [2]: http://referencesource.microsoft.com/#mscorlib/system/io/filestream.cs,837
1 parent 824952f commit d55c2d7

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/libstd/sys/windows/c.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ pub const FILE_GENERIC_WRITE: DWORD = STANDARD_RIGHTS_WRITE | FILE_WRITE_DATA |
117117
pub const FILE_FLAG_OPEN_REPARSE_POINT: DWORD = 0x00200000;
118118
pub const FILE_FLAG_BACKUP_SEMANTICS: DWORD = 0x02000000;
119119
pub const SECURITY_SQOS_PRESENT: DWORD = 0x00100000;
120+
pub const SECURITY_IDENTIFICATION: DWORD = 0x00010000;
120121

121122
pub const FIONBIO: c_ulong = 0x8004667e;
122123

src/libstd/sys/windows/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl OpenOptions {
184184
access_mode: None,
185185
share_mode: c::FILE_SHARE_READ | c::FILE_SHARE_WRITE | c::FILE_SHARE_DELETE,
186186
attributes: 0,
187-
security_qos_flags: 0,
187+
security_qos_flags: c::SECURITY_SQOS_PRESENT | c::SECURITY_IDENTIFICATION,
188188
security_attributes: 0,
189189
}
190190
}

0 commit comments

Comments
 (0)