Skip to content

fix: check multiple paths for dde-lock caller in SetLocked#216

Merged
xionglinlin merged 1 commit into
linuxdeepin:masterfrom
xionglinlin:master
Jun 17, 2026
Merged

fix: check multiple paths for dde-lock caller in SetLocked#216
xionglinlin merged 1 commit into
linuxdeepin:masterfrom
xionglinlin:master

Conversation

@xionglinlin

Copy link
Copy Markdown
Contributor

Update the caller validation in SetLocked to support both /usr/bin/dde- lock and /usr/libexec/deepin/dde-lock paths, as the lock binary location may vary across different system configurations or distributions. Also improve error handling by separating the file read failure check from the caller verification, providing clearer warnings in each case.

Log: Extended SetLocked caller path validation to include alternative dde-lock location, improving compatibility

Influence:

  1. Test locking/unlocking screen from various callers (dde-lock at /usr/ bin/dde-lock and /usr/libexec/deepin/dde-lock)
  2. Verify that unauthorized callers are properly rejected with warning
  3. Test with missing or unreadable cmdline file for proper error handling
  4. Check system log for appropriate warning messages in each case

fix: SetLocked 中检查 dde-lock 调用者的多个路径

更新 SetLocked 中的调用者验证,支持 /usr/bin/dde-lock 和 /usr/libexec/ deepin/dde-lock 两个路径,因为锁屏二进制位置可能因系统配置或发行版而异。
同时改进错误处理,将文件读取失败检查与调用者验证分开,为每种情况提供更清
晰的警告信息。

Log: 扩展 SetLocked 调用者路径验证,包含备选的 dde-lock 位置,提高兼容性

Influence:

  1. 从不同调用者(/usr/bin/dde-lock 和 /usr/libexec/deepin/dde-lock)测试 锁屏/解锁功能
  2. 验证未授权调用者是否被正确拒绝并发出警告
  3. 测试 cmdline 文件缺失或不可读时的错误处理
  4. 检查系统日志中每种情况下的适当警告信息

PMS: BUG-366505 BUG-366367
Change-Id: I0398d751e6e5eb3ff83a0dbc36e7647793b5d797

Update the caller validation in SetLocked to support both /usr/bin/dde-
lock and /usr/libexec/deepin/dde-lock paths, as the lock binary location
may vary across different system configurations or distributions. Also
improve error handling by separating the file read failure check from
the caller verification, providing clearer warnings in each case.

Log: Extended SetLocked caller path validation to include alternative
dde-lock location, improving compatibility

Influence:
1. Test locking/unlocking screen from various callers (dde-lock at /usr/
bin/dde-lock and /usr/libexec/deepin/dde-lock)
2. Verify that unauthorized callers are properly rejected with warning
3. Test with missing or unreadable cmdline file for proper error
handling
4. Check system log for appropriate warning messages in each case

fix: SetLocked 中检查 dde-lock 调用者的多个路径

更新 SetLocked 中的调用者验证,支持 /usr/bin/dde-lock 和 /usr/libexec/
deepin/dde-lock 两个路径,因为锁屏二进制位置可能因系统配置或发行版而异。
同时改进错误处理,将文件读取失败检查与调用者验证分开,为每种情况提供更清
晰的警告信息。

Log: 扩展 SetLocked 调用者路径验证,包含备选的 dde-lock 位置,提高兼容性

Influence:
1. 从不同调用者(/usr/bin/dde-lock 和 /usr/libexec/deepin/dde-lock)测试
锁屏/解锁功能
2. 验证未授权调用者是否被正确拒绝并发出警告
3. 测试 cmdline 文件缺失或不可读时的错误处理
4. 检查系统日志中每种情况下的适当警告信息

PMS: BUG-366505 BUG-366367
Change-Id: I0398d751e6e5eb3ff83a0dbc36e7647793b5d797

@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 @xionglinlin, 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分

■ 【总体评价】

代码修复了deepin-turbo加速启动下的路径校验兼容性问题,但引入了严重的身份伪造安全漏洞
身份校验机制存在设计缺陷导致存在高危漏洞,依据安全优先原则强制限制最高得分为40分

