fix: grub2 hash validation and mkconfig fallback - #1200
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
|
|
TAG Bot New tag: 6.1.102 |
|
TAG Bot New tag: 6.1.103 |
|
TAG Bot New tag: 6.1.104 |
修复 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: