Skip to content

fix: allow active users to toggle airplane mode without polkit prompt - #1213

Closed
fly602 wants to merge 9 commits into
linuxdeepin:masterfrom
fly602:master
Closed

fix: allow active users to toggle airplane mode without polkit prompt#1213
fly602 wants to merge 9 commits into
linuxdeepin:masterfrom
fly602:master

Conversation

@fly602

@fly602 fly602 commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Previously, toggling airplane mode required admin authentication via polkit even for active users, causing unnecessary dialog prompts during normal operations. This change sets allow_active to yes for the airplane mode action, while keeping allow_inactive as no to restrict non-active users. This improves usability by avoiding repeated authentication prompts for regular users.

Log: Active users can now toggle airplane mode without polkit authentication dialogs

Influence:

  1. Verify that active users can toggle airplane mode without any authentication dialog.
  2. Confirm that non-active (inactive) users still cannot toggle airplane mode.
  3. Ensure that the polkit action is still enforced for non-active sessions.
  4. Test that the change does not affect other polkit actions.

fix: 允许活跃用户切换飞行模式时无需 polkit 弹窗

之前即使用户处于活跃状态,切换飞行模式也需要通过 polkit 进行管理员
认证,导致正常操作时弹出不必要的授权对话框。此修改将飞行模式操作的
allow_active 设置为 yes,同时保持 allow_inactiveno 以限制非 活跃用户。这通过避免常规用户反复认证,提升了易用性。

Log: 活跃用户现在可以无需 polkit 认证弹窗切换飞行模式

Influence:

  1. 验证活跃用户能否无任何认证弹窗地切换飞行模式。
  2. 确认非活跃用户仍然无法切换飞行模式。
  3. 确保 polkit 操作对非活跃会话仍然有效。
  4. 测试此修改不影响其他 polkit 操作。

PMS: TASK-393313

Summary by Sourcery

Use direct polkit authorization for airplane mode and streamline daemon security and power-control infrastructure.

New Features:

  • Authorize airplane-mode operations directly through polkit while allowing policy to determine whether active users need authentication.
  • Expose short-idle power control through the system power interface.

Bug Fixes:

  • Allow active users to toggle airplane mode without unnecessary polkit authentication prompts while retaining authorization for inactive sessions.

Enhancements:

  • Remove the legacy security-loader and caller-registration authorization mechanism from daemon services.
  • Simplify daemon state access and power/idle control interfaces.

Build:

  • Update installation paths and packaging configuration after removing security-loader components.
  • Remove obsolete hardware-control policy and loader wrapper packaging artifacts.

Tests:

  • Remove obsolete short-idle concurrency and authorization-related tests.

Chores:

  • Remove security-loader dependencies, interfaces, and related D-Bus policy permissions across daemon components.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: fly602

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

@sourcery-ai

sourcery-ai Bot commented Aug 18, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates the polkit policy for the airplane mode action so that active sessions can toggle airplane mode without admin authentication, while inactive sessions remain restricted.

File-Level Changes

Change Details Files
Relaxed polkit authentication requirements for airplane mode for active users while keeping restrictions for inactive users.
  • Set the airplane mode polkit action allow_active attribute to yes so active users can toggle airplane mode without a prompt.
  • Kept allow_inactive as no to prevent non-active sessions from toggling airplane mode.
  • Ensured the change is scoped only to the airplane mode polkit action so other actions remain unaffected.
misc/polkit-action/org.deepin.dde.airplane.policy

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@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.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@fly602

fly602 commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

/test github-pr-review-ci

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:40分

■ 【总体评价】

代码实现了移除securityloader模块的架构重构,但存在严重的权限校验遗漏和并发安全问题。
逻辑正确但因多处核心接口鉴权完全丢失导致严重安全漏洞扣60分。

