Skip to content

on Linux, empty program panics if procfs is not mounted #22642

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
dwrensha opened this issue Feb 21, 2015 · 6 comments
Closed

on Linux, empty program panics if procfs is not mounted #22642

dwrensha opened this issue Feb 21, 2015 · 6 comments
Labels
I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. O-linux Operating system: Linux

Comments

@dwrensha
Copy link
Contributor

The program pub main(){} fails if procfs is not mounted:

thread '<unnamed>' panicked at 'failed to get thread attributes', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/sys/unix/thread.rs:84

It seems that the problem is a call to pthread_getattr_np() which tries to read /proc/self/maps and fails.

$ rustc --version
rustc 1.0.0-nightly (522d09dfe 2015-02-19) (built 2015-02-21)
@kmcallister kmcallister added O-linux Operating system: Linux A-io I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. labels Feb 21, 2015
@dwrensha dwrensha changed the title empty program panics on Linux if procfs is not mounted on Linux, empty program panics if procfs is not mounted Feb 21, 2015
@dwrensha
Copy link
Contributor Author

I found that I can work around this by defining my own entry point:

#![feature(start, std_misc)]

#[start]
fn start(argc: isize, argv: *const *const u8) -> isize {
    unsafe { ::std::rt::args::init(argc, argv); }
    // ...                                                                                            
    return 0;
}

@alexcrichton
Copy link
Member

Hm this is somewhat worrisome. It seems overly restrictive, but on the other hand it looks like the failure in question is our detection of the stack start of the main thread in setting up the first guard page. I forget how reliable it is that linux sets up a guard page for us, and it would be tough to remove for now at least.

@kentonv
Copy link

kentonv commented Feb 23, 2015

@alexcrichton could the code skip guard page creation when /proc is unavailable (as detected by pthread_getattr_np failing)? That seems better than failing to work at all, doesn't it?

@alexcrichton
Copy link
Member

Perhaps yes, I'd want to have a chance to look more into it though.

@psmit
Copy link

psmit commented Jul 15, 2015

Has there been any update regarding this issue? For an AI competition we want to isolate our processes and not mounting proc inside the chroot has served well for any other languages. Is there a workaround possible in code or compilation flags?

@dwrensha
Copy link
Contributor Author

@phsmit: You can work around the problem in code by defining your own entry point with the #[start] attribute.

Unfortunately, that's not an adequate solution in all situations, e.g. if you want to run rustc or cargo in a sandboxed environment.

alexcrichton added a commit to alexcrichton/rust that referenced this issue Jul 21, 2015
This can fail on linux for various reasons, such as the /proc filesystem not
being mounted. There are already many cases where we can't set up stack guards,
so just don't worry about this case and communicate that no guard was enabled.

I've confirmed that this allows the compiler to run in a chroot without /proc
mounted.

Closes rust-lang#22642
bors added a commit that referenced this issue Jul 21, 2015
This can fail on linux for various reasons, such as the /proc filesystem not
being mounted. There are already many cases where we can't set up stack guards,
so just don't worry about this case and communicate that no guard was enabled.

I've confirmed that this allows the compiler to run in a chroot without /proc
mounted.

Closes #22642
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. O-linux Operating system: Linux
Projects
None yet
Development

No branches or pull requests

5 participants