Skip to content

chore: update device permissions for systemd service#56

Merged
fly602 merged 1 commit into
linuxdeepin:masterfrom
fly602:master
Jun 16, 2026
Merged

chore: update device permissions for systemd service#56
fly602 merged 1 commit into
linuxdeepin:masterfrom
fly602:master

Conversation

@fly602

@fly602 fly602 commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

In the deepin-face.service file, modify the DeviceAllow directive to grant read-write access for char-video4linux, and add new allowances for char-media, char-drm, and /dev/vpu0 with read-write permissions. This change ensures that the deepin-face service can access necessary hardware devices for its functionality, such as video capture, media processing, and graphics rendering, which may be required for proper operation.

Influence:

  1. Test that the deepin-face service starts successfully with the updated device permissions.
  2. Verify access to video devices (/dev/video4linux*), media devices (/ dev/media*), DRM devices (/dev/dri/*), and the specific device /dev/ vpu0.
  3. Ensure the service operates correctly when using camera or graphics resources.
  4. Confirm that permissions are appropriately scoped and do not introduce security vulnerabilities.

chore: 更新系统服务的设备权限

在 deepin-face.service 文件中,更新 DeviceAllow 指令,为 char- video4linux 授予读写权限,并添加对 char-media、char-drm 和 /dev/vpu0 的 读写权限。此更改确保 deepin-face 服务能够访问其功能所需的硬件设备,如视
频捕获、媒体处理和图形渲染,这对于正常运行可能是必要的。

Influence:

  1. 测试 deepin-face 服务在更新设备权限后能否正常启动。
  2. 验证对视频设备、媒体设备、DRM 设备和特定设备 /dev/vpu0 的访问权限。
  3. 确保服务在使用摄像头或图形资源时正常运行。
  4. 确认权限范围适当,不会引入安全漏洞。

PMS: BUG-364933

In the deepin-face.service file, modify the DeviceAllow directive to
grant read-write access for char-video4linux, and add new allowances
for char-media, char-drm, and /dev/vpu0 with read-write permissions.
This change ensures that the deepin-face service can access necessary
hardware devices for its functionality, such as video capture, media
processing, and graphics rendering, which may be required for proper
operation.

Influence:
1. Test that the deepin-face service starts successfully with the
updated device permissions.
2. Verify access to video devices (/dev/video4linux*), media devices (/
dev/media*), DRM devices (/dev/dri/*), and the specific device /dev/
vpu0.
3. Ensure the service operates correctly when using camera or graphics
resources.
4. Confirm that permissions are appropriately scoped and do not
introduce security vulnerabilities.

chore: 更新系统服务的设备权限

在 deepin-face.service 文件中,更新 DeviceAllow 指令,为 char-
video4linux 授予读写权限,并添加对 char-media、char-drm 和 /dev/vpu0 的
读写权限。此更改确保 deepin-face 服务能够访问其功能所需的硬件设备,如视
频捕获、媒体处理和图形渲染,这对于正常运行可能是必要的。

Influence:
1. 测试 deepin-face 服务在更新设备权限后能否正常启动。
2. 验证对视频设备、媒体设备、DRM 设备和特定设备 /dev/vpu0 的访问权限。
3. 确保服务在使用摄像头或图形资源时正常运行。
4. 确认权限范围适当,不会引入安全漏洞。

PMS: BUG-364933

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @fly602, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:40分

■ 【总体评价】

代码修复了人脸识别服务在严格沙箱模式下的设备访问失败问题,但引入了高危的权限过度授予安全漏洞
逻辑正确但因DRM设备写权限暴露及设备组范围过广导致严重安全扣分

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

systemd服务单元文件的语法完全符合规范,DeviceAllow指令正确使用了"设备名 权限"或"设备节点 权限"的标准格式,能够准确在DevicePolicy=closed的白名单机制下放行指定硬件

建议:保持当前语法格式

  • 2.代码质量(良好)✓

代码针对BUG描述中的V4L2摄像头、媒体设备、DRM显卡及VPU硬件进行了精准的权限补充,配置项分类清晰,直接解决了底层设备访问失败的核心矛盾

建议:增加注释说明为何需要这些特定设备的权限,以方便后续维护

  • 3.代码性能(无性能问题)✓

此处为静态的系统级设备访问控制列表(ACL)配置,仅在服务启动时由systemd解析并应用至内核的cgroup设备白名单中,不涉及运行时的算法复杂度或系统调用开销

建议:无需优化

  • 4.代码安全(存在 2 个安全漏洞)✕

漏洞对比统计:新增漏洞 2 个,减少漏洞 0 个,持平 0 个
代码在修补功能问题的同时破坏了沙箱的隔离性,通过粗粒度的设备组授权和不当的读写权限扩大了攻击面

  • 安全漏洞1(【高危】):权限过度授予 在 msic/systemd/deepin-face.service 中,DeviceAllow=char-drm rw 授予了人脸识别服务对所有DRM(直接渲染管理器)设备的读写权限。人脸识别作为后台特征比对服务,仅需读取图像帧,绝对不需要写入显卡设备。攻击者若利用deepin-face服务中的任意代码执行漏洞,可通过写权限直接操控显卡状态,导致系统图形界面崩溃(拒绝服务)或结合其他漏洞实现本地权限提升。——非常重要

  • 安全漏洞2(【中危】:设备访问控制范围过大 在 msic/systemd/deepin-face.service 中,DeviceAllow=char-video4linux rw 和 DeviceAllow=char-media rw 授予了对系统中所有V4L2和Media设备的全局读写权限,而非限定到具体的人脸识别摄像头设备节点(如/dev/video0)。这导致该服务可以越权访问系统中的其他摄像头、红外设备或多媒体硬件,造成用户隐私泄露或设备状态被恶意篡改。——非常重要

  • 建议:1. 将 char-drm 的权限从 rw 降级为 r,剥夺显卡写入能力;2. 废弃 char-video4linux 和 char-media 的组授权方式,改为明确指定具体的设备节点路径(如 /dev/video0 rw),遵循最小权限原则

■ 【改进建议代码示例】

--- a/msic/systemd/deepin-face.service
+++ b/msic/systemd/deepin-face.service
@@ -16,7 +16,10 @@ ProtectSystem=strict
 #ReadOnlyPaths=/usr/share/seetaface-models/
 ReadWritePaths=/var/log/deepin-face.log
 
-DeviceAllow=char-video4linux rw
-DeviceAllow=char-media rw
-DeviceAllow=char-drm rw
+# 限制仅访问特定的人脸识别摄像头及关联媒体设备,避免干扰其他硬件
+DeviceAllow=/dev/video0 rw
+DeviceAllow=/dev/media0 rw
+# DRM设备仅需读取图像帧,严禁授予写权限以防提权或导致图形崩溃
+DeviceAllow=char-drm r
 DeviceAllow=/dev/vpu0 rw
 DevicePolicy=closed

@fly602

fly602 commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

/dev/video0 硬编码 — 摄像头如果在 /dev/video1 就找不到,char-video4linux 能自动匹配所有视频设备,安全性一样但更健壮

/dev/media0 同理 — 序号不固定

char-drm r 只读 — Vulkan 渲染节点需要写权限提交命令缓冲区,只读会导致回退到 Lavapipe 软件模拟,实测 6881ms,跟不加一样慢

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: fly602, mhduiy

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@fly602 fly602 merged commit 5fc43b3 into linuxdeepin:master Jun 16, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants