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 到 Pixel 9) 上實作。Arm 已在 r54p2 版本中提供 IOCTL 的官方分類。Documentation/ioctl-categories.rst我們會在日後發布的驅動程式版本中持續維護這份清單。
測試
請按照下列步驟驗證核心驅動程式的行為:
確認驅動程式不會封鎖合法的應用程式 IOCTL,
確認不受信任的應用程式無法執行檢測和受限的 IOCTL。