-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: IsWindowsService returns incorrect answer for restricted services #44921
Comments
cc @alexbrainman @zx2c4 |
This follows more or less the same algorithm as .NET does. Perhaps, though, it's enough to just look at the process parent? Any suggestions on a more robust algorithm? Falling back to a less robust one doesn't seem like a good idea. |
@zx2c4 I just tested ignoring the error, and I found that the
I don't know. One question to ponder is whether it's actually possible for a non-service process to get this error. I've never encountered it outside of the scenario of restricted services, but this is not exactly my area of expertise. If this error does imply that a restricted service is being used, then returning true with a nil error would be sufficient (but someone smarter than me would need to figure out whether this is actually the case). I'm 90% confident that my own use cases would be solved by falling back to the old algorithm when this EDIT: Fixed typo. |
/cc @bradfitz Could you provide an example of the code that produced the error, preferably as a Go playground link? |
Yes; might take me a day or two. |
The difference is that
Additionally Here's the relevant part of .NET source: And here's some Go code I've come across that uses |
Fantastic observation! Thank you. I'll see if I can bring us closer to the .NET function. |
Apologies for failing to post example test case code promptly; things have been super busy here and this bug got back-burnered for me. I'm happy to test a proposed patch to see if it works here; I'll try to post example test case code as soon as I have a few minutes, assuming the bug doesn't get fixed first. Thanks @the-ress for moving this diagnosis forward! |
Change https://golang.org/cl/372554 mentions this issue: |
@JeremyRand there's a patch. It'd be useful for you to try it out and see if it fixes the problem. |
@zx2c4 thanks so much for the patch! I can confirm the patched version fixes the issue for me. |
Using the service manager from an remote ssh command promt fails with `The service process could not connect to the service controller` Thanks to the detailed analysis from @kelseyma the fix was very straight forward. Using IsWindowsService() solved this problem for me. The mentioned issue at golang/go#44921 has also been fixed in the meantime, so there is no reason not to use IsWindowsService() instead. Fixes kardianos#300
Using the service manager from an remote ssh command promt fails with `The service process could not connect to the service controller` Thanks to the detailed analysis from @kelseyma the fix was very straight forward. Using IsWindowsService() solved this problem for me. The mentioned issue at golang/go#44921 has also been fixed in the meantime, so there is no reason not to use IsWindowsService() instead. Fixes #300
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I ran a Go program as a restricted Windows service (created like this, with the intent of limiting attack surface), and had the Go program check whether it was running as a service via
IsWindowsService()
.What did you expect to see?
IsWindowsService()
should return true, or at least return a non-nil error if it can't determine whether it's running as a service.What did you see instead?
IsWindowsService()
returned false, and a nil error. Some debugging indicates that the bug is here: https://github.com/golang/sys/blob/7844c3c200c348863f4ff2a6efe6c016b5ba8b57/windows/svc/security.go#L83-L86When running as a restricted service,
err
contains anAccess is denied
error. This code treats any non-nil error at this spot as indicating that the program is not running as a service, i.e. it returns false and a nil error.At the very least, the
Access is denied
error should be returned to the caller rather than returning a wrong result with a nil error. However, I also notice that the deprecatedIsAnInteractiveSession()
handles this case properly, because it does not need any permissions that restricted services do not have. It might be desirable to automatically fall back to theIsAnInteractiveSession()
implementation in this case, rather than returning an error.The text was updated successfully, but these errors were encountered: