-
Notifications
You must be signed in to change notification settings - Fork 18k
runtime: Race condition in map_fixed on Linux? #13256
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
Comments
I think you're right, but note that I think it can only happen if the Go program calls syscall.Mmap or if it calls C code that calls mmap. Unfortunately I don't see how we can fix this for the case of C code calling mmap. |
I think the race won't happen due to higher level locking.
(e.g. mheap is always locked before growing, so no other
thread could request the same address concurrently.)
|
@minux I agree that the runtime won't collide with itself, but a separate goroutine might be running at the same time and it might call syscall.Mmap explicitly. |
But there are other ways for goroutines to call syscall.Mmap with FIXED
mapping and collide with the runtime. I don't think we need to address
this: fixed mmaps are rare and the user should really know what they're
doing.
For example, you can always mmap into the heap arena reserved by the
Go runtime, and actually I had a use for that (use the garbage collector to
manage mmap'ed region)
|
Ah, yes, I see what you mean. We are only in trouble with MAP_FIXED, and that is not a case that is worth worrying about. I'm going to close this issue. @eloff please feel free to reopen if you think we are missing something. |
I think it's OK to close, it's in a fallback path for who knows which OS On Tue, Nov 17, 2015, 4:25 PM Ian Lance Taylor notifications@github.com
|
An mmap without MAP_FIXED can't succeed, because the original mmap that ran before the call to addrspace_free did not succeed. Well, I suppose it's possible that Go calls mmap, then some other thread calls munmap, then Go calls addrspace_free, then some other thread calls mmap, then Go calls mmap with MAP_FIXED. If there were a way to fix that we should do it, but I don't think there is. |
The previous call ignored the hint, but it did succeed at another address. On Tue, Nov 17, 2015, 11:42 PM Ian Lance Taylor notifications@github.com
|
I was reading the code in mem_linux.go, and discovered what seems to be a race condition in mmap_fixed. If a call to mmap happens between the check addrspace_free(v, n) and mmap(v, n, prot, flags|_MAP_FIXED, fd, offset), then another mmap that happens between the two calls could, at least in theory, return a region within the same address space. The subsequent mmap fixed will happily succeed, even if there is an existing mapping for part of that address space.
The text was updated successfully, but these errors were encountered: