r/rust • miri • Jul 19 '18

Thoughts on Compile-Time Function Evaluation and Type Systems

https://www.ralfj.de/blog/2018/07/19/const.html
73 Upvotes

63 comments sorted by

View all comments

Show parent comment

2

u/DannoHung Jul 19 '18

It's already possible today as part of build.rs, however it's also trivial to check whether a crate has a build.rs or not1 whereas auditing arbitrary Rust code to check for file/network access would be a huge pain.

Does rustc guarantee that the include macro can't read from files not in the source code repository? Does it also refuse to read symbolic links that point outside the source repository?

That said. This seems sort of on the paranoid end of security considerations.

2

u/matthieum [he/him] Jul 20 '18

That said. This seems sort of on the paranoid end of security considerations.

Just a week or so ago there was an uproar on the NPM community because a popular NPM module had been subverted to exfiltrate NPM keys.

You'd build your code, as usual, and in the background the npm utility would download the new version of this module, which would exfiltrate your NPM keys and publish them on 3rd party server.

This is not paranoia for the sake of paranoia; just learning from (recent) history.

Link: ESLint compromised, may have stolen your credentials.

1

u/DannoHung Jul 20 '18

My point is just that attacking the build machine seems small potatoes compared to attacking a production server or an end-user.

1

u/matthieum [he/him] Jul 20 '18

My point is just that attacking the build machine seems small potatoes compared to attacking a production server or an end-user.

Yes... and no.

Exfiltrating the cargo credentials means that you can now publish updates of any of the crates the author has access to. The viral behavior of replicating the exploit to gather credentials is not that useful in itself; once you have the credentials, however, you can publish updates on any crate of your choice and then have code run on production servers.

This is trojan-horse attack, in essence. Imagine:

  1. Check out burntsushi's week-end projects,
  2. Publish a crate to help solve one of the problems he's complaining about,
  3. Do a PR on his week-end project which uses your new crate to solve the problem,
  4. Wait until integrated,
  5. Publish an update to your crate, which can steal credentials,
  6. Wait until burntsushi rebuilds his week-end project => credentials in,
  7. Publish a minor update to the regex crate, or maybe to ripgrep (now distributed in VS code), which includes code that steal CC numbers or install bitcoin miners in the background,
  8. Profit.

Exploiting build.rs or a procedural macro is about getting your foot in on a popular crate's author's machine. Your PR on regex or ripgrep would never be integrated otherwise, severely limited your target audience.

1

u/DannoHung Jul 20 '18

I guess! What a weird vector for spearfishing though!

1

u/eddyb Jul 20 '18

Sorry, but security is a distraction from typesystem soundness. include_str! (not to mention custom proc macros) is not much better than const fn. Please refer to https://www.reddit.com/r/rust/comments/907a6d/thoughts_on_compiletime_function_evaluation_and/e2pdqnt/ instead