From 055e74f2a0d27b0fbad59ee3a59fa1766a37ad36 Mon Sep 17 00:00:00 2001 From: XuSt <50353838+itsXuSt@users.noreply.github.com> Date: Wed, 20 Mar 2024 13:08:50 +0800 Subject: [PATCH] fix: [247629/reboot] no auth aquired on reboot (#61) as title. Log: fix security issue. Bug: https://pms.uniontech.com/bug-view-247629.html --- src/service/bootmakerservice.cpp | 18 ++++++++++-------- src/service/data/com.deepin.bootmaker.policy | 15 ++++++++++++++- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/service/bootmakerservice.cpp b/src/service/bootmakerservice.cpp index 96476763..c9a74f09 100644 --- a/src/service/bootmakerservice.cpp +++ b/src/service/bootmakerservice.cpp @@ -29,7 +29,8 @@ #include #endif -const QString s_PolkitAction = "com.deepin.bootmaker"; +const QString s_PolkitActionCreate = "com.deepin.bootmaker.create"; +const QString s_PolkitActionReboot = "com.deepin.bootmaker.reboot"; /** @brief Polkit action authorization check. @@ -38,11 +39,14 @@ const QString s_PolkitAction = "com.deepin.bootmaker"; @note Available on linux/unix/macos platform. @return check passed. */ -bool checkAuthorization(qint64 pid) +bool checkAuthorization(qint64 pid, const QString &action) { #if defined (Q_OS_LINUX) || defined (Q_OS_UNIX) || defined (Q_OS_MAC) PolkitQt1::Authority::Result ret = PolkitQt1::Authority::instance()->checkAuthorizationSync( - s_PolkitAction, PolkitQt1::UnixProcessSubject(pid), PolkitQt1::Authority::AllowUserInteraction); + action, + PolkitQt1::UnixProcessSubject(pid), + PolkitQt1::Authority::AllowUserInteraction); + if (PolkitQt1::Authority::Yes == ret) { return true; } else { @@ -141,10 +145,8 @@ BootMakerService::~BootMakerService() void BootMakerService::Reboot() { Q_D(BootMakerService); - if (!d->checkCaller()) { - return; - } - d->bm->reboot(); + if (checkAuthorization(d->dbusCallerPid(), s_PolkitActionReboot)) + d->bm->reboot(); } void BootMakerService::Start() @@ -189,7 +191,7 @@ bool BootMakerService::Install(const QString &image, const QString &device, cons return false; } - if (!d->disableCheck && !checkAuthorization(d->dbusCallerPid())) { + if (!d->disableCheck && !checkAuthorization(d->dbusCallerPid(), s_PolkitActionCreate)) { return false; } diff --git a/src/service/data/com.deepin.bootmaker.policy b/src/service/data/com.deepin.bootmaker.policy index 6b0254c1..a52cdd80 100644 --- a/src/service/data/com.deepin.bootmaker.policy +++ b/src/service/data/com.deepin.bootmaker.policy @@ -5,7 +5,7 @@ LinuxDeepin https://www.deepin.com/ - + To create a bootable USB drive you need to authenticate. 创建启动盘需要您进行认证。 創建啓動盤需要您進行認證。 @@ -18,4 +18,17 @@ /usr/lib/deepin-daemon/deepin-boot-maker-service true + + Authentication is required to reboot the operating system. + 重启操作系统需要认证。 + 重啓作業系統需要認證。 + 重啟作業系統需要認證。 + + no + no + auth_admin_keep + + /usr/lib/deepin-daemon/deepin-boot-maker-service + true +