fix: grub2 hash validation and mkconfig fallback - #1200
Draft
mhduiy wants to merge 1 commit into
Draft
Conversation
1. Add package-level pbkdf2HashReg and validate the PBKDF2 hash format in EditAuth.Enable() before writing the crypto file, rejecting malformed hashes that grub would silently ignore. 2. Fix runUpdateGrubWithUnit(): when update-grub is not in PATH, run 'grub-mkconfig -o <grub.cfg>' instead of the broken fallback that appended update-grub and never executed grub-mkconfig. 3. Add regexp import. Log: Fixed grub boot menu edit auth failing when update-grub is missing; added hash validation to prevent silent auth bypass Influence: 1. Enable grub edit auth with a valid pbkdf2 hash and confirm it is written and grub prompts for password. 2. Enable with an invalid hash and confirm the DBus call returns an error instead of writing a broken config. 3. On a system with only grub-mkconfig (no update-grub), confirm grub.cfg is regenerated. fix: grub2 哈希校验与 mkconfig 回退修正 1. 新增包级 pbkdf2HashReg 正则,在 EditAuth.Enable() 写入前校验 PBKDF2 哈希格式,拒绝会被 grub 静默忽略的非法哈希。 2. 修正 runUpdateGrubWithUnit():update-grub 不在 PATH 时改用 'grub-mkconfig -o <grub.cfg>',原 fallback 错误地 append 了 update-grub 导致 grub-mkconfig 从未执行。 3. 新增 regexp import。 Log: 修复 update-grub 缺失时 grub 启动菜单编辑认证失效,并增加哈希校验防止静默绕过 Influence: 1. 用合法 pbkdf2 哈希开启 grub 编辑认证,确认写入并在 grub 提示密码。 2. 用非法哈希开启,确认 DBus 返回错误而非写入错误配置。 3. 在仅有 grub-mkconfig(无 update-grub)的系统上确认 grub.cfg 能重新生成。 PMS: BUG-371591
|
Skipping CI for Draft Pull Request. |
|
[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 guide (collapsed on small PRs)Reviewer's GuideThis PR adds PBKDF2 hash format validation to the grub edit authentication path and fixes the fallback behavior when update-grub is not available by correctly invoking grub-mkconfig. Sequence diagram for PBKDF2 hash validation in EditAuth.EnablesequenceDiagram
participant Caller
participant EditAuth
participant pbkdf2HashReg
participant GrubConfig
Caller->>EditAuth: Enable(sender, username, password)
EditAuth->>EditAuth: isValidUsernameAndPassword(username, password)
alt [username or password invalid]
EditAuth-->>Caller: dbusutil.ToError("username or password invalid")
else [username and password valid]
EditAuth->>pbkdf2HashReg: MatchString(password)
alt [invalid pbkdf2 hash format]
EditAuth-->>Caller: dbusutil.ToError("invalid pbkdf2 hash format")
else [valid pbkdf2 hash format]
EditAuth->>GrubConfig: setGrubEditShellAuth(username, password)
GrubConfig-->>EditAuth: error or nil
EditAuth-->>Caller: dbusutil.ToError(err) or nil
end
end
Sequence diagram for update-grub to grub-mkconfig fallbacksequenceDiagram
participant Manager as modifyManager
participant Exec as exec
participant Shell as shell
Manager->>Manager: runUpdateGrubWithUnit()
Manager->>Exec: LookPath(updateGrubCmd)
alt [update-grub found]
Exec-->>Manager: path
Manager->>Shell: command = [path]
else [update-grub not found]
Exec-->>Manager: error
Manager->>Shell: command = [grubMkconfigCmd, "-o", grubScriptFile]
end
Manager->>Shell: run(command)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修复 grub 编辑认证哈希校验与 update-grub 回退缺陷
改动
grub2/edit_auth_ifc.go:新增包级pbkdf2HashReg正则,Enable()写入前校验 PBKDF2 哈希格式,非法返回invalid pbkdf2 hash format错误,防止错误数据静默写入/etc/grub.d/42_uos_menu_crypto后被 grub 忽略(症状同原 bug:静默不校验)。新增regexpimport。grub2/modify_manger.go:runUpdateGrubWithUnit()中update-grub不在 PATH 时的 fallback 改为grub-mkconfig -o <grub.cfg>(原错误地仍 appendupdate-grub,导致grub-mkconfig从未执行),并删除死赋值path = grubMkconfigCmd。关联
审核 / 编译状态
Summary by Sourcery
Validate grub edit authentication hashes and correct the grub configuration fallback command.
Bug Fixes: