Skip to content

Use unguessable pipeline ids - #10808

Closed
aneeshusa wants to merge 2 commits into
servo:masterfrom
aneeshusa:use-unguessable-pipeline-ids
Closed

aneeshusa wants to merge 2 commits into
servo:masterfrom
aneeshusa:use-unguessable-pipeline-ids

Conversation

@aneeshusa

Copy link
Copy Markdown
Contributor

Took a pass at #10542.

Also, we should definitely make the RNG instance once and then cache it, but I'm not sure of the best way to do that. (I could use TLS as was being used for the pipeline namespaces previously, but what's the best place to initialize the RNG?) This is especially important for OsRng because it tried to call getrandom every time new is called to see if the syscall is supported.


This change is Reviewable

@highfive

Copy link
Copy Markdown

Heads up! This PR modifies the following files:

  • @KiChjang: components/script/script_thread.rs, components/script_traits/lib.rs, components/script_traits/lib.rs

@highfive

Copy link
Copy Markdown

warning Warning warning

  • These commits modify script code, but no tests are modified. Please consider adding a test!

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Apr 22, 2016
@aneeshusa

Copy link
Copy Markdown
Contributor Author

Also, this requires a one-line change to webrender_traits, but I wanted to get some feedback before making a PR for that (just need to change the definition of PipelineId there to match this one.) I'm wondering if there's a way to avoid having to duplicate the PipelineId struct, though.

@aneeshusa
aneeshusa force-pushed the use-unguessable-pipeline-ids branch from f9d7168 to 06e35ff Compare April 22, 2016 16:29
@asajeffrey

Copy link
Copy Markdown
Contributor

We should try to share the RNG. Is there a uuid crate we could use for this?


Reviewed 3 of 3 files at r1, 2 of 9 files at r2.
Review status: 3 of 10 files reviewed at latest revision, 3 unresolved discussions, some commit checks failed.


components/msg/constellation_msg.rs, line 267 [r2] (raw file):
We are assuming no collisions in the bytes generated by the RNG, which is fine but should probably be documented.


components/msg/constellation_msg.rs, line 282 [r2] (raw file):
This is creating a new RNG each time, which may be expensive (think getting entropy from the keyboard expensive).


components/msg/constellation_msg.rs, line 309 [r2] (raw file):
Does this pass the orphan rule?


Comments from Reviewable

@jdm

jdm commented Apr 22, 2016

Copy link
Copy Markdown
Member

There's a uuid crate that we already use in other places in Servo.

@asajeffrey asajeffrey added S-awaiting-answer Someone asked a question that requires an answer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Apr 22, 2016
@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #10654) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Apr 22, 2016
@asajeffrey

Copy link
Copy Markdown
Contributor

Just realized a conflict between randomized pipeline ids and repeatability of stress testing: https://github.com/servo/servo/blob/master/components/compositing/constellation.rs#L1859 says "In order to get repeatability, we sort the pipeline ids," which isn't going to work if pipeline ids are unguessable.

@asajeffrey

Copy link
Copy Markdown
Contributor

@aneeshusa are you planning on picking this back up again? Using uuids as pipeline ids seems like the way to go. We'll lose a bit of test repeatability, but I think we can live with that.

@Ms2ger

Ms2ger commented Jun 8, 2016

Copy link
Copy Markdown
Contributor

@aneeshusa ping?

@aneeshusa

Copy link
Copy Markdown
Contributor Author

Started rebasing this to use the uuid crate. I'm getting the error no method named heap_size_of_children found for type uuid::Uuid in the current scope - I need to make a PR against the uuid crate adding heapsize support behind a Cargo flag, right?

Also @asajeffrey, I definitely agree that we should cache the RNG instance. What's the best place to cache it/way to do that?

@jdm

jdm commented Jun 8, 2016

Copy link
Copy Markdown
Member

It's also possible to use #[ignore_heap_size_of = "no heapsize impl for uuid"] for the time being to avoid the error.

@asajeffrey

Copy link
Copy Markdown
Contributor

@aneeshusa where to store the RNG for uuid generation depends on where we're going to do the uuid generation. If it's the constellation, we just need one RNG there, but if we want each pipeline to be able to generate sub-pipelines, we'll need to have an RNG per script thread.

@aneeshusa

Copy link
Copy Markdown
Contributor Author

Updated.

Now requires servo/webrender_traits#56 and servo/webrender#291.

