Skip to content

fix: force C locale for grub pbkdf2 hash parse - #3408

Draft
mhduiy wants to merge 1 commit into
masterfrom
fix/grub-edit-auth-locale
Draft

mhduiy wants to merge 1 commit into
masterfrom
fix/grub-edit-auth-locale

Conversation

@mhduiy

@mhduiy mhduiy commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

修复 grub 启动菜单编辑认证在非中文 locale 下失效

问题

在非中文 locale(如 sw64 的 2500 基础镜像缺少中文翻译)下,grub-mkpasswd-pbkdf2 输出英文格式,passwdEncrypt() 按固定字段下标 fields.at(3) 提取到 "your" 而非哈希,导致 grub 编辑认证被静默绕过——开关显示已开启但实际无密码保护。

改动

  • 为 grub-mkpasswd-pbkdf2 子进程经 QProcessEnvironment 强制注入 LANG=C/LANGUAGE=C,固定输出为英文格式,消除对系统 locale 的依赖。
  • 哈希提取改用正则 grub\.pbkdf2\.sha\d+\.\d+\.[0-9A-Fa-f]+\.[0-9A-Fa-f]+(captured(0)),替代固定下标 fields.at(3),无论哈希落在第 4 字段(zh_CN)还是第 7 字段(C/en_US)都能正确提取,且自带格式校验。
  • 新增 #include <QProcessEnvironment>。

关联

审核 / 编译状态

  • 代码审核:已通过(95 分 / 优秀)
  • amd64 编译验证:已通过

Summary by Sourcery

Ensure grub PBKDF2 password hashing works reliably across locales by making hash extraction locale-independent.

Bug Fixes:

  • Fix grub menu edit authentication being silently bypassed when grub-mkpasswd-pbkdf2 output is localized and the hash field is misparsed.

Enhancements:

  • Make grub-mkpasswd-pbkdf2 subprocess run under a forced C locale to produce predictable, non-localized output.
  • Extract the PBKDF2 hash from grub-mkpasswd-pbkdf2 output using a validated regular expression matching the expected hash format instead of relying on a fixed field position.

1. Force LANG=C/LANGUAGE=C on the grub-mkpasswd-pbkdf2 subprocess via
   QProcessEnvironment so its output stays English regardless of the
   system locale.
2. Extract the PBKDF2 hash with a regex
   (grub\.pbkdf2\.sha\d+\.\d+\.[0-9A-Fa-f]+\.[0-9A-Fa-f]+) instead of
   the fixed index fields.at(3), which returned "your" under
   non-Chinese locales and silently broke grub edit auth.
3. Add #include <QProcessEnvironment>.

Log: Fixed grub boot menu edit auth not prompting for password under non-Chinese locales

Influence:
1. Set grub edit auth password under C and zh_CN locales and verify
   the hash is written correctly.
2. Reboot and press 'e' in grub to confirm a password is required on
   affected arches (e.g. sw64).
3. Verify the existing zh_CN locale path still works after the change.

fix: 强制 C locale 解析 grub pbkdf2 哈希

1. 通过 QProcessEnvironment 为 grub-mkpasswd-pbkdf2 子进程强制注入
   LANG=C/LANGUAGE=C,固定输出为英文格式,消除对系统 locale 的依赖。
2. 哈希提取改用正则
   (grub\.pbkdf2\.sha\d+\.\d+\.[0-9A-Fa-f]+\.[0-9A-Fa-f]+) 替代固定下标
   fields.at(3),后者在非中文 locale 下取到 "your",导致 grub 编辑认证
   被静默绕过。
3. 新增 #include <QProcessEnvironment>。

Log: 修复非中文 locale 下 grub 启动菜单编辑认证不弹出密码的问题

Influence:
1. 在 C 和 zh_CN locale 下设置 grub 编辑认证密码,确认哈希正确写入。
2. 重启在 grub 按 e 键确认受影响架构(如 sw64)需要密码。
3. 确认改动后原有 zh_CN locale 路径仍能正常工作。

PMS: BUG-371591
@deepin-ci-robot

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@deepin-ci-robot

Copy link
Copy Markdown

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

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 11, 2026

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

Reviewer's Guide

Forces grub-mkpasswd-pbkdf2 to run under the C locale and replaces positional-field parsing with a regex-based parser to robustly extract PBKDF2 hashes from localized output, adding the necessary Qt includes and environment setup.

Sequence diagram for updated passwdEncrypt PBKDF2 hash extraction

sequenceDiagram
    participant CommonInfoWork
    participant QProcess_pbkdf2 as QProcess_pbkdf2
    participant grub_mkpasswd_pbkdf2

    CommonInfoWork->>QProcess_pbkdf2: setProgram("grub-mkpasswd-pbkdf2")
    CommonInfoWork->>QProcess_pbkdf2: setProcessChannelMode(SeparateChannels)
    CommonInfoWork->>QProcess_pbkdf2: setProcessEnvironment(env LANG=C LANGUAGE=C)
    CommonInfoWork->>QProcess_pbkdf2: start()
    QProcess_pbkdf2->>grub_mkpasswd_pbkdf2: execute under C locale
    QProcess_pbkdf2-->>CommonInfoWork: waitForFinished()
    CommonInfoWork->>QProcess_pbkdf2: readAllStandardOutput()
    QProcess_pbkdf2-->>CommonInfoWork: PBKDF2 output

    CommonInfoWork->>CommonInfoWork: pbkdf2HashRe.match(line)
    alt match.hasMatch()
        CommonInfoWork->>CommonInfoWork: captured(0) // grub.pbkdf2.shaX.iter.salt.hash
        CommonInfoWork-->>CommonInfoWork: return hash
    else no match
        CommonInfoWork-->>CommonInfoWork: continue search or return empty
    end
Loading

File-Level Changes

Change Details Files
Force grub-mkpasswd-pbkdf2 child process to use the C locale to stabilize output format.
  • Create a QProcessEnvironment from the system environment before starting grub-mkpasswd-pbkdf2.
  • Inject LANG=C and LANGUAGE=C into the environment.
  • Assign the customized environment to the QProcess via setProcessEnvironment().
src/plugin-commoninfo/operation/commoninfowork.cpp
Harden PBKDF2 hash extraction by switching from positional splitting to regex matching of the hash pattern.
  • Introduce a static QRegularExpression that matches grub.pbkdf2.sha... format.
  • Read the process stdout, iterate PBKDF2 lines, and use the regex to capture the hash instead of using the 4th whitespace-delimited field.
  • Remove dependency on locale-specific field positions to prevent incorrect values (like 'your') from being used as the hash.
src/plugin-commoninfo/operation/commoninfowork.cpp
Add missing Qt include required for environment handling.
  • Include at the top of the compilation unit to support the new environment manipulation code.
src/plugin-commoninfo/operation/commoninfowork.cpp

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

@deepin-bot

deepin-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.104
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3409

@deepin-bot

deepin-bot Bot commented Aug 18, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.105
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3419

@deepin-bot

deepin-bot Bot commented Sep 10, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.106
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3497

@deepin-bot

deepin-bot Bot commented Sep 11, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.107
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3503

@deepin-bot

deepin-bot Bot commented Sep 23, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.109
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3545

This branch has not been deployed

No deployments
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