2025 年 3 月 27 日より、AOSP のビルドとコントリビューションには aosp-main
ではなく android-latest-release
を使用することをおすすめします。詳細については、AOSP の変更をご覧ください。
ファズ モジュール
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Rust ファジングは、LLVM の libFuzzer ファジング エンジンへのバインディングを提供する libfuzzer-sys
クレートを通じてサポートされています。詳しくは、libfuzzer-sys リポジトリと LLVM libFuzzer プロジェクトのページをご覧ください。
rust_fuzz
モジュールは、実行時にファジングを開始するファザー バイナリを生成します(cc_fuzz
モジュールと同様)。ファザーは libFuzzer
ファジング エンジンを利用しているため、ファジング制御のために多数の引数を取ることができます。これらは libFuzzer ドキュメントに記載されています。
rust_fuzz
モジュールは、rust_binary
モジュールの拡張であるため、同じプロパティと考慮事項を共有します。また、cc_fuzz
モジュールと同じプロパティと機能の多くが実装されています。
rust_fuzz
モジュールをビルドする際に、--cfg fuzzing
フラグが発行されます。これを使用してライブラリ コードの条件つきコンパイルをサポートし、ファジングを向上させることができます。
基本的な Rust ファザーを作成する
次のコードを使用して、Android.bp
ビルドファイルでファズ モジュールを定義できます。
rust_fuzz {
name: "example_rust_fuzzer",
srcs: ["fuzzer.rs"],
// Config for running the target on fuzzing infrastructure can be set under
// fuzz_config. This shares the same properties as cc_fuzz's fuzz_config.
fuzz_config: {
fuzz_on_haiku_device: true,
fuzz_on_haiku_host: false,
},
// Path to a corpus of sample inputs, optional. See https://llvm.org/docs/LibFuzzer.html#corpus
corpus: ["testdata/*"],
// Path to a dictionary of sample byte sequences, optional. See https://llvm.org/docs/LibFuzzer.html#dictionaries
dictionary: "example_rust_fuzzer.dict",
}
fuzzer.rs
ファイルには、単純なファザーが含まれています。
fn heap_oob() {
let xs = vec![0, 1, 2, 3];
let val = unsafe { *xs.as_ptr().offset(4) };
println!("Out-of-bounds heap value: {}", val);
}
fuzz_target!(|data: &[u8]| {
let magic_number = 327;
if data.len() == magic_number {
heap_oob();
}
});
この fuzz_target!(|data: &[u8]| { /* fuzz using data here */ });
は、libFuzzer
エンジンによって呼び出されるファズ ターゲット エントリ ポイントを定義します。data
引数は、libFuzzer
エンジンにより提供されるバイト シーケンスであり、ターゲット関数をファジングするための入力として扱われます。
このファザーの例では、データの長さのみがチェックされて heap_oob
関数を呼び出すかどうかが判断されますが、この関数を呼び出すと、境界外の読み取りが発生します。libFuzzer
はカバレッジに基づくファザーであるため、データの最初の 326 バイトから新しい実行パスが得られないと判断すると、問題となる長さにすばやく収束します。
この例はツリーの tools/security/fuzzing/example_rust_fuzzer/ にあります。
もう少し複雑な別のファザー(rustlib
依存関係をファジングする)の例をツリー内で確認するには、legacy_blob_fuzzer をご覧ください。
構造に対応する Rust ファザーの作成方法については、Rust Fuzz プロジェクトの公式ドキュメントである Rust Fuzz Book をご覧ください。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-04-04 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-04-04 UTC。"],[],[],null,["# Fuzz modules\n\nRust fuzzing is supported through the `libfuzzer-sys` crate, which provides\nbindings to LLVM's libFuzzer fuzzing engine. For more information, see the [libfuzzer-sys](https://github.com/rust-fuzz/libfuzzer)\nrepository as well as the [LLVM libFuzzer project page](https://llvm.org/docs/LibFuzzer.html).\n\nThe `rust_fuzz` module produces a fuzzer binary which begins fuzzing when it's\nrun (similar to `cc_fuzz` modules). As the fuzzer leverages the `libFuzzer`\nfuzzing engine, it can take a number of arguments to control fuzzing. These are\nenumerated in the [libFuzzer documentation](https://llvm.org/docs/LibFuzzer.html#options).\n\n`rust_fuzz` modules are an extension of `rust_binary` modules, and as such share\nthe same properties and considerations. Additionally, they implement many of the\nsame properties and functionality as do the `cc_fuzz` modules.\n\nWhen building `rust_fuzz` modules, the `--cfg fuzzing` flag is emitted which can\nbe used to support conditional compilation of library code to improve fuzzing.\n\nWrite a basic Rust fuzzer\n-------------------------\n\nYou can define a fuzz module in an `Android.bp` build file with this code: \n\n rust_fuzz {\n name: \"example_rust_fuzzer\",\n srcs: [\"fuzzer.rs\"],\n\n // Config for running the target on fuzzing infrastructure can be set under\n // fuzz_config. This shares the same properties as cc_fuzz's fuzz_config.\n fuzz_config: {\n fuzz_on_haiku_device: true,\n fuzz_on_haiku_host: false,\n },\n\n // Path to a corpus of sample inputs, optional. See https://llvm.org/docs/LibFuzzer.html#corpus\n corpus: [\"testdata/*\"],\n\n // Path to a dictionary of sample byte sequences, optional. See https://llvm.org/docs/LibFuzzer.html#dictionaries\n dictionary: \"example_rust_fuzzer.dict\",\n }\n\nThe `fuzzer.rs` file contains a simple fuzzer: \n\n fn heap_oob() {\n let xs = vec![0, 1, 2, 3];\n let val = unsafe { *xs.as_ptr().offset(4) };\n println!(\"Out-of-bounds heap value: {}\", val);\n }\n\n fuzz_target!(|data: &[u8]| {\n let magic_number = 327;\n if data.len() == magic_number {\n heap_oob();\n }\n });\n\nHere `fuzz_target!(|data: &[u8]| { /* fuzz using data here */ });` defines the\nfuzz-target entry-point called by the `libFuzzer` engine. The `data` argument is\na sequence of bytes provided by the `libFuzzer` engine to be manipulated as input\nto fuzz the targeted function.\n\nIn this example fuzzer, only the length of the data gets checked to determine\nwhether to call the `heap_oob` function, the calling of which results in an\nout-of-bounds read. `libFuzzer` is a coverage-guided fuzzer, so it quickly converges on the\nproblematic length as it determines that the first 326 B of data don't\nresult in new execution paths.\n\nLocate this example, in-tree, at [tools/security/fuzzing/example_rust_fuzzer/](https://android.googlesource.com/platform/tools/security/+/669e5608d5bea0171b4888bed099725c4300b346/fuzzing/example_rust_fuzzer/fuzzer.rs).\nTo view a slightly more complex example of another fuzzer (which fuzzes a `rustlib`\ndependency) in-tree, see the [legacy_blob_fuzzer](https://android.googlesource.com/platform/system/security/+/2f503e597130e1d65dbf9fb4cd0fbd6a2f9ccb07/keystore2/src/fuzzers/legacy_blob_fuzzer.rs).\n\nFor guidance on [how to write structure-aware Rust fuzzers](https://rust-fuzz.github.io/book/cargo-fuzz/structure-aware-fuzzing.html),\nsee the [Rust Fuzz book](https://rust-fuzz.github.io/book/introduction.html), the official documentation for the Rust Fuzz project."]]