I haven't added the caching yet. The RNG instance should be cached in the script thread, but I'm not sure how to easily get a reference to it from the HTMLIFrameElement so it can be used.

There is also a usage of fake_root_pipeline_id() in tests/unit/net/http_loader.rs that needs to be removed; I'm not exactly sure how to approach this.

@pcwalton

Copy link
Copy Markdown
Contributor

I'll r+ the changes to the dependent crates once @asajeffrey signs off on the design behind this change.

@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #10225) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Jun 16, 2016
@emilio

emilio commented Jul 4, 2016

Copy link
Copy Markdown
Member

Ping? Is this still alive? :)

aneeshusa added 2 commits July 5, 2016 04:33
This was being kept around for code in devtools/lib.rs, which itself was
a TODO. That TODO was fixed in b7de946 in October, allowing this method
to be removed as well.
Make PipelineIds unique and unforgeable, enacting a capability security
scheme and preventing spoofing.
This makes the only way to interact with a pipeline to be given its ID.

Previously, PipelineIds were (namespaced) incremented integers, making
them easy to generate but lacking the necessary security properties.

Now, each pipeline ID is a v4 UUID: an opaque 128 bit random token.
They are generated via a cryptographically-secure RNG (OsRng), which
provides the key properties of uniqueness and unguessability that
together make pipeline IDs unforgeable.
Uniqueness can be provided by any RNG with a sufficiently large period,
which will stop the same pipeline ID from being generated more than once.
However, in order for the RNG output to be unguessable (i.e. an attacker
cannot predict the next output based on previous outputs, or reconstruct
previous outputs if (part of) the internal RNG state is revealed), the
RNG must be cryptographically secure.
@aneeshusa
aneeshusa force-pushed the use-unguessable-pipeline-ids branch from 10f09a4 to c01833c Compare July 5, 2016 05:04
@aneeshusa

aneeshusa commented Jul 5, 2016 •

Copy link
Copy Markdown
Contributor Author

Rebased this and the required PRs; sorry about the delay. I was waiting on some WR changes to be merged and their version bumped in Servo, so I could rebase my bitrotted WR changes, so I could rebase this locally and test it.

@cbrewster cbrewster removed the S-needs-rebase There are merge conflict errors. label Jul 5, 2016
@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #12216) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Jul 5, 2016
@asajeffrey

Copy link
Copy Markdown
Contributor

Sorry about the delay. Only one comment, which is about using rand::thread_rng. Once it's rebased and squashed, this can be r=me.


Reviewed 3 of 11 files at r3, 9 of 9 files at r6.
Review status: all files reviewed at latest revision, 2 unresolved discussions, some commit checks failed.


components/msg/constellation_msg.rs, line 282 [r2] (raw file):

Previously, asajeffrey (Alan Jeffrey) wrote…

This is creating a new RNG each time, which may be expensive (think getting entropy from the keyboard expensive).

Use `rand::thread_rng` for this?

Comments from Reviewable

@asajeffrey asajeffrey removed the S-awaiting-review There is new code that needs to be reviewed. label Jul 13, 2016
@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-answer Someone asked a question that requires an answer. labels Jul 13, 2016
@aneeshusa

Copy link
Copy Markdown
Contributor Author

@asajeffrey I wrote about this in constellation_msg.rs but I'll recap - we need to have a cryptographically secure RNG, so we have to use OsRng. Cryptographic security is what provides the key property (actually one of two) of unguessability.

Let me know how I can change the wording to make this more clear, since this is a key part of the design and so I want the reasoning should be easily understood from the comments/commit message.

@asajeffrey

Copy link
Copy Markdown
Contributor

I don't think we need a cryptographically secure RNG, we just need something to make guessing attacks unlikely. I think thread_rng is going to be robust enough.

@asajeffrey asajeffrey added S-needs-squash Some (or all) of the commits in the PR should be combined. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Jul 18, 2016
@asajeffrey

Copy link
Copy Markdown
Contributor

I don't really mind about generating an RNG every time, as pipeline id generation doesn't happen that often. You can rebase, squash, and r=me.

@asajeffrey

Copy link
Copy Markdown
Contributor

@aneeshusa ping?

@aneeshusa

Copy link
Copy Markdown
Contributor Author

I don't have time to finish right now.

@aneeshusa aneeshusa closed this Aug 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-needs-rebase There are merge conflict errors. S-needs-squash Some (or all) of the commits in the PR should be combined.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants