GPU 系统调用过滤

Android 16 QPR2 添加了一个 SELinux 宏来强化内核驱动程序。此宏会阻止生产环境中的受限 IOCTL,例如已废弃的 IOCTL 或用于内核驱动程序开发的 IOCTL。它还将驱动程序分析的 IOCTL 限制为 shell 或可调试的应用。使用此宏可增强设备的安全性。

实现

如需通过精细的系统调用过滤来强化设备,请在设备的 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 设备(Pixel 6-9)上实现。Arm 已在其 r54p2 版本Documentation/ioctl-categories.rst 中提供了 IOCTL 的官方分类。 此列表将在未来的驱动程序版本中继续维护。

测试

执行以下操作来验证内核驱动程序的行为:

  • 检查驱动程序是否不会阻止合法的应用 IOCTL,

  • 验证不受信任的应用是否无法执行插桩和受限 IOCTL。