Repository navigation
fix: use --print-reply for udev dbus-send to fix USB auto-refresh - #235
wangrong1069 wants to merge 1 commit into
Conversation
1. Root cause: USBadd.sh and USBremove.sh used fire-and-forget dbus-send (--type=method_call), so the caller process exited before DiskManagerService::checkAuthorization() could resolve its bus name via GetConnectionUnixUser, returning NameHasNoOwner and denying authorization - the UI refresh signal was never sent 2. Fix: add --print-reply flag to both scripts so the caller stays alive until the service finishes processing; udev runs as root (UID=0) so checkAuthorization passes the root identity check 3. Impact: USB hot-plug auto-refresh works again; udev scripts block ~5s (updateUsb sleep) well within the 30s default udev timeout; no C++ authorization model change Log: Fix USB hot-plug auto-refresh not working in disk manager Influence: 1. Test USB device insertion triggers auto-refresh in disk manager 2. Test USB device removal triggers auto-refresh in disk manager 3. Test rapid sequential plug/unplug of multiple USB devices for udev timeout or event loss fix: 修复udev脚本dbus-send为--print-reply以修复USB自动刷新 1. 根因:USBadd.sh 和 USBremove.sh 使用 fire-and-forget 模式的 dbus-send(--type=method_call),调用者进程在 DiskManagerService::checkAuthorization() 通过 GetConnectionUnixUser 解析 bus name 前即退出,返回 NameHasNoOwner 导致授权失败,界面刷新信号未发出 2. 方案:两个脚本各新增 --print-reply 标志,使调用者进程存活至 服务端处理完毕;udev 以 root 运行(UID=0),通过 root 身份 授权检查 3. 影响:USB 热插拔自动刷新恢复;udev 脚本阻塞约 5 秒 (updateUsb sleep)远低于 30 秒默认 udev 超时;不改变 C++ 授权安全模型 Log: 修复磁盘管理器USB热插拔不自动刷新的问题 Influence: 1. 测试插入USB设备后磁盘管理器界面自动刷新 2. 测试拔出USB设备后磁盘管理器界面自动刷新 3. 测试快速连续插拔多个USB设备,验证无udev超时或事件丢失 PMS: BUG-362437
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: wangrong1069 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 |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThe udev USB add/remove scripts now use blocking Sequence diagram for blocking USB add refresh authorizationsequenceDiagram
participant Udev as USBadd.sh
participant DBus as D-Bus
participant Service as DiskManagerService
participant Auth as GetConnectionUnixUser
participant UI as DiskManagerUI
Udev->>DBus: dbus-send --print-reply updateUsb
DBus->>Service: updateUsb()
Service->>Auth: GetConnectionUnixUser
Auth-->>Service: UID=0
Service->>Service: checkAuthorization()
Service-->>DBus: method reply
DBus-->>Udev: print reply
Service-->>UI: refresh signal
Sequence diagram for blocking USB remove refresh authorizationsequenceDiagram
participant Udev as USBremove.sh
participant DBus as D-Bus
participant Service as DiskManagerService
participant Auth as GetConnectionUnixUser
participant UI as DiskManagerUI
Udev->>DBus: dbus-send --print-reply updateUsbRemove
DBus->>Service: updateUsbRemove()
Service->>Auth: GetConnectionUnixUser
Auth-->>Service: UID=0
Service->>Service: checkAuthorization()
Service-->>DBus: method reply
DBus-->>Udev: print reply
Service-->>UI: refresh signal
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: [] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: [] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: [] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: [] 💡 改进建议代码示例本报告由 AI 代码审查工具自动生成 |
|
TAG Bot New tag: 6.0.28 |
|
TAG Bot New tag: 6.0.29 |
|
TAG Bot New tag: 6.0.30 |
Root Cause Analysis
USB hot-plug auto-refresh stopped working after a security hardening commit (
f6ada21) that changedDiskManagerService::checkAuthorization()to properly validate theGetConnectionUnixUserreply. The udev scripts (USBadd.sh,USBremove.sh) used fire-and-forgetdbus-send --type=method_call, so the caller process exited beforecheckAuthorization()could resolve its bus name —GetConnectionUnixUserreturnedNameHasNoOwner, authorization was denied, and the UI refresh signal was never emitted. A minimal DBus demo confirmed this: fire-and-forget mode fails authorization, while--print-reply(blocking) mode succeeds.Fix
Added the
--print-replyflag todbus-sendin bothservice/udev/USBadd.shandservice/udev/USBremove.sh, switching from fire-and-forget to blocking mode. The caller process now stays alive untilDiskManagerServicefinishes processing. Since udev scripts run as root (UID=0),checkAuthorization()resolves the caller identity and passes the root check. No C++ authorization model changes.Change Safety Assessment
Code Safety
dbus-sendlines are not the product of a previous bug fix — historical commits modified trigger conditions (ProcNumbercheck) and process detection, not thedbus-sendcall mode. This change does not revert any historical fix.references= 0); no callers are affected.PartedCore::updateUsb()containssleep(5), soUSBadd.shblocks ~5s under--print-reply. The default udev event timeout is 30s — 5s is well within bounds.PartedCore::updateUsbRemove()has no sleep and returns immediately. Different USB devices' udev events are handled by independent worker processes, so one device blocking 5s does not affect others. No udev timeout risk.Business Impact Scope
USB hot-plug auto-refresh in the disk manager. Users inserting or removing external drives will see the interface auto-refresh again.
Verification Suggestion
Test inserting/removing external USB drives and verify the disk manager UI auto-refreshes. Test rapid sequential plug/unplug of multiple devices for udev timeout or event loss.
根因分析
安全加固提交(
f6ada21)将DiskManagerService::checkAuthorization()改为正确校验GetConnectionUnixUser回复后,USB 热插拔自动刷新失效。udev 脚本(USBadd.sh、USBremove.sh)使用 fire-and-forget 模式的dbus-send --type=method_call,调用者进程在checkAuthorization()解析 bus name 前即退出——GetConnectionUnixUser返回NameHasNoOwner,授权被拒,界面刷新信号未发出。最小 DBus demo 已验证:fire-and-forget 模式授权失败,--print-reply(阻塞)模式授权成功。修复方案
在
service/udev/USBadd.sh和service/udev/USBremove.sh的dbus-send中新增--print-reply标志,从 fire-and-forget 改为阻塞模式。调用者进程存活至DiskManagerService处理完毕,udev 以 root 运行(UID=0),checkAuthorization()解析到 root 身份并通过检查。不改变 C++ 授权安全模型。改动安全评估
代码安全评估
dbus-send行非历史 bug 修复产物——历史提交修改的是触发条件(ProcNumber检查)和进程检测方法,未改dbus-send调用模式。本次改动不撤销任何历史修复。references= 0),无调用者受影响。PartedCore::updateUsb()含sleep(5),--print-reply模式下USBadd.sh阻塞约 5 秒。udev 默认事件超时 30 秒,5 秒远低于此限。PartedCore::updateUsbRemove()无 sleep,立即返回。不同 USB 设备的 udev 事件由独立 worker 进程并行处理,单个设备阻塞 5 秒不影响其他设备。无 udev 超时风险。业务影响范围
磁盘管理器 USB 热插拔自动刷新。用户插入或拔出外接硬盘时界面将恢复自动刷新。
验证建议
测试插入/拔出外接 USB 硬盘,验证磁盘管理器界面自动刷新。测试快速连续插拔多个设备,验证无 udev 超时或事件丢失。
Summary by Sourcery
Bug Fixes: