m/n/c/update: fix matching boot entries
The matching code accidentally worked as long as there was only one boot
entry for each loader path (boot-a.efi/boot-b.efi) as it type-asserted
a pointer which caused ok to always be false and thus all entries passed
through the UUID check.
This fixes the type assertion and following logic.
Change-Id: I83fdd2204028633dc274055f7d1ecb458747174e
Reviewed-on: https://review.monogon.dev/c/monogon/+/2031
Tested-by: Jenkins CI
Reviewed-by: Serge Bazanski <serge@monogon.tech>
diff --git a/metropolis/node/core/update/update.go b/metropolis/node/core/update/update.go
index 84a5db9..a357fa5 100644
--- a/metropolis/node/core/update/update.go
+++ b/metropolis/node/core/update/update.go
@@ -143,29 +143,9 @@
}
func (s *Service) getOrMakeBootEntry(existing map[int]*efivarfs.LoadOption, slot Slot) (int, error) {
- for idx, e := range existing {
- if len(e.FilePath) != 2 {
- // Not our entry
- continue
- }
- switch p := e.FilePath[0].(type) {
- case *efivarfs.HardDrivePath:
- gptMatch, ok := p.PartitionMatch.(*efivarfs.PartitionGPT)
- if ok && gptMatch.PartitionUUID != s.ESPPart.ID {
- // Not related to our ESP
- continue
- }
- default:
- continue
- }
- switch p := e.FilePath[1].(type) {
- case efivarfs.FilePath:
- if string(p) == slot.EFIBootPath() {
- return idx, nil
- }
- default:
- continue
- }
+ idx, ok := s.findBootEntry(existing, slot)
+ if ok {
+ return idx, nil
}
newEntry := &efivarfs.LoadOption{
Description: fmt.Sprintf("Metropolis Slot %s", slot),
@@ -189,6 +169,34 @@
return newIdx, err
}
+func (s *Service) findBootEntry(existing map[int]*efivarfs.LoadOption, slot Slot) (int, bool) {
+ for idx, e := range existing {
+ if len(e.FilePath) != 2 {
+ // Not our entry
+ continue
+ }
+ switch p := e.FilePath[0].(type) {
+ case *efivarfs.HardDrivePath:
+ gptMatch, ok := p.PartitionMatch.(efivarfs.PartitionGPT)
+ if !(ok && gptMatch.PartitionUUID == s.ESPPart.ID) {
+ // Not related to our ESP
+ continue
+ }
+ default:
+ continue
+ }
+ switch p := e.FilePath[1].(type) {
+ case efivarfs.FilePath:
+ if string(p) == slot.EFIBootPath() {
+ return idx, true
+ }
+ default:
+ continue
+ }
+ }
+ return 0, false
+}
+
// MarkBootSuccessful must be called after each boot if some implementation-
// defined criteria for a successful boot are met. If an update has been
// installed and booted and this function is called, the updated version is