Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upImplement a sandbox for environment variables and files #49387
Conversation
rust-highfive
assigned
nikomatsakis
Mar 26, 2018
This comment has been minimized.
This comment has been minimized.
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nikomatsakis (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
rust-highfive
added
the
S-waiting-on-review
label
Mar 26, 2018
This comment has been minimized.
This comment has been minimized.
|
OK, I'll fix up the Cargo.locks |
jsgf
force-pushed the
jsgf:rustc-env-sb
branch
4 times, most recently
from
a08ab09
to
9cd3650
Mar 26, 2018
jsgf
added a commit
to jsgf/rustfmt
that referenced
this pull request
Mar 26, 2018
jsgf
referenced this pull request
Mar 26, 2018
Closed
Update parser initialization to match rust-lang/rust#49387 #2566
This comment has been minimized.
This comment has been minimized.
|
Corresponding rustfmt PR rust-lang/rustfmt#2566 |
jsgf
force-pushed the
jsgf:rustc-env-sb
branch
10 times, most recently
from
611b892
to
0e98404
Mar 26, 2018
This comment has been minimized.
This comment has been minimized.
|
cc @michaelwoerister since this is slightly related to path remapping. |
This comment has been minimized.
This comment has been minimized.
|
Is there any kind of RFC etc? We do make various changes to rustc flags without them on occasion, but this seems like a series enough piece of design that it would be important to coordinate, no? |
This comment has been minimized.
This comment has been minimized.
|
There's no RFC, but I could write one up if needed - the pull request is basically what it would say though. Should I post it to internals to see what people think? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
jsgf
force-pushed the
jsgf:rustc-env-sb
branch
from
0e98404
to
ac0a5e4
Apr 3, 2018
This comment has been minimized.
This comment has been minimized.
jsgf
referenced this pull request
Apr 5, 2018
Open
RFC: Implement a sandbox for environment variables and files #2391
This comment has been minimized.
This comment has been minimized.
|
|
nikomatsakis
removed
the
S-waiting-on-review
label
Apr 11, 2018
This comment has been minimized.
This comment has been minimized.
|
Blocked on rust-lang/rfcs#2391 |
This comment has been minimized.
This comment has been minimized.
|
|
jsgf
added some commits
Mar 25, 2018
jsgf
force-pushed the
jsgf:rustc-env-sb
branch
from
9e0327c
to
dc1ed74
Apr 26, 2018
This comment has been minimized.
This comment has been minimized.
|
|
shepmaster
added
S-blocked
and removed
S-blocked
labels
May 7, 2018
pietroalbini
added
S-blocked
and removed
S-blocked
labels
May 14, 2018
kennytm
added
S-blocked
and removed
S-blocked
labels
May 21, 2018
pietroalbini
added
S-blocked
and removed
S-blocked
labels
May 28, 2018
TimNN
added
A-allocators
and removed
A-allocators
labels
Jun 5, 2018
pietroalbini
added
S-blocked
and removed
S-blocked
labels
Jun 25, 2018
TimNN
added
A-allocators
and removed
A-allocators
labels
Jul 3, 2018
This comment has been minimized.
This comment has been minimized.
|
Ping from triage! Thanks for your PR @jsgf. It looks like this PR is blocked on an RFC which is going to take some time to resolve, so we're closing this PR for now. Feel free to reopen in the future. |
jsgf commentedMar 26, 2018
•
edited
This PR introduces some simple sandboxing for process environment variables and for include files (collectively "system environment").
This is primarily to allow a build system to more precisely control the inputs to rustc which may affect the generated output. Rust has two mechanisms by which an input source can access ambient properties of rustc's system environment:
env!()andoption_env!()for reading environment variables, andinclude!()/include_str!()/include_bytes!()for reading arbitrary files.(This PR specifically does not intend to address any actual security concerns, since there are many other avenues that it does not attempt to control, such as compiler plugins/proc macros. However, it does help with unintentional problems which could result in later security problems if unaddressed.)
Environment Variables
rustc allows source code to directly access its process environment variables via the
env!()andoptional_env!()(pseudo-)macros. This poses a few of problems:PATHandLD_LIBRARY_PATH, for example) with environment the compiled code might want, and doesn't allow them to be set independentlyWe introduce the following new command-line options to allow the apparent environment to be controlled at a fine-grain level:
--env-clear- completely empty the logical environment visible toenv!()/optional_env!(), causing them to all fail/returnNone. Without any other options, this will completely disable environment variable access.--env-allow NAME- allow a specific environment variable to be read from the process environment--env-define NAME=VAL- define a logical environment variable. This does not need to be present in the actual process environment, or if it is, its value is overriddenBy default, the environment is completely open, leaving the existing behaviour unchanged. Once one of the options above is specified, accesses to environment variable become controlled accordingly.
Paths
Rust allows arbitrary other files to be directly included, either as more Rust source code (
include!()), a text string (include_str!()) or arbitrary binary data (include_bytes!()). These macros take a raw string which is used as a path which may be absolute - they therefore allow any file that rustc has permission to access to be used in the compiled output.(This differs from separating a crate into multiple source files, as those files are always relative to the top-level
lib.rs/main.rssource.)This causes a couple of problems:
To implement this, we introduce a couple of command-line options:
--clear-include-prefixes- clear all allowable prefixes, effectively disabling allinclude*!()macros--include-prefix PATH- addPATHto the set of valid prefixes. All included paths must match one of the valid path prefixes before it can be opened.All paths are canonicalized before matching, so they must exist at the time they're specified.
By default, all path prefixes are valid, leaving the current behaviour unchanged. They are only constrained once one of the options above are specified.
Note that a "path prefix" can be an entire pathname, allowing these options to explicitly specify which individual files may be included.
Rustfmt
Rustfmt uses the
ParseSess::with_span_handler()constructor, so I've updated it to use a default (unlimited) sandbox in rust-lang/rustfmt#2566.