การกรอง Syscall ของ GPU

Android 16 QPR2 เพิ่มมาโคร SELinux เพื่อเพิ่มความปลอดภัยให้กับไดรเวอร์เคอร์เนล มาโครนี้จะบล็อก IOCTL ที่ถูกจำกัดในการใช้งานจริง เช่น IOCTL ที่เลิกใช้งานแล้ว หรือ IOCTL สำหรับการพัฒนาไดรเวอร์เคอร์เนล นอกจากนี้ยังจำกัด IOCTL สำหรับการสร้างโปรไฟล์ไดรเวอร์ ให้เฉพาะแอปที่สามารถดีบักหรือเชลล์ได้ ใช้มาโครนี้เพื่อเพิ่มความปลอดภัย ของอุปกรณ์

การใช้งาน

หากต้องการเพิ่มความปลอดภัยให้อุปกรณ์ด้วยการกรอง Syscall แบบละเอียด ให้เรียกใช้มาโคร set_xperm_filter ใน SEPolicy ของอุปกรณ์ เช่น

# set_xperm_filter(target_context, allowed_target, unpriv_ioctls, restricted_ioctls, instrumentation_ioctls)
# Allow targets to harden their IOCTL interfaces by specifying
# unprivileged, blocked, and instrumentation-specific IOCTLs for appdomain.
#
# Parameters:
#   target_context: The target context to apply the filter to.
#   allowed_target: Additional `appdomain` target to exempt from hardened policy.
#     Allows for an allowlist of services, or gating by a target SDK.
#   unpriv_ioctls: IOCTLs to allow across appdomain.
#   restricted_ioctls: IOCTLs to deny across appdomain.
#   instrumentation_ioctls: IOCTLs intended to be used in development.
#     IOCTLs will be allowed from `shell` or `debuggable` applications.

define(`unpriv_gpu_ioctls', `0x0000, 0x0001, 0x0002')
define(`restricted_ioctls', `0x1110, 0x1111, 0x1112')
define(`instrumentation_gpu_ioctls', `0x2220, 0x2221, 0x2222')
set_xperm_filter(
  gpu_device,
  untrusted_app_sdk_gate,
  unpriv_ioctls,
  restricted_ioctls,
  instrumentation_ioctls)

คำจำกัดความของมาโครสำหรับ set_xperm_filter อยู่ใน system/sepolicy/public/te_macros

มาโครจะอนุญาต unpriv_ioctls บล็อก restricted_ioctls และจำกัด instrumentation_ioctls ให้กับกระบวนการ shell หรือแอป debuggable ตัวกรองมีผลกับแอปพลิเคชันที่เริ่มต้นจาก target_sdk ที่ระบุ

ฟีเจอร์นี้ได้รับการติดตั้งใช้งานในอุปกรณ์ Pixel ที่ใช้ GPU Mali (Pixel 6-9) Arm ได้จัดหมวดหมู่ IOCTL อย่างเป็นทางการในDocumentation/ioctl-categories.rstของรุ่น r54p2 เราจะดูแลรายการนี้ต่อไปในการเผยแพร่ไดรเวอร์ในอนาคต

ทดสอบ

ทำดังนี้เพื่อยืนยันลักษณะการทำงานของไดรเวอร์เคอร์เนล

  • ตรวจสอบว่าไดรเวอร์ไม่ได้บล็อก IOCTL ของแอปพลิเคชันที่ถูกต้อง และ

  • ยืนยันว่าแอปพลิเคชันที่ไม่น่าเชื่อถือไม่สามารถเรียกใช้เครื่องมือวัดและ IOCTL ที่จำกัดได้