■ 【详细分析】

  • 1.语法逻辑 存在错误 ✕
    具体分析内容,指出代码位置、函数名及问题原因:bin/dde-system-daemon/power.go 中的 setState 函数移除了原有的 file != d.idleStatePath 分支判断,导致在设置屏幕状态时错误地与 ShortIdleState 进行比较并可能提前返回错误。同时,system/power1/manager.go 移除了 ShortIdleStateMu 读写锁,但 setShortIdleState 和 doSetMode 可能被并发调用(如定时器回调和D-Bus调用),存在严重的数据竞争。
    潜在问题:屏幕状态设置逻辑异常;ShortIdleState 并发读写数据竞争。
    建议:恢复 setState 中的文件路径分支判断;恢复 ShortIdleState 和 shortIdleEnable 的互斥锁保护。
  • 2.代码质量 较差 ✕
    具体分析内容:bin/dde-system-daemon/power.go 将原版使用的 os.ReadFile/WriteFile 降级为已废弃的 ioutil.ReadFile/WriteFile。system/airplane_mode1/manager.go 中重新实现了 checkAuthorization 函数,而非提取为公共工具复用,违反DRY原则。同时删除了核心逻辑变更对应的单元测试文件 power_test.go。
    潜在问题:引入已废弃API;鉴权代码重复;缺失测试覆盖。
    建议:将 ioutil 替换为 os 包对应函数;将 checkAuthorization 抽离至公共模块;补充并发和鉴权相关的单元测试。
  • 3.代码性能 存在性能问题 ✕
    具体分析内容:system/airplane_mode1/manager.go 中的 checkAuthorization 函数在每次鉴权时都调用 dbus.SystemBus() 获取新的系统总线连接,而不是复用已有的 mgr.service.Conn()。
    潜在问题:频繁创建和销毁D-Bus连接增加不必要的系统调用和开销。
    建议:修改 checkAuthorization 接收 *dbus.Conn 参数,传入 mgr.service.Conn()。
  • 4.代码安全 存在 4 个安全漏洞(高危2个,中危2个) ✕
    漏洞对比统计:新增漏洞 4 个,减少漏洞 0 个,持平 0 个
    总体风险描述,指出漏洞位置和攻击面:本次重构本意是回退到原生Polkit,但实际操作中直接删除了鉴权代码而未补充替代方案,导致多个涉及系统核心状态(电源、输入设备、飞行模式)的D-Bus接口完全裸奔,任意本地用户均可调用。

  • 安全漏洞1([无] ):[权限绕过] 在 [bin/dde-system-daemon/power.go 的 SetIdleState 和 SetScreenState 函数] 中,[移除了 sender 鉴权参数和 securityloader.AuthorizeWithPolkit 调用,且未补充标准 Polkit 校验。任何本地用户可通过 D-Bus 直接调用修改系统内核空闲和屏幕状态文件,导致拒绝服务或系统挂起] ——非常重要

  • 安全漏洞2([无] ):[权限绕过] 在 [system/inputdevices1/touchpad.go 的 SetTouchpadEnable 函数] 中,[移除了 securityloader.AuthorizeWithPolkit 调用且未做任何鉴权替换。普通用户可随意禁用触摸板,影响其他用户正常使用,构成本地拒绝服务] ——非常重要

  • 安全漏洞3([无] ):[权限绕过] 在 [system/power1/manager_ifc.go 的 SetTlpMode 函数] 中,[移除了原有的 Polkit 鉴权逻辑。任意用户可调用此接口修改系统 TLP 模式(如强制设置为性能模式或节能模式),可导致笔记本过热或性能受限,属于本地权限提升/配置篡改] ——非常重要

  • 安全漏洞4([无] ):[权限配置错误] 在 [misc/polkit-action/org.deepin.dde.airplane.policy 文件] 中,[将 allow_active 从 auth_admin_keep 修改为 yes。这导致任何活跃的本地用户无需输入密码即可直接开启飞行模式,切断系统所有无线网络连接,构成严重的本地拒绝服务风险] ——非常重要

  • 建议:针对所有被移除鉴权的D-Bus方法,必须使用 go-dbus-factory 的 polkit 包补充标准的 CheckAuthorization 调用;恢复 airplane.policy 中的 auth_admin_keep 配置;将新增的 SetShortIdleState 加入严格的 Polkit 鉴权。

