]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: give useful failure message on mlock failure
authorAustin Clements <austin@google.com>
Thu, 5 Dec 2019 19:41:24 +0000 (14:41 -0500)
committerAustin Clements <austin@google.com>
Fri, 6 Dec 2019 15:19:52 +0000 (15:19 +0000)
Currently, we're ignoring failures to mlock signal stacks in the
workaround for #35777. This means if your mlock limit is low, you'll
instead get random memory corruption, which seems like the wrong
trade-off.

This CL checks for mlock failures and panics with useful guidance.

Updates #35777.

Change-Id: I15f02d3a1fceade79f6ca717500ca5b86d5bd570
Reviewed-on: https://go-review.googlesource.com/c/go/+/210098
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/runtime/os_linux_amd64.go

index 21e4790c5379aeb630fd4f03fc3c9bdb5986e76c..cbfcf2e40ab42e63f81c8e0a7e5c637c4988987c 100644 (file)
@@ -59,5 +59,13 @@ func osArchInit() {
 }
 
 func mlockGsignal(gsignal *g) {
-       mlock(gsignal.stack.hi-physPageSize, physPageSize)
+       if err := mlock(gsignal.stack.hi-physPageSize, physPageSize); err < 0 {
+               printlock()
+               println("runtime: mlock of signal stack failed:", -err)
+               if err == -_ENOMEM {
+                       println("runtime: increase the mlock limit (ulimit -l) or")
+               }
+               println("runtime: update your kernel to 5.4.2 or later")
+               throw("mlock failed")
+       }
 }