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

windows: fix -d=checkptr slice failures #65

Closed
wants to merge 10 commits into from

Conversation

rikysya
Copy link
Contributor

@rikysya rikysya commented Mar 25, 2020

This CL fixes unsafe casts to slices that are missing length or capacity.

Running tests with -d=checkptr enabled may panic on casting unsafe.Pointer to a static array of large predefined length, that is most likely much bigger than the size of the actual array in memory. Checkptr check is not satisfied if slicing operator misses length and capacity arguments (*[(1 << 30) - 1]uint16)(unsafe.Pointer(p))[:], or when there is no slicing at all (*[(1 << 30) - 1]uint16)(unsafe.Pointer(p)).

To find all potential cases I used grep -nr ")(unsafe.Pointer(" ./windows, then filtered out safe casts when object size is always static and known at compile time.

To reproduce the issue run tests with checkptr enabled go test -a -gcflags=all=-d=checkptr ./windows/....

Updates golang/go#34972
Fixes golang/go#38355

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@rikysya
Copy link
Contributor Author

rikysya commented Mar 25, 2020

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@gopherbot
Copy link

This PR (HEAD: 8f8c737) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/sys/+/225418 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link

Message from Gobot Gobot:

Patch Set 1:

Congratulations on opening your first change. Thank you for your contribution!

Next steps:
Within the next week or so, a maintainer will review your change and provide
feedback. See https://golang.org/doc/contribute.html#review for more info and
tips to get your patch through code review.

Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.

During May-July and Nov-Jan the Go project is in a code freeze, during which
little code gets reviewed or merged. If a reviewer responds with a comment like
R=go1.11, it means that this CL will be reviewed as part of the next development
cycle. See https://golang.org/s/release for more details.


Please don’t reply on this GitHub thread. Visit golang.org/cl/225418.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

This PR (HEAD: 212a4e6) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/sys/+/225418 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link

Message from Tobias Klauser:

Patch Set 3:

(2 comments)

Thanks for the CL. I'd suggest to split this up into two CLs: one addressing the golang.org/x/sys/unix package and one addressing the golang.org/x/sys/windows package.


Please don’t reply on this GitHub thread. Visit golang.org/cl/225418.
After addressing review feedback, remember to publish your drafts!

@rikysya rikysya changed the title sys: ensure passing checkptr check sys/windows: ensure passing checkptr check Mar 26, 2020
@gopherbot
Copy link

This PR (HEAD: 9e3e00a) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/sys/+/225418 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@rikysya rikysya changed the title sys/windows: ensure passing checkptr check sys/windows: fix -d=checkptr slice failures Mar 26, 2020
@gopherbot
Copy link

Message from Tobias Klauser:

Patch Set 5:

