]> git.lizzy.rs Git - rust.git/commit - src/tools/miri
Rollup merge of #89999 - talagrand:GetTempPath2, r=m-ou-se
authorMatthias Krüger <matthias.krueger@famsik.de>
Thu, 9 Dec 2021 04:08:31 +0000 (05:08 +0100)
committerGitHub <noreply@github.com>
Thu, 9 Dec 2021 04:08:31 +0000 (05:08 +0100)
commit856eefece946994ea76030c756df5fdf669cac9e
treea4f1dea689e69b900689a96fd4b895a0e02b4538
parent3fc5bd7abc2878f65a3c3dbc594874bae369cdf8
parent1d26e413de7a026ae2e99dad82edd2b8affcf5f3
Rollup merge of #89999 - talagrand:GetTempPath2, r=m-ou-se

Update std::env::temp_dir to use GetTempPath2 on Windows when available.

As a security measure, Windows 11 introduces a new temporary directory API, GetTempPath2.
When the calling process is running as SYSTEM, a separate temporary directory
will be returned inaccessible to non-SYSTEM processes. For non-SYSTEM processes
the behavior will be the same as before.

This can help mitigate against attacks such as this one:
https://medium.com/csis-techblog/cve-2020-1088-yet-another-arbitrary-delete-eop-a00b97d8c3e2

Compatibility risk: Software which relies on temporary files to communicate between SYSTEM and non-SYSTEM
processes may be affected by this change. In many cases, such patterns may be vulnerable to the very
attacks the new API was introduced to harden against.
I'm unclear on the Rust project's tolerance for such change-of-behavior in the standard library. If anything,
this PR is meant to raise awareness of the issue and hopefully start the conversation.

How tested: Taking the example code from the documentation and running it through psexec (from SysInternals) on
Win10 and Win11.
On Win10:
C:\test>psexec -s C:\test\main.exe
<...>
Temporary directory: C:\WINDOWS\TEMP\

On Win11:
C:\test>psexec -s C:\test\main.exe
<...>
Temporary directory: C:\Windows\SystemTemp\
library/std/src/env.rs
library/std/src/sys/windows/c.rs
library/std/src/sys/windows/os.rs