■ 【详细分析】

  • 1.语法逻辑(基本正确)✓

代码将文件读取与合法性校验拆分为两个独立的if判断块,逻辑清晰。使用QString::fromUtf8处理QByteArray,能够正确处理/proc/pid/cmdline中以\0分隔的参数格式,截取第一个参数进行比对,符合预期逻辑。
潜在问题:无
建议:无

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

拆分了文件打开失败和调用者非法两种不同异常情况的日志输出,将具体的cmdline路径打印到日志中,极大提升了线上问题排查的效率。注释保留了关于deepin-turbo后续演进的技术债务说明。
潜在问题:无
建议:无

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

将原先的链式调用拆分为变量赋值,增加了一次QString对象的构造,但/proc/pid/cmdline文件极小,开销可忽略不计,对系统无性能影响。
潜在问题:(如无则省略此行)
建议:无

  • 4.代码安全(存在 1 个安全漏洞(高危1个))✕

漏洞对比统计:新增漏洞 1 个,减少漏洞 0 个,持平 0 个
身份校验机制完全依赖可被用户空间任意伪造的/proc/pid/cmdline,导致本地权限绕过

  • 安全漏洞1(高危):权限绕过/身份伪造 在 SessionManager::SetLocked 中,代码通过读取/proc//cmdline并使用startsWith判断调用者是否为dde-lock。由于cmdline内容来源于进程启动时的argv[0],任何本地普通用户均可编写恶意程序,将其argv[0]伪装为/usr/bin/dde-lock或/usr/libexec/deepin/dde-lock,随后调用该DBus接口即可绕过身份校验,触发未授权的锁屏或解锁操作,造成拒绝服务或安全机制失效 ——非常重要

  • 建议:废弃基于cmdline的身份校验,改用读取/proc//exe符号链接获取真实的可执行文件绝对路径进行比对,或结合DBus服务端的策略机制限制仅允许特定系统用户调用

■ 【改进建议代码示例】

diff --git a/src/dde-session/impl/sessionmanager.cpp b/src/dde-session/impl/sessionmanager.cpp
index e58608f..safe_check 100644
--- a/src/dde-session/impl/sessionmanager.cpp
+++ b/src/dde-session/impl/sessionmanager.cpp
@@ -496,13 +496,17 @@ void SessionManager::SetLocked(bool lock)
-    QFile file(cmdLine);
+    // 使用 /proc/<pid>/exe 获取真实可执行文件路径,防止 argv[0] 伪造
+    QString exePath = QString("/proc/%1/exe").arg(callerPid);
+    QFileInfo exeInfo(exePath);
 
-    // NOTE: 如果以deepin-turbo进行加速启动,这里是不准确的,可能需要判断desktop文件的全路径,不过deepin-turbo后续应该会放弃支持
-    if (!file.open(QIODevice::ReadOnly)) {
-        qWarning() << "SetLocked: failed to read caller cmdline:" << cmdLine;
+    if (!exeInfo.exists() || exeInfo.isSymLink()) {
+        qWarning() << "SetLocked: failed to read caller exe path:" << exePath;
         return;
     }
-    const QString caller = QString::fromUtf8(file.readAll());
-    if (!caller.startsWith("/usr/bin/dde-lock") && !caller.startsWith("/usr/libexec/deepin/dde-lock")) {
-        qWarning() << "SetLocked: illegal caller:" << caller;
+
+    // readLink 会解析符号链接指向的真实绝对路径
+    const QString realCallerPath = exeInfo.symLinkTarget();
+    if (realCallerPath != "/usr/bin/dde-lock" && realCallerPath != "/usr/libexec/deepin/dde-lock") {
+        qWarning() << "SetLocked: illegal caller:" << realCallerPath;
         return;
     }

@xionglinlin

Copy link
Copy Markdown
Contributor Author

@deepin-ci-robot
本次提交的代码review问题使用task记录:https://pms.uniontech.com/task-view-391207.html
后续可以考虑其他方式进行修改

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: xionglinlin, yixinshark, zccrs

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

@xionglinlin xionglinlin merged commit 1574a0e into linuxdeepin:master Jun 17, 2026
18 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.

4 participants