Foxboron / sbctl

:computer: :lock: :key: Secure Boot key manager
MIT License
1.46k stars 84 forks source link

Unable to enroll-keys using TPM2 EventLog #384

Open pietrushnic opened 2 days ago

pietrushnic commented 2 days ago

When in Setup Mode on Odroid-H4+ with AMI BIOS, it seems I have two OptionROMs, which hashes I would like to enroll to db:

user@OST2:~$ sudo tpm2_eventlog eventlog | grep "BOOT_SERVICES_DRIVER" -A11 -B2

- EventNum: 10
  PCRIndex: 2
  EventType: EV_EFI_BOOT_SERVICES_DRIVER
  DigestCount: 1
  Digests:
  - AlgorithmId: sha256
    Digest: "b03547bedfc2e380c582564ea2a7a676e82264bf78029e5a2a1830ed9bebc334"
  EventSize: 84
  Event:
    ImageLocationInMemory: 0x6d9b4018
    ImageLengthInMemory: 154400
    ImageLinkTimeAddress: 0x0
    LengthOfDevicePath: 52
    DevicePath: '02010c00d041030a0000000001010600001c01010600000004081800000000003800000000000000ff1d0100000000007fff0400'
- EventNum: 11
  PCRIndex: 2
  EventType: EV_EFI_BOOT_SERVICES_DRIVER
  DigestCount: 1
  Digests:
  - AlgorithmId: sha256
    Digest: "b03547bedfc2e380c582564ea2a7a676e82264bf78029e5a2a1830ed9bebc334"
  EventSize: 84
  Event:
    ImageLocationInMemory: 0x6d98e018
    ImageLengthInMemory: 154400
    ImageLinkTimeAddress: 0x0
    LengthOfDevicePath: 52
    DevicePath: '02010c00d041030a0000000001010600031c01010600000004081800000000003800000000000000ff1d0100000000007fff0400'

Trying to enroll using:

sudo sbctl enroll-keys --tpm-eventlog

Unfortunately, it fails with the:

Enrolling keys to EFI variables...

With checksums from the TPM Eventlog...✗

couldn't sync keys: could not enroll db keys: signature data exists already

The error could be more precise. In the AMI Setup Mode, the BIOS DB is deleted, so the critical question is where the signature exists. I assume it doesn't mean "signature" but a hash of a given OptionROM. Or maybe the error is because there are two events in the event log about the same component.

Does sbctl mean dbDefault?

Can any tools help look into this issue and give you more context?

Foxboron commented 2 days ago

Ah, this error is supposed to be ignored and not bubbled up. So this can easily be fixed.

pietrushnic commented 2 days ago

@Foxboron, if I would like to contribute a fix for this bug, where should I start with setting up a development environment and testing? IIUC, should this be fixed in go-uefi or here?

It seems to bubble from here

Or maybe check for that error here and ignore/print the warning that such a signature/hash already exists.

Foxboron commented 2 days ago

I think it should be fixed in sbctl. I think it's usefull to have some semantic error if you try to include an existing hash.

Fixing it in tpm.go is a good idea. You can either use ExistsInList and just don't run Append on true. Or just check the error for ErrSigDataExists and ignore bubbling it up. Both are valid approaching IMO.

Thanks for contributing :) I'll try and get a new release out the door soon'ish as well.