(2 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/225418.
After addressing review feedback, remember to publish your drafts!

@rikysya rikysya changed the title sys/windows: fix -d=checkptr slice failures windows: fix -d=checkptr slice failures Mar 26, 2020
@gopherbot
Copy link

Message from Tobias Klauser:

Patch Set 7: Run-TryBot+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/225418.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gobot Gobot:

Patch Set 7:

TryBots beginning. Status page: https://farmer.golang.org/try?commit=a8670abf


Please don’t reply on this GitHub thread. Visit golang.org/cl/225418.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gobot Gobot:

Patch Set 7: TryBot-Result-1

1 of 14 TryBots failed:
Failed on android-amd64-emu: https://storage.googleapis.com/go-build-log/2975b27b/android-amd64-emu_77b6617e.log

Consult https://build.golang.org/ to see whether they are new failures. Keep in mind that TryBots currently test exactly your git commit, without rebasing. If your commit's git parent is old, the failure might've already been fixed.


Please don’t reply on this GitHub thread. Visit golang.org/cl/225418.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Tobias Klauser:

Patch Set 7:

Alex, could you please have a look at this if you find time? Thanks!


Please don’t reply on this GitHub thread. Visit golang.org/cl/225418.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

This PR (HEAD: 2ff63b3) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/sys/+/225418 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link

Message from Alex Brainman:

Patch Set 8:

(7 comments)

Thank you Yaroslav for working on this.

Please, see some comments below.

Alex


Please don’t reply on this GitHub thread. Visit golang.org/cl/225418.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Bryan C. Mills:

Patch Set 8:

(5 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/225418.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Bryan C. Mills:

Patch Set 8: Run-TryBot+1

TRY=windows-amd64-race


Please don’t reply on this GitHub thread. Visit golang.org/cl/225418.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gobot Gobot:

Patch Set 8:

SlowBots beginning. Status page: https://farmer.golang.org/try?commit=4d9c8109


Please don’t reply on this GitHub thread. Visit golang.org/cl/225418.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gobot Gobot:

Patch Set 8: TryBot-Result+1

SlowBots are happy.
SlowBot builds that ran:

  • windows-amd64-race

Please don’t reply on this GitHub thread. Visit golang.org/cl/225418.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Alex Brainman:

Patch Set 8:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/225418.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Bryan C. Mills:

Patch Set 8:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/225418.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Alex Brainman:

Patch Set 8:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/225418.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Bryan C. Mills:

Patch Set 8:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/225418.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

This PR (HEAD: 2215e0a) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/sys/+/225418 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link

Message from Bryan C. Mills:

Patch Set 16: Code-Review+1

(5 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/225418.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Alex Brainman:

Patch Set 16:

(5 comments)

Sorry I am slow to review. But this CL is large.

Alex


Please don’t reply on this GitHub thread. Visit golang.org/cl/225418.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Tobias Klauser:

Patch Set 16:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/225418.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Alex Brainman:

Patch Set 16:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/225418.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Bryan C. Mills:

Patch Set 16:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/225418.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

This PR (HEAD: 43e62db) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/sys/+/225418 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link

This PR (HEAD: 77dff96) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/sys/+/225418 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link

Message from Yaroslav Vorobiov:

Patch Set 18:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/225418.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Alex Brainman:

Patch Set 18:

(2 comments)

Just couple more comments. Thank you very much.

Alex


Please don’t reply on this GitHub thread. Visit golang.org/cl/225418.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

This PR (HEAD: 73288ad) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/sys/+/225418 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link

Message from Alex Brainman:

Patch Set 19: Run-TryBot+1

TRY=windows-386, windows-amd64, windows-amd64-race


Please don’t reply on this GitHub thread. Visit golang.org/cl/225418.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gobot Gobot:

Patch Set 19:

SlowBots beginning. Status page: https://farmer.golang.org/try?commit=9a4b5ce9


Please don’t reply on this GitHub thread. Visit golang.org/cl/225418.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gobot Gobot:

Patch Set 19: TryBot-Result+1

SlowBots are happy.
SlowBot builds that ran:

  • windows-386-2008
  • windows-amd64-2016
  • windows-amd64-race

Please don’t reply on this GitHub thread. Visit golang.org/cl/225418.
After addressing review feedback, remember to publish your drafts!

gopherbot pushed a commit that referenced this pull request May 19, 2020
This CL fixes unsafe casts to slices that are missing length or capacity.

Running tests with -d=checkptr enabled may panic on casting unsafe.Pointer to a static array of large predefined length, that is most likely much bigger than the size of the actual array in memory. Checkptr check is not satisfied if slicing operator misses length and capacity arguments `(*[(1 << 30) - 1]uint16)(unsafe.Pointer(p))[:]`, or when there is no slicing at all `(*[(1 << 30) - 1]uint16)(unsafe.Pointer(p))`.

To find all potential cases I used `grep -nr ")(unsafe.Pointer(" ./windows`, then filtered out safe casts when object size is always static and known at compile time.

To reproduce the issue run tests with checkptr enabled `go test -a -gcflags=all=-d=checkptr ./windows/...`.

Updates golang/go#34972
Fixes golang/go#38355

Change-Id: I9dd2084b4f9fb7618cdb140fb2f38b56b6d6cc04
GitHub-Last-Rev: 73288ad
GitHub-Pull-Request: #65
Reviewed-on: https://go-review.googlesource.com/c/sys/+/225418
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
@gopherbot
Copy link

Message from Alex Brainman:

Patch Set 19: Code-Review+2

LGTM

Thank you very much.

Alex


Please don’t reply on this GitHub thread. Visit golang.org/cl/225418.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

This PR is being closed because golang.org/cl/225418 has been merged.

@gopherbot gopherbot closed this May 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

x/sys/windows/svc/mgr: "checkptr: converted pointer straddles multiple allocations"
3 participants