自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
GWP-ASan 和 KFENCE
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
GWP-ASan 和 KFENCE 分別是使用者空間和核心的概率記憶體偵測工具。啟用後,系統會使用額外的記憶體頁面保護少數配置,這些頁面會環繞所分配的記憶體。這樣一來,您就能以微不足道的效能負載偵測緩衝區溢位和使用後釋放。即使受保護的配置有較低的取樣率,在大量部署時,仍能有效偵測記憶體安全錯誤。自推出以來,這些工具已協助我們找出許多平台錯誤,並證明自己是改善穩定性和安全性的有用工具。我們建議供應商啟用這些功能,並密切監控在使用者裝置上偵測到的錯誤。
開發人員應檢查 /data/tombstones
、logcat
或供應商 DropboxManager
管道,確認是否有使用者端錯誤。
詳情請參閱有關偵錯 Android 原生程式碼的說明文件。
偵錯原生 Android 平台程式碼arrow_forward
偵測使用者空間記憶體安全錯誤的 GWP-ASan
GWP-ASan 是在 Android 11 中針對使用者空間堆積分配作業推出。GWP-ASan 偵測到錯誤時,會使用 Cause: [GWP-ASan]:
記錄錯誤報告並終止程序。錯誤報告包含額外的配置和取消配置資訊,可讓您更輕鬆地找出根本原因。
系統啟動時,GWP-ASan 會隨機啟用 1% 的系統程序或應用程式,以及在 AndroidManifest.xml
檔案中設定 android:gwpAsanMode
的應用程式。
GWP-ASanarrow_forward
使用 KFENCE 偵測核心記憶體安全錯誤
Android 12 推出了用於核心堆積配置的 KFENCE。當 KFENCE 偵測到錯誤時,會記錄一個開始於 BUG: KFENCE,
的當機報告,並停用防護頁面並繼續執行。這可啟用可盡量減少對使用者體驗影響的核心錯誤偵測機制。
如要進一步瞭解 KFENCE,請參閱 https://www.kernel.org 的說明文件。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","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 (世界標準時間)。"],[],[],null,["# GWP-ASan and KFENCE are probabilistic memory detection tools for userspace\nand the kernel, respectively. When enabled, a small number of allocations are\nguarded with additional memory pages that surround the allocated memory.\nThis allows detecting buffer overflows and use-after-frees at a negligible\nperformance overhead. Even with a small sample rate for the guarded allocations,\nwhen deployed at scale they can effectively detect memory safety bugs.\nSince their introduction these tools have helped identify numerous platform\nbugs and have proved to be a valuable tool for improving stability and security.\nWe encourage vendors to enable them and to closely monitor the bugs detected on\nend user devices.\n\n\nDevelopers should check the presence of crashes by checking\n`/data/tombstones`, `logcat` or by monitoring the vendor\n[DropboxManager](https://developer.android.com/reference/android/os/DropBoxManager)\npipeline for end user bugs.\n\n\nFor more information see our docs on debugging Android native\ncode.\n[Debugging Native Android Platform Codearrow_forward](/docs/core/tests/debug)\n\nGWP-ASan for detecting userspace memory safety bugs\n---------------------------------------------------\n\n\nGWP-ASan was introduced in Android 11 for userspace\nheap allocations. When GWP-ASan detects a bug, it records a crash report with\n`Cause: [GWP-ASan]:` and terminates the process. The bug reports\ncontain additional allocation and deallocation information that make it easier\nto identify the root cause.\n\n\nGWP-ASan is randomly enabled, at start-up, for 1% of system processes or\napps and for applications that set the `android:gwpAsanMode` in their\n`AndroidManifest.xml` file.\n[GWP-ASanarrow_forward](https://developer.android.com/ndk/guides/gwp-asan)\n\nKFENCE for detecting kernel memory safety bugs\n----------------------------------------------\n\n\nAndroid 12 introduced KFENCE for kernel heap\nallocations. When KFENCE detects a bug, it records a crash report starting\nwith `BUG: KFENCE,` disables the guard pages and continues execution.\nThis enables a kernel bug detection mechanism that minimally impacts the user\nexperience.\n\n\nTo learn more about KFENCE see the documentation available at [https://www.kernel.org](https://www.kernel.org/doc/html/latest/dev-tools/kfence.html)"]]