از 27 مارس 2025، توصیه می کنیم از android-latest-release
به جای aosp-main
برای ساختن و کمک به AOSP استفاده کنید. برای اطلاعات بیشتر، به تغییرات AOSP مراجعه کنید.
ماژول های فاز
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
Rust fuzzing از طریق جعبه libfuzzer-sys
پشتیبانی می شود، که اتصالات را به موتور فازی libFuzzer LLVM ارائه می کند. برای اطلاعات بیشتر، به مخزن libfuzzer-sys و همچنین صفحه پروژه LLVM libFuzzer مراجعه کنید.
ماژول rust_fuzz
یک باینری fuzzer تولید می کند که هنگام اجرا شروع به فاز شدن می کند (شبیه به ماژول های cc_fuzz
). همانطور که فازر از موتور فازی libFuzzer
استفاده می کند، می تواند چندین آرگومان برای کنترل فازی شدن نیاز داشته باشد. اینها در مستندات libFuzzer برشمرده شده اند.
ماژولهای rust_fuzz
توسعهای از ماژولهای rust_binary
هستند و به این ترتیب ویژگیها و ملاحظات یکسانی دارند. علاوه بر این، آنها بسیاری از ویژگی ها و عملکردهای مشابه ماژول های cc_fuzz
را پیاده سازی می کنند.
هنگام ساخت ماژولهای rust_fuzz
، پرچم --cfg fuzzing
منتشر میشود که میتواند برای پشتیبانی از کامپایل شرطی کد کتابخانه برای بهبود فازبندی استفاده شود.
یک Rust fuzzer اولیه بنویسید
شما می توانید یک ماژول fuzz را در یک فایل ساخت 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
حاوی یک fuzzer ساده است:
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 */ });
نقطه ورودی fuzz-target را تعریف می کند که توسط موتور libFuzzer
فراخوانی شده است. آرگومان data
، دنباله ای از بایت ها است که توسط موتور libFuzzer
ارائه می شود تا به عنوان ورودی برای فازی کردن تابع هدف دستکاری شود.
در این fuzzer مثال، فقط طول داده بررسی می شود تا مشخص شود که آیا تابع heap_oob
فراخوانی شود، فراخوانی آن منجر به خواندن خارج از محدوده می شود. libFuzzer
یک fuzzer هدایت پوشش است، بنابراین به سرعت در طول مشکل همگرا می شود زیرا تعیین می کند که 326 B اول داده منجر به مسیرهای اجرایی جدید نمی شود.
این مثال را در داخل درخت در tools/security/fuzzing/example_rust_fuzzer/ پیدا کنید. برای مشاهده یک مثال کمی پیچیدهتر از fuzzer دیگر (که وابستگی rustlib
را از بین میبرد) در درخت، به legacy_blob_fuzzer مراجعه کنید.
برای راهنمایی در مورد نحوه نوشتن Rust fuzzers آگاه از ساختار ، به کتاب Rust Fuzz ، مستندات رسمی پروژه Rust Fuzz مراجعه کنید.
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-07-29 بهوقت ساعت هماهنگ جهانی."],[],[],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."]]