■ 【改进建议代码示例】

// bin/dde-system-daemon/power.go
// 修复:恢复 sender 参数并补充标准 Polkit 鉴权逻辑
func (d *Daemon) SetIdleState(sender dbus.Sender, state bool) *dbus.Error {
	err := d.authorize(sender, "org.deepin.dde.daemon.set-idle-state")
	if err != nil {
		logger.Warningf("SetIdleState authorization failed: %v", err)
		return dbusutil.ToError(err)
	}
	logger.Infof("SetIdleState %s try set state: %v", d.idleStatePath, state)
	return dbusutil.ToError(d.setState(d.idleStatePath, state))
}

func (d *Daemon) SetScreenState(sender dbus.Sender, state bool) *dbus.Error {
	err := d.authorize(sender, "org.deepin.dde.daemon.set-screen-state")
	if err != nil {
		logger.Warningf("SetScreenState authorization failed: %v", err)
		return dbusutil.ToError(err)
	}
	logger.Infof("SetScreenState %s try set state: %v", d.idleScreenStatePath, state)
	return dbusutil.ToError(d.setState(d.idleScreenStatePath, state))
}

// 新增标准 Polkit 鉴权辅助函数,替代被移除的 securityloader
func (d *Daemon) authorize(sender dbus.Sender, actionID string) error {
	polkit "github.com/linuxdeepin/go-dbus-factory/system/org.freedesktop.policykit1"
	authority := polkit.NewAuthority(d.service.Conn())
	subject := polkit.MakeSubject(polkit.SubjectKindSystemBusName)
	subject.SetDetail("name", string(sender))
	result, err := authority.CheckAuthorization(0, subject, actionID,
		nil, polkit.CheckAuthorizationFlagsAllowUserInteraction, "")
	if err != nil {
		return err
	}
	if !result.IsAuthorized {
		return errors.New("access denied")
	}
	return nil
}

// system/airplane_mode1/manager.go
// 修复:复用已有的 D-Bus 连接,避免频繁创建新连接带来的性能损耗与安全风险
func checkAuthorization(service *dbusutil.Service, actionId string, sysBusName string) error {
	polkit "github.com/linuxdeepin/go-dbus-factory/system/org.freedesktop.policykit1"
	authority := polkit.NewAuthority(service.Conn())
	subject := polkit.MakeSubject(polkit.SubjectKindSystemBusName)
	subject.SetDetail("name", sysBusName)

	ret, err := authority.CheckAuthorization(0, subject, actionId,
		nil, polkit.CheckAuthorizationFlagsAllowUserInteraction, "")
	if err != nil {
		return err
	}
	if !ret.IsAuthorized {
		return errors.New("not authorized")
	}
	return nil
}

func (mgr *Manager) Enable(sender dbus.Sender, enableAirplaneMode bool) *dbus.Error {
	err := checkAuthorization(mgr.service, actionId, string(sender))
	if err != nil {
		logger.Warningf("checkAuthorization failed, err: %v, actionId=%v", err, actionId)
		return dbusutil.ToError(err)
	}
	err = mgr.block(rfkillTypeAll, enableAirplaneMode)
	if err != nil {
		logger.Warningf("block all radio failed, err: %v", err)
		return dbusutil.ToError(err)
	}
	return nil
}

@deepin-ci-robot

Copy link
Copy Markdown

@fly602: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
github-pr-review-ci cbcdf1e link true /test github-pr-review-ci

Full PR test history. Your PR dashboard.

Details

Instructions 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.

@fly602 fly602 closed this Aug 19, 2026
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.

2 participants