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

Switch to golang.org/x/sys/execabs for windows security fix #2344

Merged
merged 6 commits into from
Aug 4, 2021

Conversation

Jacalz
Copy link
Member

@Jacalz Jacalz commented Jul 31, 2021

Description:

The os/exec package on Windows will match the behaviour of cmd.exe by considering the local folder as a primary part of the path. This means that a malicious binary with the same name, in the current folder, would be run instead of the expected binary in the system path. Due to the backwards compat being an issue, this could not be fixed within ox/exec before Go v2. See https://blog.golang.org/path-security for more info.

This should not change any behaviour for anything else than Windows platforms. I think we should target this for develop as it potentially could break things if we run any binaries within the local path (easily fixed by adding ./ in the code). It did not look like any of the use cases here ran binaries in the current folder, so I think we should be fine. I do however not have access to any Windows computer to test it on at this point in time.

Checklist:

  • Tests included.
  • Lint and formatter run with no errors.
  • Tests all pass.

The os/exec package on Windows will match the behaviour of cmd.exe by considering the local folder as a primary part of the path.
This means that a malicious binary with the same name, in the current folder, would be run instead of the expected binary in the system path.
Due to the backwards compat being an issue, this could not be fixed within ox/exec before Go v2. See https://blog.golang.org/path-security for more info.
@Jacalz
Copy link
Member Author

Jacalz commented Jul 31, 2021

As a further note, I have switched everything to use the new package for the sake of consistency. Some of the vendored code uses "os/exec" still, so I don't think we gain any binary size improvements from doing this.

The switch to the new package has been made upstream as well. Update to gain that functionality there.
@Jacalz
Copy link
Member Author

Jacalz commented Jul 31, 2021

From the vendor folder, these are the deps that still rely on os/exec. I will get a patch up for goinfo.

vendor/github.com/godbus/dbus/v5/conn_darwin.go:        "os/exec"
vendor/github.com/godbus/dbus/v5/conn_other.go: "os/exec"
vendor/github.com/lucor/goinfo/report/go_env.go:        "os/exec"
vendor/github.com/lucor/goinfo/report/go_module.go:     "os/exec"
vendor/github.com/lucor/goinfo/report/go_version.go:    "os/exec"
vendor/github.com/lucor/goinfo/report/os_darwin.go:     "os/exec"
vendor/github.com/lucor/goinfo/report/os_windows.go:    "os/exec"
vendor/github.com/lucor/goinfo/report/os_xdg.go:        "os/exec"

@Jacalz
Copy link
Member Author

Jacalz commented Jul 31, 2021

I have lucor/goinfo#3 open now.

@Jacalz
Copy link
Member Author

Jacalz commented Jul 31, 2021

Should I get a PR up for godbus as well? There is no extra security to gain for us as we just use it on other platforms, but there could potentially be a use case for knowing that we do not depend on "os/exec" in terms of binary size.

lucor
lucor previously approved these changes Aug 2, 2021
Copy link
Member

@lucor lucor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just need to update github.com/lucor/goinfo@fce12a3 from your PR

@lucor
Copy link
Member

lucor commented Aug 2, 2021

Should I get a PR up for godbus as well? There is no extra security to gain for us as we just use it on other platforms, but there could potentially be a use case for knowing that we do not depend on "os/exec" in terms of binary size.

Probably having a PR for godbus does not hurt, even if as you said it does not add any extra security due to the target platform.
In any case I would not block this PR by the godbus one.

@Jacalz
Copy link
Member Author

Jacalz commented Aug 3, 2021

Should I get a PR up for godbus as well? There is no extra security to gain for us as we just use it on other platforms, but there could potentially be a use case for knowing that we do not depend on "os/exec" in terms of binary size.

Probably having a PR for godbus does not hurt, even if as you said it does not add any extra security due to the target platform.
In any case I would not block this PR by the godbus one.

Yeah, you are right. Always good to be a helpful open source citizen and contribute upstream where possible :)
Agreed, I think this should be fine to re-review now that goinfo is updated again.

lucor
lucor previously approved these changes Aug 3, 2021
Copy link
Member

@andydotxyz andydotxyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don’t delete khrplatform.h

@andydotxyz
Copy link
Member

Should I get a PR up for godbus as well?

Yeah good idea

@andydotxyz
Copy link
Member

I have switched everything to use the new package

I think updating unrelated dependencies should be a different PR - it requires a lot more testing and if there is an issue we would surely address them separately

@Jacalz
Copy link
Member Author

Jacalz commented Aug 3, 2021

I have switched everything to use the new package

I think updating unrelated dependencies should be a different PR - it requires a lot more testing and if there is an issue we would surely address them separately

Sorry if I was a bit vague here. The blog post above mentions that all of the golang.org/x/ packages have been updated to use the security fix as many of them rely on the execution of commands. I have not updated any other dependencies at all and they are thus not unrelated to this change.

Please don’t delete khrplatform.h

If it was deleted, it must have happened when running go mod vendor. We probably need a better way to get that in there. We can't have it break each time we update the modules.

@andydotxyz
Copy link
Member

If it was deleted, it must have happened when running go mod vendor. We probably need a better way to get that in there. We can't have it break each time we update the modules.

yes. Our old approach (fyne vendor) could work, but we stopped using it. I filed a bug upstream some time ago go-gl/gl#140

@Jacalz
Copy link
Member Author

Jacalz commented Aug 3, 2021

If it was deleted, it must have happened when running go mod vendor. We probably need a better way to get that in there. We can't have it break each time we update the modules.

yes. Our old approach (fyne vendor) could work, but we stopped using it. I filed a bug upstream some time ago go-gl/gl#140

Can we not just add the file upstream instead of here then?

@andydotxyz
Copy link
Member

Can we not just add the file upstream instead of here then?

Maybe you need to read the ticket more carefully… the file exists upstream but is removed during vendoring. I suggested they take the same workaround approach as GLFW did that allowed us to stop using our own vendor script

@Jacalz
Copy link
Member Author

Jacalz commented Aug 3, 2021

Can we not just add the file upstream instead of here then?

Maybe you need to read the ticket more carefully… the file exists upstream but is removed during vendoring. I suggested they take the same workaround approach as GLFW did that allowed us to stop using our own vendor script

Ah, sorry. Makes sense. Will add the file back in the meantime.

@Jacalz
Copy link
Member Author

Jacalz commented Aug 3, 2021

I have added back the file now.

@Jacalz Jacalz merged commit 2b0ac02 into fyne-io:develop Aug 4, 2021
@Jacalz Jacalz deleted the os/execabs branch August 4, 2021 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants