-
Notifications
You must be signed in to change notification settings - Fork 22
efi/preinstall: Fall back to checking the BootGuard status MSR in HAP mode #535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
chrisccoulson
merged 2 commits into
canonical:master
from
chrisccoulson:preinstall-support-btgstatus-msr-in-hap-mode
Apr 9, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| //go:build amd64 | ||
|
|
||
| // -*- Mode: Go; indent-tabs-mode: t -*- | ||
|
|
||
| /* | ||
| * Copyright (C) 2026 Canonical Ltd | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License version 3 as | ||
| * published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| package preinstall | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| ) | ||
|
|
||
| // checkHostSecurityIntelBootGuardMSR checks the BootGuard configuration using the BootGuard status | ||
| // MSR rather than the HFSTS registers. The MSR is mirrored by the startup ACM - it will contain | ||
| // all zeroes if this didn't execute, in which case, BootGuard is not active. | ||
| // | ||
| // This has some limitations compared with using the HFSTS registers. Eg, it's not possible to | ||
| // ensure that the system has properly transitioned out of manufacturing mode. | ||
| func checkHostSecurityIntelBootGuardMSR(status bootGuardStatus) error { | ||
| if status&bootGuardCapability == 0 { | ||
| return &NoHardwareRootOfTrustError{errors.New("BootGuard ACM is not active")} | ||
| } | ||
|
|
||
| // Check the BootGuard profile. | ||
| profile, err := status.btgProfile() | ||
| if err != nil { | ||
| return &NoHardwareRootOfTrustError{fmt.Errorf("cannot determine BootGuard profile: %w", err)} | ||
| } | ||
| switch profile { | ||
| case btgProfileFVE, btgProfileFVME: | ||
| // We require verified boot, so the 2 profiles with forced | ||
| // verification are ok. | ||
| return nil | ||
| default: | ||
| return &NoHardwareRootOfTrustError{errors.New("unsupported BootGuard profile")} | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| //go:build amd64 | ||
|
|
||
| // -*- Mode: Go; indent-tabs-mode: t -*- | ||
|
|
||
| /* | ||
| * Copyright (C) 2026 Canonical Ltd | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License version 3 as | ||
| * published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| package preinstall_test | ||
|
|
||
| import ( | ||
| . "gopkg.in/check.v1" | ||
|
|
||
| . "github.com/snapcore/secboot/efi/preinstall" | ||
| ) | ||
|
|
||
| type hostSecurityIntelBtgMSRSuite struct{} | ||
|
|
||
| var _ = Suite(&hostSecurityIntelBtgMSRSuite{}) | ||
|
|
||
| func (*hostSecurityIntelBtgMSRSuite) TestCheckHostSecurityIntelBootGuardMSRGoodFVMEProfile(c *C) { | ||
| c.Check(CheckHostSecurityIntelBootGuardMSR(0x000000030000007d), IsNil) | ||
| } | ||
|
|
||
| func (*hostSecurityIntelBtgMSRSuite) TestCheckHostSecurityIntelBootGuardMSRGoodFVEProfile(c *C) { | ||
| c.Check(CheckHostSecurityIntelBootGuardMSR(0x000000030000005d), IsNil) | ||
| } | ||
|
|
||
| func (*hostSecurityIntelBtgMSRSuite) TestCheckHostSecurityIntelBootGuardMSRErrInvalidProfile(c *C) { | ||
| err := CheckHostSecurityIntelBootGuardMSR(0x000000030000007c) | ||
| c.Check(err, ErrorMatches, `no hardware root-of-trust properly configured: cannot determine BootGuard profile: invalid profile`) | ||
| c.Check(err, FitsTypeOf, &NoHardwareRootOfTrustError{}) | ||
| } | ||
|
|
||
| func (*hostSecurityIntelBtgMSRSuite) TestCheckHostSecurityIntelBootGuardMSRErrUnsupportedNoFVMEProfile(c *C) { | ||
| err := CheckHostSecurityIntelBootGuardMSR(0x000000030000000c) | ||
| c.Check(err, ErrorMatches, `no hardware root-of-trust properly configured: unsupported BootGuard profile`) | ||
| c.Check(err, FitsTypeOf, &NoHardwareRootOfTrustError{}) | ||
| } | ||
|
|
||
| func (*hostSecurityIntelBtgMSRSuite) TestCheckHostSecurityIntelBootGuardMSRErrUnsupportedVMProfile(c *C) { | ||
| err := CheckHostSecurityIntelBootGuardMSR(0x000000030000006d) | ||
| c.Check(err, ErrorMatches, `no hardware root-of-trust properly configured: unsupported BootGuard profile`) | ||
| c.Check(err, FitsTypeOf, &NoHardwareRootOfTrustError{}) | ||
| } | ||
|
|
||
| func (*hostSecurityIntelBtgMSRSuite) TestCheckHostSecurityIntelBootGuardMSRErrNoBtg(c *C) { | ||
| err := CheckHostSecurityIntelBootGuardMSR(0) | ||
| c.Check(err, ErrorMatches, `no hardware root-of-trust properly configured: BootGuard ACM is not active`) | ||
| c.Check(err, FitsTypeOf, &NoHardwareRootOfTrustError{}) | ||
| } |
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| //go:build amd64 | ||
|
|
||
| // -*- Mode: Go; indent-tabs-mode: t -*- | ||
|
|
||
| /* | ||
| * Copyright (C) 2026 Canonical Ltd | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License version 3 as | ||
| * published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| package preinstall | ||
|
|
||
| import ( | ||
| "errors" | ||
|
|
||
| internal_efi "github.com/snapcore/secboot/internal/efi" | ||
| ) | ||
|
|
||
| const bootGuardStatusMsr = 0x13a | ||
|
|
||
| type bootGuardStatus uint64 | ||
|
|
||
| const ( | ||
| bootGuardNEM bootGuardStatus = 1 << 0 | ||
| bootGuardFACB bootGuardStatus = 1 << 4 | ||
| bootGuardMeasuredBoot bootGuardStatus = 1 << 5 | ||
| bootGuardVerifiedBoot bootGuardStatus = 1 << 6 | ||
| bootGuardCapability bootGuardStatus = 1 << 32 | ||
|
|
||
| bootGuardStatusTPMShift = 1 | ||
| bootGuardStatusTPMMask bootGuardStatus = (3 << bootGuardStatusTPMShift) | ||
| ) | ||
|
|
||
| type bootGuardTPMStatus uint64 | ||
|
|
||
| const ( | ||
| bootGuardTPMStatusNone bootGuardTPMStatus = 0 | ||
| bootGuardTPMStatus12 bootGuardTPMStatus = 1 | ||
| bootGuardTPMStatus2 bootGuardTPMStatus = 2 | ||
| bootGuardTPMStatusPTT bootGuardTPMStatus = 3 | ||
| ) | ||
|
|
||
| func (s bootGuardStatus) tpmStatus() bootGuardTPMStatus { | ||
| return bootGuardTPMStatus(s&bootGuardStatusTPMMask) >> bootGuardStatusTPMShift | ||
| } | ||
|
|
||
| func (s bootGuardStatus) btgProfile() (btgProfile, error) { | ||
| // We can't check the error enforcement policy here, either because it's | ||
| // not mirrored into the MSR, or it is but we don't know which 2 bits to | ||
| // use. We just interpret the other bits into one of the well known No_FVME, | ||
| // VM, FVE and FVME profiles. This is ok because there are no known profiles | ||
| // where these bits are reused with different error enforcement policies. | ||
| f := s&bootGuardFACB > 0 | ||
| v := s&bootGuardVerifiedBoot > 0 | ||
| m := s&bootGuardMeasuredBoot > 0 | ||
| p := s&bootGuardNEM > 0 | ||
|
|
||
| switch { | ||
| case !f && !v && !m && !p: | ||
| return btgProfileNoFVME, nil | ||
| case !f && v && m && p: | ||
| return btgProfileVM, nil | ||
| case f && v && !m && p: | ||
| return btgProfileFVE, nil | ||
| case f && v && m && p: | ||
| return btgProfileFVME, nil | ||
| default: | ||
| return 0, errors.New("invalid profile") | ||
| } | ||
| } | ||
|
|
||
| func readIntelBootGuardStatus(env internal_efi.HostEnvironmentAMD64) (bootGuardStatus, error) { | ||
| msrValue, err := env.ReadMSRs(bootGuardStatusMsr) | ||
| if err != nil { | ||
| return 0, err | ||
| } | ||
|
|
||
| // NOTE: msrValue[0] is fine because BootGuard status MSR has the same value across all CPUs | ||
| return bootGuardStatus(msrValue[0]), nil | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose this measured boot has nothing to do with TPM, or does it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It implies that the ACM is the root of trust for measurement rather than the EFI firmware measuring itself.