Skip to content

Boostraped rustc fails in thread initialization on NetBSD #50313

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

Closed
MartinHusemann opened this issue Apr 29, 2018 · 3 comments
Closed

Boostraped rustc fails in thread initialization on NetBSD #50313

MartinHusemann opened this issue Apr 29, 2018 · 3 comments
Labels
O-netbsd Operating system: NetBSD

Comments

@MartinHusemann
Copy link
Contributor

Trying to build rustc on NetBSD fails, after creating a local rustc, it fails when invoked for the first time:

thread 'main' panicked at 'unable to reset the guard page',libstd/sys/unix/thread.rs:361:21

I have no idea why that mprotect() call fails, it would be helpfull if the panic would mention the address and the return value.

Unfortunately I can't just invoke the same binary manually as it needs some secret/hidden environment setup to work.

@MartinHusemann
Copy link
Contributor Author

I could at least trace it, so the failing call is:

8094 1 rustc CALL mprotect(0x7f7fff006000,0x1000,3)
8094 1 rustc RET mprotect -1 errno 13 Permission denied

which looks like a properly aligned stack address, 1 page, and RW mapping request.

@MartinHusemann
Copy link
Contributor Author

... and the corresponding mmap worked and returned the same address, so all looks fine:

8094 1 rustc CALL mmap(0x7f7fff006000,0x1000,PROT_NONE,0x1012<PRIVATE,FIXED,,,>,0xffffffff,0,0)
8094 1 rustc RET mmap 140187715788800/0x7f7fff006000

I'm puzzled

@MartinHusemann
Copy link
Contributor Author

Found it:
with PAX MPROTECT enabled (which we do by default), it is not allowed to mprotect() to something less restrictive than the initial mmap() did.

Fix is simple: change the initial mmap() to MAP_READ|MAP_WRITE and do an mprotect(0) right away. This creates a mapping that allows later mprotect(MAP_READ|MAP_WRITE).

@estebank estebank added A-build O-netbsd Operating system: NetBSD labels May 1, 2018
bors added a commit that referenced this issue May 10, 2018
Map the stack guard page with max protection on NetBSD

On NetBSD the initial mmap() protection of a mapping can not be made
less restrictive with mprotect().

So when mapping a stack guard page, use the maximum protection
we ever want to use, then mprotect() it to the permission we
want it to have initially.

Fixes #50313
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-netbsd Operating system: NetBSD
Projects
None yet
Development

No branches or pull requests

2 participants