Skip to content

Commit 905a56e

Browse files
zaolinChriMarMe
authored andcommitted
Fix malformed and spec violation of postibbdigest parsing
Signed-off-by: Philipp Deppenwiese <zaolin.daisuki@gmail.com>
1 parent 22aff9b commit 905a56e

7 files changed

Lines changed: 175 additions & 3 deletions

File tree

pkg/intel/metadata/bg/bootpolicy/manifest_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ import (
1212

1313
func TestReadWrite(t *testing.T) {
1414
unittest.BGManifestReadWrite(t, &Manifest{}, "testdata/bpm.bin")
15+
unittest.BGManifestReadWrite(t, &Manifest{}, "testdata/bpm2.bin")
1516
}

pkg/intel/metadata/bg/bootpolicy/se.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type SE struct {
3434
// PrettyString: DMA Protection 2 Limit Address
3535
Reserved3 [8]byte `json:"seDMAProtLimit1"`
3636

37-
PostIBBHash bg.HashStructure `json:"sePostIBBHash"`
37+
PostIBBHash bg.HashStructureFill `json:"sePostIBBHash"`
3838

3939
IBBEntryPoint uint32 `json:"seIBBEntry"`
4040

pkg/intel/metadata/bg/bootpolicy/se_manifestcodegen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
723 Bytes
Binary file not shown.

pkg/intel/metadata/bg/hash.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,42 @@ type HashStructure struct {
1111
HashAlg Algorithm `default:"0x10" json:"hsAlg"`
1212
HashBuffer []byte `json:"hsBuffer"`
1313
}
14+
15+
type HashStructureFill struct {
16+
HashAlg Algorithm `default:"0x0b" json:"hsAlg"`
17+
HashBuffer []byte `countValue:"hashSize()" prettyValue:"hashSizePrint()" json:"hsBuffer"`
18+
}
19+
20+
func (a Algorithm) size() uint16 {
21+
switch a {
22+
case AlgUnknown:
23+
return 0
24+
case AlgNull:
25+
return 0
26+
case AlgSHA1:
27+
return 20
28+
case AlgSHA256:
29+
return 32
30+
default:
31+
return 0
32+
}
33+
}
34+
35+
func (h HashStructureFill) hashSize() uint16 {
36+
const hashSizeFieldLen = 2
37+
if h.HashAlg.IsNull() {
38+
// Evil hack, more investigation needed
39+
return AlgSHA256.size() + hashSizeFieldLen
40+
} else {
41+
return h.HashAlg.size() + hashSizeFieldLen
42+
}
43+
}
44+
45+
func (h HashStructureFill) hashSizePrint() interface{} {
46+
if h.HashAlg.IsNull() {
47+
// Evil hack, more investigation needed
48+
return make([]byte, AlgSHA256.size())
49+
} else {
50+
return h.HashBuffer
51+
}
52+
}

pkg/intel/metadata/bg/hash_manifestcodegen.go

Lines changed: 132 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/intel/metadata/common/unittest/read_write.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func BGManifestReadWrite(t *testing.T, m bg.Manifest, testDataFilePath string) {
4040
testData, err := os.ReadFile(testDataFilePath)
4141
require.NoError(t, err)
4242

43-
nR, err := m.ReadFrom(bytes.NewReader(append(testData, []byte(`extra bytes`)...)))
43+
nR, err := m.ReadFrom(bytes.NewReader(testData))
4444
require.NoError(t, err)
4545
require.Equal(t, int64(len(testData)), nR)
4646
require.Equal(t, nR, int64(m.TotalSize()))

0 commit comments

Comments
 (0)