Lukasz Anforowicz | 652bf4a | 2024-03-20 16:48:29 | [diff] [blame] | 1 | # `unsafe` Rust Guidelines |
| 2 | |
Lukasz Anforowicz | df3d5af | 2024-03-20 18:21:16 | [diff] [blame] | 3 | ## Code Review Policy {#code-review-policy} |
Lukasz Anforowicz | 652bf4a | 2024-03-20 16:48:29 | [diff] [blame] | 4 | |
| 5 | All `unsafe` Rust code in Chromium needs to be reviewed and LGTM-ed by a member |
| 6 | of the `unsafe-rust-in-chrome@google.com` group and the review must be cc'd to |
| 7 | the group for visibility. This policy applies to both third-party code |
| 8 | (e.g. under `//third_party/rust`) and first-party code. |
| 9 | |
| 10 | To 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 Anforowicz | a80ca4b | 2024-09-06 21:55:09 | [diff] [blame] | 17 | You can consider using `tools/crates/create_draft_comments.py` to streamline |
| 18 | creating such comments. |
Lukasz Anforowicz | 652bf4a | 2024-03-20 16:48:29 | [diff] [blame] | 19 | |
| 20 | Note that changes _anywhere_ in a crate that uses `unsafe` blocks may violate |
| 21 | the internal invariants on which those `unsafe` blocks rely. It is unrealistic |
| 22 | to 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 |
| 24 | reviewers should be on the lookout for code changes which feel as though they |
| 25 | could affect invariants on which `unsafe` blocks rely. |
| 26 | |
| 27 | ## `cargo vet` Policy {#cargo-vet-policy} |
| 28 | |
| 29 | All third-party Rust code in Chromium needs to be covered by `cargo vet` audits. |
Lukasz Anforowicz | 3f6638cc | 2024-08-27 17:17:48 | [diff] [blame] | 30 | In other words, `tools/crates/run_cargo_vet.py check` should always succeed |
| 31 | (this is enforced by `//third_party/rust/PRESUBMIT.py`). |
Lukasz Anforowicz | 652bf4a | 2024-03-20 16:48:29 | [diff] [blame] | 32 | |
| 33 | Audit criteria required for a given crate depend on how the crate is used. The |
| 34 | criteria 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 |
| 38 | is meant to be used (maybe transitively) in a `safe`, `sandbox`, or `test` |
| 39 | environment. For example, to declare that a crate is `safe` to be used in the |
| 40 | browser 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 | |
| 43 | Additional 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 Anforowicz | 85e0a35 | 2024-04-19 17:07:48 | [diff] [blame] | 49 | [auditing_standards.md](https://github.com/google/rust-crate-audits/blob/main/auditing_standards.md), |
Lukasz Anforowicz | 3f6638cc | 2024-08-27 17:17:48 | [diff] [blame] | 50 | which also provides guidance for conducting delta audits. |
Lukasz Anforowicz | 652bf4a | 2024-03-20 16:48:29 | [diff] [blame] | 51 | * 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 Anforowicz | 85e0a35 | 2024-04-19 17:07:48 | [diff] [blame] | 54 | The `tools/crates/run_cargo_vet.py` may be used to invoke Chromium's copy of |
| 55 | `cargo-vet`. |
Lukasz Anforowicz | 652bf4a | 2024-03-20 16:48:29 | [diff] [blame] | 56 | * 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 Anforowicz | 85e0a35 | 2024-04-19 17:07:48 | [diff] [blame] | 61 | 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 Anforowicz | 652bf4a | 2024-03-20 16:48:29 | [diff] [blame] | 63 | |