fix(power): secure system power actions - #157
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: mhduiy 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 GuideIntegrates explicit caller authorization into the system Power1 service: trusted callers are registered and persisted with UID/PID validation, privileged power mutations are gated by an internal allow‑list plus Polkit, SetAllowCaller is restricted via D‑Bus policy, and Polkit/deepin‑security‑loader build/runtime deps are added. Sequence diagram for Power1 caller authorization on privileged power actionssequenceDiagram
actor Caller
participant SystemPowerManager
participant PolkitAuthority
Caller->>SystemPowerManager:SetMode
SystemPowerManager->>SystemPowerManager:authorizePowerAction
alt calledFromDBus() is false
SystemPowerManager->>SystemPowerManager:setMode
SystemPowerManager-->>Caller:mode updated
else calledFromDBus() is true
SystemPowerManager->>SystemPowerManager:isAllowedCaller
alt isAllowedCaller returns true
SystemPowerManager->>SystemPowerManager:setMode
SystemPowerManager-->>Caller:mode updated
else lookupFailed is true
SystemPowerManager->>Caller:sendErrorReply
else not allowed and lookup ok
SystemPowerManager->>PolkitAuthority:checkAuthorizationSync(kPowerAction)
alt PolkitQt1::Authority::Yes
SystemPowerManager->>SystemPowerManager:setMode
SystemPowerManager-->>Caller:mode updated
else hasError or result != Yes
SystemPowerManager->>Caller:sendErrorReply
end
end
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
1. Register trusted callers with persisted UID and PID validation. 2. Authorize privileged power changes through caller records or Polkit. 3. Restrict SetAllowCaller to trusted registrars and D-Bus policies. 4. Add the security-loader and Polkit build/runtime dependencies. Log: Protect system Power1 mutations with explicit caller authorization. Influence: System power changes require authorization. fix(power): 加固系统电源操作 1. 通过持久化的 UID 和 PID 校验登记可信调用者。 2. 通过调用者记录或 Polkit 鉴权敏感电源变更。 3. 通过可信登记者和 D-Bus 策略限制 SetAllowCaller。 4. 添加 security-loader 与 Polkit 构建和运行依赖。 Log: 为系统 Power1 敏感操作增加明确的调用者鉴权。 PMS: TASK-394241 Influence: 系统电源变更需要通过鉴权。
f1fa158 to
fc7b8ef
Compare
deepin pr auto review★ 总体评分:55分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // 在 powermanager.h 中添加启动时间记录
struct AllowedCaller {
uint uid = 0;
uint pid = 0;
quint64 startTime = 0; // 新增:进程启动时间
};
// 修改 addAllowedCaller 获取并保存 startTime
bool SystemPowerManager::addAllowedCaller(const QString &uniqueName)
{
// ... 前置检查 ...
const QDBusReply<uint> uid = bus->serviceUid(uniqueName);
const QDBusReply<uint> pid = bus->servicePid(uniqueName);
if (!uid.isValid() || !pid.isValid())
return false;
// 获取进程启动时间
quint64 startTime = 0;
QFile statFile(QStringLiteral("/proc/%1/stat").arg(pid.value()));
if (statFile.open(QIODevice::ReadOnly)) {
const QString data = QString::fromLatin1(statFile.readAll());
// 解析 /proc/[pid]/stat 的第22个字段 (starttime)
int idx = data.lastIndexOf(')');
if (idx != -1) {
QStringList parts = data.mid(idx + 2).split(QChar::Space);
if (parts.size() >= 20) {
startTime = parts.at(19).toULongLong(); // 第22个字段,索引为19
}
}
}
// ... 权限验证逻辑 ...
m_allowedCallers.insert(uniqueName, {uid.value(), pid.value(), startTime});
saveAllowedCallers();
return true;
}
// 修改 isAllowedCaller 增加启动时间校验
bool SystemPowerManager::isAllowedCaller(const QString &uniqueName, bool &lookupFailed) const
{
// ... 前置检查 ...
const QDBusReply<uint> uid = bus->serviceUid(uniqueName);
const QDBusReply<uint> pid = bus->servicePid(uniqueName);
if (!uid.isValid() || !pid.isValid()) {
lookupFailed = true;
return false;
}
// 重新获取当前进程启动时间进行比对
quint64 currentStartTime = 0;
QFile statFile(QStringLiteral("/proc/%1/stat").arg(pid.value()));
if (statFile.open(QIODevice::ReadOnly)) {
const QString data = QString::fromLatin1(statFile.readAll());
int idx = data.lastIndexOf(')');
if (idx != -1) {
QStringList parts = data.mid(idx + 2).split(QChar::Space);
if (parts.size() >= 20) {
currentStartTime = parts.at(19).toULongLong();
}
}
}
return uid.value() == it->uid && pid.value() == it->pid && currentStartTime == it->startTime;
} |
|
@mhduiy: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
This is a stacked security follow-up for #153 and contains only the system Power1 authorization integration.
This PR is intentionally separate because the security-loader authorization design may change independently. After #153 merges, retarget this PR to master.
Log: Protect system Power1 mutations with explicit caller authorization.
PMS: TASK-394241
Influence: System power changes require authorization.
Summary by Sourcery
Secure Power1 system power actions with trusted caller validation and Polkit authorization.
New Features:
Enhancements:
Build: