2025 年 3 月 27 日より、AOSP のビルドとコントリビューションには aosp-main
ではなく android-latest-release
を使用することをおすすめします。詳細については、AOSP の変更をご覧ください。
カーネル制御フローの整合性
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
制御フロー整合性(CFI)は、コンパイル済みバイナリの元の制御フローグラフへの変更を許容しないセキュリティ メカニズムであり、そうした変更を行う攻撃を著しく困難にします。
Android 9 では、LLVM の CFI 実装がより多くのコンポーネントとカーネルで可能になりました。システム CFI はデフォルトで有効になっていますが、カーネル CFI は自分で有効にする必要があります。
LLVM の CFI は、リンク時最適化(LTO)を有効にしてコンパイルする必要があります。LTO は、リンク時までオブジェクト ファイルの LLVM ビットコード表現を保持します。これにより、コンパイラはどの最適化を実行できるかをより適切に判断できます。LTO を有効にすると、最終バイナリのサイズが小さくなり、パフォーマンスが向上しますが、コンパイル時間が長くなります。Android でのテストでは、LTO と CFI を組み合わせた場合、コードのサイズとパフォーマンスのオーバーヘッドは無視できるほどわずかであり、少数のケースでは両方とも改善が見られました。
CFI の技術的な詳細と、他の forward-control チェックの処理方法については、LLVM の設計ドキュメントをご覧ください。
実装
kCFI パッチは、サポートされているすべての Android カーネル バージョンに含まれています。CONFIG_CFI_CLANG
オプションは kCFI を有効にし、GKI でデフォルトで設定されます。
トラブルシューティング
有効にしたら、ドライバに存在する可能性がある型の不一致エラーを調べます。互換性のない関数ポインタによる間接的な関数呼び出しは、CFI エラーを発生させます。CFI エラーが検出されると、カーネルは、呼び出された関数と、失敗に至るスタックトレースの両方を含む警告を出力します。このエラーを解決するには、関数ポインタと呼び出される関数が常に同じ型を持つようにします。
CFI エラーのデバッグを行う際は、CONFIG_CFI_PERMISSIVE
を有効にすると便利です。これにより、カーネル パニックが発生する代わりに警告が出力されます。Permissive モードは、製品版では使用しないでください。
検証
現在、CFI 専用の CTS テストはありません。CFI がデバイスに影響しないことを確認するには、CFI を有効または無効にして CTS テストをパスするかどうかを検証してください。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-07-27 UTC。
[null,null,["最終更新日 2025-07-27 UTC。"],[],[],null,["# Kernel control flow integrity\n\n[Control flow\nintegrity](https://clang.llvm.org/docs/ControlFlowIntegrity.html) (CFI) is a security mechanism that disallows changes to the\noriginal control flow graph of a compiled binary, making it significantly harder\nto perform such attacks.\n\n\nIn Android 9, we enabled LLVM's implementation of CFI in more components and\nalso in the kernel. [System CFI](/docs/security/test/cfi) is on by\ndefault, but you need to enable kernel CFI.\n\n\nLLVM's CFI requires compiling with [Link-Time Optimization\n(LTO)](https://llvm.org/docs/LinkTimeOptimization.html). LTO preserves the LLVM bitcode representation of object files until\nlink-time, which allows the compiler to better reason about what optimizations\ncan be performed. Enabling LTO reduces the size of the final binary and improves\nperformance, but increases compile time. In testing on Android, the combination\nof LTO and CFI results in negligible overhead to code size and performance; in a\nfew cases both improved.\n\n\nFor more technical details about CFI and how other forward-control checks are\nhandled, see the [LLVM design\ndocumentation](https://clang.llvm.org/docs/ControlFlowIntegrityDesign.html).\n\nImplementation\n--------------\n\n\nThe kCFI patches are in all supported Android kernel versions. The `CONFIG_CFI_CLANG `\noption enables kCFI and is set by default in GKI.\n\n### Troubleshooting\n\n\nAfter enabling, work through any type mismatch errors that may exist with their\ndrivers. An indirect function call through an incompatible function pointer\ntrips CFI. When a CFI failure is detected, the kernel prints out a warning that\nincludes both the function that was called and the stacktrace that led to the\nfailure. Correct this by ensuring function pointers always have the same type as\nthe function that's called.\n\n\nTo assist in debugging CFI failures, enable `CONFIG_CFI_PERMISSIVE`,\nwhich prints out a warning instead of causing a kernel panic. Permissive mode\nmust not be used in production.\n\nValidation\n----------\n\n\nCurrently, there are no CTS test specifically for CFI. Instead, make sure that\nCTS tests pass with and without CFI enabled to verify that CFI isn't impacting\nthe device."]]