-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
runtime: signal handling: cgoSigtramp fails to save C callee-save registers. #18328
Labels
Comments
The repro case is a minor variation on the test-case added in change 34239, obtained by making a local variable live across the invocation of the deferred handler: $ diff -u $GOROOT/misc/cgo/testsanitizers/tsan9.go ./issue18328.go
--- /home/bcmills/src/go/misc/cgo/testsanitizers/tsan9.go 2016-12-15 11:54:46.895601246 -0800
+++ ./issue18328.go 2016-12-15 12:40:58.691484523 -0800
@@ -19,10 +19,14 @@
size_t n;
struct timeval tvstart, tvnow;
int diff;
+ void *prev = NULL, *cur;
gettimeofday(&tvstart, NULL);
for (n = 0; n < 1<<20; n++) {
- free(malloc(n));
+ cur = malloc(n);
+ free(prev);
+ prev = cur;
+
gettimeofday(&tvnow, NULL);
diff = (tvnow.tv_sec - tvstart.tv_sec) * 1000 * 1000 + (tvnow.tv_usec - tvstart.tv_usec);
@@ -32,6 +36,8 @@
break;
}
}
+
+ free(prev);
}
*/
import "C"
|
@ianlancetaylor: I'm guessing one of us should fix this. I'm happy to send a patch unless you want to do it yourself. |
CL https://golang.org/cl/34501 mentions this issue. |
CL https://golang.org/cl/35068 mentions this issue. |
gopherbot
pushed a commit
that referenced
this issue
Jan 12, 2017
Use R11 (a caller-saved temp register) instead of RBX (a callee-saved register). I believe this only affects linux/amd64, since it is the only platform with a non-trivial cgoSigtramp implementation. Updates #18328. Change-Id: I3d35c4512624184d5a8ece653fa09ddf50e079a2 Reviewed-on: https://go-review.googlesource.com/35068 Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
In programs using cgo,
runtime.setsig
registersruntime.cgoSigtramp
as the handler for signals to the runtime.cgoSigtramp
callssigtramp
, which callssigtrampgo
, which uses the Go calling convention. The Go convention treats all registers except the stack pointer and frame pointer as caller-save (#16922).In debugging #17641, I noticed that
cgoSigtramp
does not save the C callee-save registers before invoking those Go functions. If the call to the Go handler is forwarded through other C handlers (as in the case of TSAN interceptors; see #18255), that potentially results in corruption of the register contents and undefined behavior when control returns to the C caller.I am attempting to write a reproducible test-case and will post it here as an update.
The text was updated successfully, but these errors were encountered: