2025년 3월 27일부터 AOSP를 빌드하고 기여하려면 aosp-main
대신 android-latest-release
를 사용하는 것이 좋습니다. 자세한 내용은 AOSP 변경사항을 참고하세요.
Fuzz 모듈
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Rust 퍼징은 LLVM의 libFuzzer 퍼징 엔진으로의 바인딩을 제공하는 libfuzzer-sys
크레이트를 통해 지원됩니다. 자세한 내용은 libfuzzer-sys 저장소 및 LLVM libFuzzer 프로젝트 페이지를 참고하세요.
rust_fuzz
모듈은 (cc_fuzz
모듈과 비슷하게) 실행되면 퍼징을 시작하는 퍼저 바이너리를 생성합니다. 퍼저는 libFuzzer
퍼징 엔진을 사용하므로 여러 인수를 받아서 퍼징을 제어할 수 있습니다. 인수는 libFuzzer 도움말에 나와 있습니다.
rust_fuzz
모듈은 rust_binary
모듈의 확장이기 때문에 rust_binary 모듈과 동일한 속성 및 고려 사항을 공유합니다. 또한 cc_fuzz
모듈과 여러 동일한 속성 및 기능을 구현합니다.
rust_fuzz
모듈을 빌드하는 경우 라이브러리 코드의 조건부 컴파일을 지원하여 퍼징을 향상하는 데 사용할 수 있는 --cfg fuzzing
플래그는 생략됩니다.
기본 Rust fuzzer 작성
다음 코드를 사용하여 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
엔진에 의해 호출되는 fuzz-target 진입점을 정의합니다. data
인수는 libFuzzer
엔진이 제공하는 바이트로 이루어진 시퀀스로, 타겟팅된 함수의 퍼징을 위한 입력으로서 조작됩니다.
이 퍼저 예에서는 heap_oob
함수를 호출할지 여부를 판단하기 위해 데이터의 길이만 검사되며, 호출의 결과로 범위 외 읽기가 발생합니다. libFuzzer
는 커버리지 기반 퍼저이므로 데이터의 처음 326B의 결과로 새로운 실행 결과가 생성되지 않는다는 사실을 확인하면 문제가 되는 길이로 빠르게 수렴합니다.
이 예는 tools/security/fuzzing/example_rust_fuzzer/의 트리에서 확인할 수 있습니다.
트리에서 (rustlib
종속 항목을 퍼징하는) 다른 퍼저의 보다 복잡한 예를 보려면 legacy_blob_fuzzer를 참고하세요.
구조 인식 Rust 퍼저를 작성하는 방법을 알아보려면 Rust Fuzz 프로젝트 공식 도움말인 Rust Fuzz 북을 참고하세요.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(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-07-27(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."]]