فلترة طلبات النظام لوحدة معالجة الرسومات

يضيف Android 16 QPR2 ماكرو SELinux لتعزيز أمان برامج تشغيل النواة. يحظر هذا الماكرو عناصر IOCTL المحظورة في مرحلة الإنتاج، مثل عناصر IOCTL التي تم إيقافها أو تلك الخاصة بتطوير برامج تشغيل النواة. ويفرض أيضًا قيودًا على عناصر IOCTL الخاصة بإنشاء ملفات تعريف برامج التشغيل لتطبيقات shell أو التطبيقات القابلة لتصحيح الأخطاء. استخدِم هذا الماكرو لتعزيز أمان جهازك.

التنفيذ

لتعزيز أمان جهازك باستخدام فلترة دقيقة لطلبات النظام، استخدِم ماكرو set_xperm_filter في سياسة SELinux لجهازك، على سبيل المثال:

# 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 التي تستخدم وحدة معالجة الرسومات Mali (من Pixel 6 إلى Pixel 9). قدّمت شركة Arm تصنيفًا رسميًا لعناصر IOCTL في Documentation/ioctl-categories.rst في إصدار r54p2. وسيتم الحفاظ على هذه القائمة في إصدارات برامج التشغيل المستقبلية.

اختبار

اتّبِع الخطوات التالية للتحقّق من سلوك برنامج تشغيل النواة:

  • تأكَّد من أنّ برنامج التشغيل لا يحظر عناصر IOCTL المشروعة للتطبيق،

  • تأكَّد من أنّ التطبيقات غير الموثوق بها لا يمكنها تنفيذ عناصر IOCTL الخاصة بالتتبُّع والقياس والمحظورة.