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

Setting #![windows_subsystem = "windows"], processes will not be spawned under Windows server 2008 SYSTEM privileges. #113851

Closed
b1nhack opened this issue Jul 19, 2023 · 14 comments
Labels
A-process Area: `std::process` and `std::env` C-bug Category: This is a bug. O-windows Operating system: Windows O-windows-7 OS: Windows 7 or Windows Server 2008 R2 or etc. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@b1nhack
Copy link

b1nhack commented Jul 19, 2023

I tried this code:

#![windows_subsystem = "windows"]

use std::process;

fn main() {
    process::Command::new("notepad.exe").spawn().unwrap();
}

I expected to see this happen:
Setting #![windows_subsystem = "windows"], processes will not be spawned under Windows server 2008 SYSTEM privileges.

Meta

rustc --version --verbose:

rustc 1.70.0 (90c541806 2023-05-31)
binary: rustc
commit-hash: 90c541806f23a127002de5b4038be731ba1458ca
commit-date: 2023-05-31
host: x86_64-pc-windows-msvc
release: 1.70.0
LLVM version: 16.0.2
Backtrace

Because of the specification of #![windows_subsystem = "windows"], so I can't see the backtrace

@b1nhack b1nhack added the C-bug Category: This is a bug. label Jul 19, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 19, 2023
@bjorn3
Copy link
Member

bjorn3 commented Jul 19, 2023

What processes do you expect to not be spawned?

@b1nhack
Copy link
Author

b1nhack commented Jul 20, 2023

What processes do you expect to not be spawned?

everyting

@bjorn3
Copy link
Member

bjorn3 commented Jul 20, 2023

I don't understand the issue you are having. Please give a concrete example of a process that shouldn't have started.

@b1nhack
Copy link
Author

b1nhack commented Jul 20, 2023

I don't understand the issue you are having. Please give a concrete example of a process that shouldn't have started.

notepad.exe is one

@bjorn3
Copy link
Member

bjorn3 commented Jul 20, 2023

If you run your program with SYSTEM privileges and your program then runs notepad.exe, it is expected that notepad.exe will also run with SYSTEM privileges. Programs inherit the privileges level of their parent by default.

If you don't run your program with SYSTEM privileges and yet notepad.exe somehow runs with SYSTEM privileges, that is not a bug in rust, but one in Windows. It shouldn't be possible for an unprivileged user to run arbitrary programs with the highest possible privilege level.

@b1nhack
Copy link
Author

b1nhack commented Jul 20, 2023

No, I mean only under Windows Server 2008, and running with SYSTEM privileges.

@bjorn3
Copy link
Member

bjorn3 commented Jul 20, 2023

Do you run your own program with SYSTEM privileges?

@b1nhack
Copy link
Author

b1nhack commented Jul 21, 2023

#![windows_subsystem = "windows"]

use std::process;

fn main() {
    process::Command::new("notepad.exe").spawn().unwrap();
}

This code is compiled into a binary program (*.exe).
Note: MSVC toolchain needs to specify "-C", "target-feature=+crt-static" flag to be compatible with Windows server 2008.
The compiled exe, under Windows server 2008 with administrator privileges can normally spawn a notepad.exe process.

Using processhacker runas a cmd.exe with SYSTEM privileges, executing the compiled exe in a cmd with SYSTEM privileges will not spawn a notepad.exe process.
And this problem only occurs if you specify #![windows_subsystem = "windows"].

@bjorn3 bjorn3 added the O-windows Operating system: Windows label Jul 21, 2023
@ChrisDenton
Copy link
Member

Have you tried nightly rust?

@b1nhack
Copy link
Author

b1nhack commented Jul 22, 2023

Not yet

@workingjubilee
Copy link
Member

workingjubilee commented Jul 22, 2023

Note: Windows 2008 is based on Windows Vista which is out of our support range, unless you mean Windows 2008 R2, which is based on Windows 7 and is currently considered a "best effort" support target. These are also End of Support for Microsoft as well, unfortunately.

It would be useful to confirm if this problem is still active on Windows 10, Windows 11, or their "Windows Server" derivatives.

@b1nhack
Copy link
Author

b1nhack commented Jul 22, 2023

I am referring to Windows Server 2008 R2, after my testing, Windows 10 does not have this issue.

@workingjubilee
Copy link
Member

Then this issue will be "fixed" in ~7 months by rust-lang/compiler-team#651

@workingjubilee workingjubilee added O-windows-7 OS: Windows 7 or Windows Server 2008 R2 or etc. A-process Area: `std::process` and `std::env` T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jul 22, 2023
@jieyouxu
Copy link
Member

Triage: no longer relevant because rust-lang/compiler-team#651.

@jieyouxu jieyouxu closed this as not planned Won't fix, can't repro, duplicate, stale Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-process Area: `std::process` and `std::env` C-bug Category: This is a bug. O-windows Operating system: Windows O-windows-7 OS: Windows 7 or Windows Server 2008 R2 or etc. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants