4 ms·
If you have to reverse-engineer the undocumented Go calling sequence to call Rust, you probably shouldn't be using that for security-critical crypto functions.
by Animats 7y ago
If you have to reverse-engineer the undocumented Go calling sequence to call Rust, you probably shouldn't be using that for security-critical crypto functions. The next time somebody changes something, there will be trouble.
This is especially an issue in a garbage collected language. If the only reference to something was passed from Go to Rust, will Go's GC marker find it? If it doesn't, everything will work just fine, until someday a garbage collection happens at the wrong moment.
In security critical code, that's probably exploitable if you can force a GC from another thread.
- yencabulator 7y ago> If the only reference to something was passed from Go to Rust, will Go's GC marker find it? No, and rightly so. I would expect https://golang.org/cmd/cgo/#hdr-Passing_pointers https://golang.org/cmd/cgo/#hdr-Passing_pointers to apply just as much here as with CGo (the criteria is "foreign allocator", not CGo).
- Animats 7y agoWhich is a problem here, because the OP is calling Rust from Go using the Go calling sequence. So Go's checking doesn't know it's calling non-Go code. There's a defined way to call C from Go, but the OP is not using that interface.
- yencabulator 7y agoIt's fine as long as you don't store Go pointers in non-Go memory. If the local variable is the last reference to the thing, https://golang.org/pkg/runtime/#KeepAlive https://golang.org/pkg/runtime/#KeepAlive makes sure the Go side doesn't drop it before the call is complete.