Skip to content

runtime: fix badsignal2 to initialize r3 with a valid address #50822

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

marler8997
Copy link

@marler8997 marler8997 commented Jan 26, 2022

We ran into an issue on the hololens which is an arm64 windows platform.
We noticed that in runtime.badsignal2 it would call WriteFile, but then
we would get an Access Violation inside it when it attempted to derefence
the lpNumberOfBytesWritten variable. It appears that runtime.badsignal2
is assigning this variable, which is a pointer, to whatever is in r13
(note this is assembly), but I don't see where r13 is initialized and in
our case it was set to 1, so WriteFile ended up dereferencing the value 1
causing the Access Violation.

This change initially modified the assembly to set r3 to 0 which would
fix the issue by allowing WriteFile to print the error message and then
return, however, according to Microsoft's docs, lpNumberOfBytesWritten
should only be assigned "NULL" if the overlapped argumet is not NULL, which
is not the case here. So I've updated the assembly code to set R3 to a
location on the stack.

Note that it's likely this issue hasn't been noticed because it occurs
right before an abort so the result ends up being almost the same except
the error message doesn't get printed to stderr. Also this would sometimes
work because whatever happens to be in r13 could be 0 or a valid pointer.

@marler8997

This comment has been minimized.

@gopherbot
Copy link
Contributor

This PR (HEAD: 1a53732) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/381196 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
Contributor

Message from Gopher Robot:

Patch Set 1:

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

Next steps:
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 or adds a tag like "wait-release", 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/381196.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Michael Knyszek:

Patch Set 1:

(1 comment)


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

@gopherbot
Copy link
Contributor

Message from Michael Knyszek:

Patch Set 1: Run-TryBot+1 Trust+1

(3 comments)


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

@gopherbot
Copy link
Contributor

Message from Gopher Robot:

Patch Set 1:

(1 comment)


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

@gopherbot
Copy link
Contributor

Message from Gopher Robot:

Patch Set 1:

(1 comment)


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

@gopherbot
Copy link
Contributor

Message from Michael Knyszek:

Patch Set 1:

(1 comment)


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

@gopherbot
Copy link
Contributor

Message from Gopher Robot:

Patch Set 1: TryBot-Result-1

(1 comment)


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

@gopherbot
Copy link
Contributor

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

Please visit https://go-review.googlesource.com/c/go/+/381196 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
Contributor

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

Please visit https://go-review.googlesource.com/c/go/+/381196 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

We ran into an issue on the hololens which is an arm64 windows platform.
We noticed that in runtime.badsignal2 it would call WriteFile, but then
we would get an Access Violation inside it when it attempted to derefence
the lpNumberOfBytesWritten variable. It appears that runtime.badsignal2
is assigning this variable, which is a pointer, to whatever is in r13
(note this is assembly), but I don't see where r13 is initialized and in
our case it was set to 1, so WriteFile ended up dereferencing the value 1
causing the Access Violation.

This change initially modified the assembly to set r3 to 0 which would
fix the issue by allowing WriteFile to print the error message and then
return, however, according to Microsoft's docs, lpNumberOfBytesWritten
should only be assigned "NULL" if the overlapped argumet is not NULL, which
is not the case here.  So I've updated the assembly code to set R3 to a
location on the stack.

Note that it's likely this issue hasn't been noticed because it occurs
right before an abort so the result ends up being almost the same except
the error message doesn't get printed to stderr. Also this would sometimes
work because whatever happens to be in r13 could be 0 or a valid pointer.
@gopherbot
Copy link
Contributor

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

Please visit https://go-review.googlesource.com/c/go/+/381196 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

@marler8997 marler8997 changed the title runtime/sys_windows_arm64: fix badsignal2 to initialize r3 to a defined value runtime: fix badsignal2 to initialize r3 with a valid address Jan 28, 2022
@gopherbot
Copy link
Contributor

Message from Jonathan Marler:

Patch Set 5:

(1 comment)


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

@gopherbot
Copy link
Contributor

Message from Jonathan Marler:

Patch Set 5: Code-Review+1

(1 comment)


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

@gopherbot
Copy link
Contributor

Message from Michael Pratt:

Patch Set 5: Code-Review+1

(1 comment)


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

@gopherbot
Copy link
Contributor

Message from Michael Knyszek:

Patch Set 5: Code-Review+2


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

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.

2 participants