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

x/sys/windows: GetCurrentProcessToken() not working on Windows 7 SP1 #56946

Closed
kmahyyg opened this issue Nov 26, 2022 · 9 comments
Closed

x/sys/windows: GetCurrentProcessToken() not working on Windows 7 SP1 #56946

kmahyyg opened this issue Nov 26, 2022 · 9 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Milestone

Comments

@kmahyyg
Copy link

kmahyyg commented Nov 26, 2022

What version of Go are you using (go version)?

$ go version
go version go1.19.3 windows/amd64

Does this issue reproduce with the latest release?

Yes, I'm currently running latest release.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOARCH=amd64
set GOVERSION=go1.19.3
set GCCGO=gccgo
set GOAMD64=v1
set GOOS=windows

What did you do?

Under Windows 10 Build 19044, CGO disabled, compile a program, code here: https://go.dev/play/p/LjfMdT6mTHZ

What did you expect to see?

Run on Windows 10 (which I compiled the binary): working as intended
Run on Windows 7 SP1 (Build 7601): working as intended

What did you see instead?

Run on Windows 10 (which I compiled the binary): working as intended
Run on Windows 7 SP1 (Build 7601, Version 6.1.7601): Error message: The handle is invalid.

I confirmed that I've closed all the antivirus which might affect the program running, to reproduce the bug, use "-fakeToken=true" as cmdline param.

20221126-214231-Jump Desktop-000727

@seankhliao seankhliao changed the title golang.org/x/sys/windows: GetCurrentProcessToken() not working on Windows 7 SP1 x/sys/windows: GetCurrentProcessToken() not working on Windows 7 SP1 Nov 26, 2022
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Nov 26, 2022
@gopherbot gopherbot added this to the Unreleased milestone Nov 26, 2022
@seankhliao seankhliao added OS-Windows NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Nov 26, 2022
@thanm
Copy link
Contributor

thanm commented Nov 30, 2022

Relevant: #57003

@mknyszek
Copy link
Contributor

mknyszek commented Dec 7, 2022

CC @golang/windows

@kmahyyg
Copy link
Author

kmahyyg commented Dec 14, 2022

If #57003 #57004 are accepted, this issue should be closed directly. I've migrated to Windows Server 2022 now, but there's still a lot of Windows 7 in my company, I am really worrying about their assets. XD

@alexbrainman
Copy link
Member

I read code at https://go.dev/play/p/LjfMdT6mTHZ and the error can be returned on line 44 or 48. It would help to write repro code in a way that is always obvious where the problem is.

I suspect this code might fail for many different reasons other than been run on Windows 7. But I am not Windows security expert. So I could be wrong.

@kmahyyg you will have better chance to get help with this, if you post your question somewhere where Windows developers are. Perhaps https://stackoverflow.com ?

Alex

@kmahyyg
Copy link
Author

kmahyyg commented Dec 27, 2022

@alexbrainman

and the error can be returned on line 44 or 48.

Just add a line number in error message when print out. Now it's L44. Check pointer in memory using debugger, you'll see more.

I mostly wrote these code using Windows native CPP, they are always working in CPP, But I don't know why these functions in golang library are written in this way.

@alexbrainman
Copy link
Member

... I mostly wrote these code using Windows native CPP, they are always working in CPP, But I don't know why these functions in golang library are written in this way.

If you can reproduce this problem with C program, you can just compare your C and Go programs and see what is different. You can remove bits from your programs until it is obvious where the problem is.

Alex

@kmahyyg
Copy link
Author

kmahyyg commented Dec 27, 2022

The problem here is why your library implements the function in this way which lead to fault. Not my code. I just give an example and say I met a situation that something went wrong. And trying to tell u there's an issue.

@kmahyyg
Copy link
Author

kmahyyg commented Dec 27, 2022

Ouch, and also, Windows 7 reaches its EOL in a few days. Let's just throw it away. (even a lot of Windows 7 machines is running in Production)

@kmahyyg kmahyyg closed this as completed Dec 27, 2022
@kmahyyg
Copy link
Author

kmahyyg commented Dec 27, 2022

@alexbrainman Token(^uintptr(4 - 1)) makes me really confused, though.

https://cs.opensource.google/go/x/sys/+/refs/tags/v0.3.0:windows/security_windows.go;l=668

//sys	OpenProcessToken(process Handle, access uint32, token *Token) (err error) = advapi32.OpenProcessToken

type Token Handle

// OpenCurrentProcessToken opens an access token associated with current
// process with TOKEN_QUERY access. It is a real token that needs to be closed.
//
// Deprecated: Explicitly call OpenProcessToken(CurrentProcess(), ...)
// with the desired access instead, or use GetCurrentProcessToken for a
// TOKEN_QUERY token.
func OpenCurrentProcessToken() (Token, error) {
	var token Token
	err := OpenProcessToken(CurrentProcess(), TOKEN_QUERY, &token)
	return token, err
}

// GetCurrentProcessToken returns the access token associated with
// the current process. It is a pseudo token that does not need
// to be closed.
func GetCurrentProcessToken() Token {
	return Token(^uintptr(4 - 1))
}

@kmahyyg kmahyyg closed this as not planned Won't fix, can't repro, duplicate, stale Dec 27, 2022
@golang golang locked and limited conversation to collaborators Dec 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

No branches or pull requests

6 participants