fix(usb): disable all interfaces of composite receivers - #760
deepin-bot[bot] merged 1 commit into
Conversation
Reviewer's GuideThe PR centralizes USB authorization in a utility that validates interface paths, enumerates all sibling interfaces of the physical receiver, updates them consistently, and rolls back partial changes on failure. Existing control and boot-restoration flows now reuse this operation instead of rewriting paths to interface 0, while database state is updated only around successful authorization changes. Sequence diagram for composite USB authorizationsequenceDiagram
participant Control as ControlInterface
participant Utils as UsbAuthorizationUtils
participant Sysfs as USB sysfs
participant DB as EnableSqlManager
Control->>Utils: setInterfacesAuthorized(path, enable_device)
Utils->>Utils: interfacePaths(path, sysRoot)
Utils->>Sysfs: Read each sibling authorized state
Utils->>Sysfs: Write authorization for every interface
alt Any read or write fails
Utils->>Sysfs: Restore previously changed states
Utils-->>Control: false
else All interfaces updated
Utils-->>Control: true
Control->>DB: Update authorization record
end
Flow diagram for USB interface enumeration and validationflowchart TD
A[Selected interface path] --> B{Valid /devices path and interface format?}
B -- No --> F[Return failure]
B -- Yes --> C[Locate physical device directory]
C --> D[Enumerate sibling interface directories]
D --> E[Keep siblings with authorized files]
E --> G{Interfaces found?}
G -- No --> F
G -- Yes --> H[Return all interface paths]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="deepin-devicemanager-server/deepin-devicecontrol/src/enablecontrol/usbauthorizationutils.cpp" line_range="107-108" />
<code_context>
+ continue;
+ }
+
+ for (auto it = originalStates.crbegin(); it != originalStates.crend(); ++it)
+ writeAuthorized(sysRoot + it->first + "/authorized", it->second);
+ return false;
+ }
</code_context>
<issue_to_address>
**issue (broader_impact):** Rollback write failures are ignored, so `setInterfacesAuthorized` returns false even when one or more previously changed interfaces remain in the new authorization state instead of being restored.
**Triggers:** When a rollback write fails after a later interface operation fails.
**Suggested fix:** Check each rollback result, log the incomplete restoration, and expose the restoration failure to the caller.
</issue_to_address>ca10406 to
e74a640
Compare
Disable every interface belonging to the selected physical USB device. 禁用所选物理 USB 设备下的全部接口。 Log: 修复无线键鼠接收器仅禁用键盘的问题 PMS: BUG-377327 Influence: 复合 USB 接收器禁用、启用及持久化恢复行为。
e74a640 to
3bf3bab
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 语法正确,逻辑清晰。physicalDevicePath() 函数正确解析 USB 设备路径和接口路径,setInterfacesAuthorized() 实现了完整的授权设置流程(读取原始状态→写入新状态→设备级 toggle→失败回滚),边界条件处理完善。 2. 代码质量 ✅评价: 优秀 ✅ 通过 潜在问题:
建议: 代码结构清晰,注释完整。建议修正 controlinterface.h 中的版权年份格式,统一为 '2019-2026 UnionTech Software Technology Co., Ltd.'。 3. 代码性能 ✅评价: 优秀 ✅ 通过 潜在问题:
建议: 性能良好,资源使用合理。USB 设备接口数量通常少于 10 个,目录遍历开销可忽略。建议将 physicalDevicePath() 的结果传递给 interfacePaths() 以避免重复计算。 4. 代码安全 🔒评价: 优秀 ✅ 通过
安全漏洞详情: 建议: 存在0个安全漏洞。安全合规。physicalDevicePath() 包含路径遍历防护(检查 '..' 和 '/devices/' 前缀),authorized 文件值验证为 '0' 或 '1',文件写入操作检查返回值,回滚机制确保失败时恢复原始状态。 💡 改进建议代码示例// 修正版权年份格式
// SPDX-FileCopyrightText: 2019-2026 UnionTech Software Technology Co., Ltd.
// 避免重复调用 physicalDevicePath()
bool UsbAuthorizationUtils::setInterfacesAuthorized(const QString &path, bool authorized, const QString &sysRoot)
{
const QString devicePath = physicalDevicePath(path, sysRoot);
if (devicePath.isEmpty()) {
qWarning() << "No USB device found for" << path;
return false;
}
// 直接使用 devicePath 枚举接口,避免在 interfacePaths() 中重复调用
const QStringList interfaces = interfacePathsFromDevice(devicePath, sysRoot);
// ...
}本报告由 AI 代码审查工具自动生成 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: max-lvs, Resurgamz The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/merge |
Summary
Root Cause
Composite keyboard and mouse receivers expose separate interfaces. The existing code rewrote the selected mouse interface path from
:1.1to:1.0, which disabled the keyboard interface while leaving the mouse usable.Verification
deepin-devicecontroltarget successfullygit diff --checkpassedPMS: BUG-377327
Summary by Sourcery
Update USB receiver authorization so composite devices are handled consistently across control and restoration flows.
Bug Fixes:
Enhancements: