]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go.1.14] runtime: validate candidate searchAddr in pageAlloc.find
authorMichael Anthony Knyszek <mknyszek@google.com>
Mon, 13 Jul 2020 19:51:50 +0000 (19:51 +0000)
committerDmitri Shuralyov <dmitshur@golang.org>
Sat, 22 Aug 2020 01:24:38 +0000 (01:24 +0000)
commit060e0c868a6f856e41a198e78457672b97bbf76e
tree95283b4d7788528541ddf3926240565422699e30
parent73268bec86787cb8061baf9ab6f0fee3da1be7a4
[release-branch.go.1.14] runtime: validate candidate searchAddr in pageAlloc.find

Currently pageAlloc.find attempts to find a better estimate for the
first free page in the heap, even if the space its looking for isn't
necessarily going to be the first free page in the heap (e.g. if npages
>= 2). However, in doing so it has the potential to return a searchAddr
candidate that doesn't actually correspond to mapped memory, but this
candidate might still be adopted. As a result, pageAlloc.alloc's fast
path may look at unmapped summary memory and segfault. This case is rare
on most operating systems since the heap is kept fairly contiguous, so
the chance that the candidate searchAddr discovered is unmapped is
fairly low. Even so, this is totally possible and outside the user's
control when it happens (in fact, it's likely to happen consistently for
a given user on a given system).

Fix this problem by ensuring that our candidate always points to mapped
memory. We do this by looking at mheap's arenas structure first. If it
turns out our candidate doesn't correspond to mapped memory, then we
look at inUse to round up the searchAddr to the next mapped address.

While we're here, clean up some documentation related to searchAddr.

For #40191.
Fixes #40192.

Change-Id: I759efec78987e4a8fde466ae45aabbaa3d9d4214
Reviewed-on: https://go-review.googlesource.com/c/go/+/242680
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
(cherry picked from commit b56791cdea5caa87ffcd585d29c294bd3d08a06a)
Reviewed-on: https://go-review.googlesource.com/c/go/+/246197
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
src/runtime/mpagealloc.go
src/runtime/mpagealloc_test.go
src/runtime/mranges.go