blob: b9eb8a34b3acd6c6d447f2f4b7cdb68cceb6fff0 [file] [log] [blame] [view]
Lukasz Anforowicz652bf4a2024-03-20 16:48:291# `unsafe` Rust Guidelines
2
Lukasz Anforowiczdf3d5af2024-03-20 18:21:163## Code Review Policy {#code-review-policy}
Lukasz Anforowicz652bf4a2024-03-20 16:48:294
5All `unsafe` Rust code in Chromium needs to be reviewed and LGTM-ed by a member
6of the `unsafe-rust-in-chrome@google.com` group and the review must be cc'd to
7the group for visibility. This policy applies to both third-party code
8(e.g. under `//third_party/rust`) and first-party code.
9
10To facilitate a code review please:
11
12* Add `unsafe-rust-in-chrome@google.com` to the CC line of a Gerrit code review.
13 - TODO(https://crbug.com/328789397): Automate this via Tricium or AyeAye.
14
15* For each new or modified `unsafe` block, function, `impl`, etc.,
16 add an unresolved "TODO: `unsafe` review" comment in Gerrit.
Lukasz Anforowicza80ca4b2024-09-06 21:55:0917 You can consider using `tools/crates/create_draft_comments.py` to streamline
18 creating such comments.
Lukasz Anforowicz652bf4a2024-03-20 16:48:2919
20Note that changes _anywhere_ in a crate that uses `unsafe` blocks may violate
21the internal invariants on which those `unsafe` blocks rely. It is unrealistic
22to require a `unsafe-rust-in-chrome@google.com` review to re-audit all the
23`unsafe` blocks each time a crate is updated, but the crate `OWNERS` and other
24reviewers should be on the lookout for code changes which feel as though they
25could affect invariants on which `unsafe` blocks rely.
26
27## `cargo vet` Policy {#cargo-vet-policy}
28
29All third-party Rust code in Chromium needs to be covered by `cargo vet` audits.
Lukasz Anforowicz3f6638cc2024-08-27 17:17:4830In other words, `tools/crates/run_cargo_vet.py check` should always succeed
31(this is enforced by `//third_party/rust/PRESUBMIT.py`).
Lukasz Anforowicz652bf4a2024-03-20 16:48:2932
33Audit criteria required for a given crate depend on how the crate is used. The
34criteria are written to
35`third_party/rust/chromium_crates_io/supply-chain/config.toml` by
36`tools/crates/run_gnrt.py vendor` based on whether
37`third_party/rust/chromium_crates_io/gnrt_config.toml` declares that the crate
38is meant to be used (maybe transitively) in a `safe`, `sandbox`, or `test`
39environment. For example, to declare that a crate is `safe` to be used in the
40browser process, it needs to be audited and certified to be `safe-to-deploy`,
41`ub-risk-2` or lower, and either `does-not-implement-crypto` or `crypto-safe`.
42
43Additional notes:
44
45* Some audits can be done by any engineer ("ub-risk-0" and "safe-to-run") while
46 others will require specialists from the `unsafe-rust-in-chrome@google.com`
47 group (see the ["Code Review Policy" above](#code-review-policy). More
48 details about audit criteria and the required expertise are explained in the
Lukasz Anforowicz85e0a352024-04-19 17:07:4849 [auditing_standards.md](https://github.com/google/rust-crate-audits/blob/main/auditing_standards.md),
Lukasz Anforowicz3f6638cc2024-08-27 17:17:4850 which also provides guidance for conducting delta audits.
Lukasz Anforowicz652bf4a2024-03-20 16:48:2951* See
52 [Cargo Vet documentation](https://mozilla.github.io/cargo-vet/recording-audits.html)
53 for how to record the audit in `audits.toml`.
Lukasz Anforowicz85e0a352024-04-19 17:07:4854 The `tools/crates/run_cargo_vet.py` may be used to invoke Chromium's copy of
55 `cargo-vet`.
Lukasz Anforowicz652bf4a2024-03-20 16:48:2956* Chromium uses both our own audits
57 (stored in `third_party/rust/chromium_crates_io/supply-chain/audits.toml`)
58 as well as audits imported from other parts of Google
59 (e.g. Android, Fuchsia, etc.). This means that adding a new crate does not
60 necessarily require a new audit if the crate has already been audited by
Lukasz Anforowicz85e0a352024-04-19 17:07:4861 other projects (in this case, `cargo vet` will record the imported audit
62 in the `third_party/rust/chromium_crates_io/supply-chain/imports.lock` file).
Lukasz Anforowicz652bf4a2024-03-20 16:48:2963