जीपीयू सिस्टम कॉल फ़िल्टरिंग

Android 16 क्यूपीआर 2 में, कर्नेल ड्राइवर को सुरक्षित बनाने के लिए SELinux मैक्रो जोड़ा गया है. यह मैक्रो, प्रोडक्शन में प्रतिबंधित IOCTL को ब्लॉक करता है. जैसे, अब काम न करने वाले IOCTL या कर्नेल ड्राइवर डेवलपमेंट के लिए IOCTL. यह ड्राइवर की प्रोफ़ाइलिंग के लिए, IOCTL को शेल या डीबग किए जा सकने वाले ऐप्लिकेशन तक सीमित करता है. अपने डिवाइस की सुरक्षा को बेहतर बनाने के लिए, इस मैक्रो का इस्तेमाल करें.

लागू करना

अपने डिवाइस को ज़्यादा सुरक्षित बनाने के लिए, उसके SEPolicy में set_xperm_filter मैक्रो को कॉल करें. उदाहरण के लिए:

# 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 से शुरू होने वाले ऐप्लिकेशन पर लागू होता है.

यह सुविधा, Mali GPU (Pixel 6-9) का इस्तेमाल करने वाले Pixel डिवाइसों पर लागू की गई है. Arm ने अपने r54p2 वर्शन के Documentation/ioctl-categories.rst में, अपने IOCTL को आधिकारिक तौर पर अलग-अलग कैटगरी में बांटा है. ड्राइवर के आने वाले वर्शन में भी, इस सूची को अपडेट किया जाता रहेगा.

टेस्ट

कर्नेल ड्राइवर के बर्ताव की पुष्टि करने के लिए, यह तरीका अपनाएं:

  • देखें कि ड्राइवर, सही ऐप्लिकेशन IOCTL को ब्लॉक न करे और,

  • पुष्टि करें कि भरोसेमंद न होने वाले ऐप्लिकेशन, इंस्ट्रूमेंटेशन और प्रतिबंधित IOCTL को एक्ज़ीक्यूट न कर पाएं.