ตั้งแต่วันที่ 27 มีนาคม 2025 เป็นต้นไป เราขอแนะนำให้ใช้ android-latest-release
แทน aosp-main
เพื่อสร้างและมีส่วนร่วมใน AOSP โปรดดูข้อมูลเพิ่มเติมที่หัวข้อการเปลี่ยนแปลงใน AOSP
ความสมบูรณ์ของการควบคุมโฟลว์เคอร์เนล
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ความสมบูรณ์ของโฟลว์การควบคุม (CFI) คือกลไกการรักษาความปลอดภัยที่ไม่อนุญาตให้เปลี่ยนแปลงกราฟโฟลว์การควบคุมเดิมของไบนารีที่คอมไพล์แล้ว ซึ่งทำให้การโจมตีดังกล่าวทำได้ยากขึ้นอย่างมาก
ใน Android 9 เราได้เปิดใช้ CFI ของ LLVM ในคอมโพเนนต์เพิ่มเติมและในเคอร์เนลด้วย CFI ของระบบจะเปิดอยู่โดยค่าเริ่มต้น แต่คุณต้องเปิดใช้ CFI ของเคอร์เนล
CFI ของ LLVM กำหนดให้ต้องคอมไพล์ด้วยการเพิ่มประสิทธิภาพเวลาลิงก์ (LTO) LTO จะเก็บรักษาการนำเสนอบิตโค้ด LLVM ของไฟล์ออบเจ็กต์ไว้จนกว่าจะถึงเวลาลิงก์ ซึ่งช่วยให้คอมไพเลอร์สามารถหาเหตุผลเกี่ยวกับการเพิ่มประสิทธิภาพที่ทำได้ดีขึ้น การเปิดใช้ LTO จะลดขนาดของไบนารีขั้นสุดท้ายและปรับปรุงประสิทธิภาพ แต่จะทำให้เวลาคอมไพล์นานขึ้น ในการทดสอบบน Android พบว่าการใช้ LTO และ CFI ร่วมกันทำให้ขนาดและประสิทธิภาพของโค้ดเพิ่มขึ้นเพียงเล็กน้อย และในบางกรณีก็ทำให้ทั้ง 2 อย่างดีขึ้น
ดูรายละเอียดทางเทคนิคเพิ่มเติมเกี่ยวกับ CFI และวิธีจัดการการตรวจสอบการควบคุมแบบส่งต่ออื่นๆ ได้ที่เอกสารประกอบการออกแบบ LLVM
การใช้งาน
การแก้ไข kCFI มีอยู่ในเคอร์เนล Android ทุกเวอร์ชันที่รองรับ ตัวเลือก CONFIG_CFI_CLANG
จะเปิดใช้ kCFI และตั้งค่าไว้โดยค่าเริ่มต้นใน GKI
การแก้ปัญหา
หลังจากเปิดใช้แล้ว ให้แก้ไขข้อผิดพลาดประเภทไม่ตรงกันซึ่งอาจเกิดขึ้นกับไดรเวอร์ การเรียกใช้ฟังก์ชันโดยอ้อมผ่านตัวชี้ฟังก์ชันที่ใช้ร่วมกันไม่ได้ทำให้ CFI หยุดทำงาน เมื่อตรวจพบข้อผิดพลาด CFI เคอร์เนลจะพิมพ์คำเตือนที่รวมทั้งฟังก์ชันที่เรียกใช้และสแต็กเทรซที่ทําให้เกิดความผิดพลาด แก้ไขโดยตรวจสอบว่าตัวชี้ฟังก์ชันมีประเภทเดียวกับฟังก์ชันที่เรียกใช้เสมอ
หากต้องการช่วยแก้ไขข้อผิดพลาด CFI ให้เปิดใช้ CONFIG_CFI_PERMISSIVE
ซึ่งจะพิมพ์คำเตือนแทนที่จะทำให้เกิด Kernel Panic ต้องไม่ใช้โหมดอนุญาตในเวอร์ชันที่ใช้งานจริง
การตรวจสอบความถูกต้อง
ปัจจุบันยังไม่มีการทดสอบ CTS สำหรับ CFI โดยเฉพาะ แต่ให้ตรวจสอบว่าการทดสอบ CTS ผ่านทั้งที่มีและไม่มีการเปิดใช้ CFI เพื่อยืนยันว่า CFI ไม่ได้ส่งผลต่ออุปกรณ์
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ 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,["# 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."]]