Skip to content

Commit f1f8117

Browse files
Nick Bofferdingdcrowell77
authored andcommitted
Enable HBB measurement based on secure mode enablement
Change-Id: Ia731f7ee2fff280d078da9878322f69beb3aa7cc RTC: 167581 Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/36221 Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com> Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com> Tested-by: Jenkins OP Build CI <op-jenkins+hostboot@us.ibm.com> Reviewed-by: Michael Baiocchi <mbaiocch@us.ibm.com> Reviewed-by: Stephen M. Cprek <smcprek@us.ibm.com> Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com>
1 parent ac0ff7b commit f1f8117

File tree

4 files changed

+74
-77
lines changed

4 files changed

+74
-77
lines changed

src/include/usr/secureboot/header.H

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace SECUREBOOT
5555
*/
5656
~Header()
5757
{
58-
free(iv_data);
58+
free(const_cast<void*>(iv_data));
5959
iv_data=NULL;
6060
}
6161

@@ -64,8 +64,9 @@ namespace SECUREBOOT
6464

6565
/**
6666
* @brief Extracts base image (HBB) header (ECC removed) from
67-
* HBB secure load address (HRMOR - 4k) to support extending
68-
* HBB measurements to TPM in secure mode.
67+
* security area preserved across the bootloader to HBB
68+
* handoff to support extending HBB measurements to TPM in
69+
* secure mode.
6970
*
7071
* @warning Asserts if header is already cached (code bug)
7172
*/
@@ -82,11 +83,7 @@ namespace SECUREBOOT
8283
* @param[in] i_pHeader Pointer to non-secure 4k HBB header
8384
* extracted from PNOR.
8485
*
85-
* @warning Asserts if input pointer is NULL (code bug)
86-
* @warning Asserts if header already cached (code bug)
87-
* @warning Memory violation if buffer data is less than 4k in size
88-
* (code bug)
89-
* @warning Ignores buffer data beyond 4k in size
86+
* @warning Carries all the same warnings as _set
9087
*/
9188
void setNonSecurely(
9289
const void* i_pHeader);
@@ -95,16 +92,20 @@ namespace SECUREBOOT
9592
* @brief Return pointer to base image (HBB) header.
9693
*
9794
* @par Detailed Description:
98-
* When SBE first loads Hostboot, if system is in secure mode,
99-
* it copies the HBB code to the HRMOR address (aka the secure
100-
* load address) and puts the HBB header 4k in front of it. In
101-
* non-secure mode, SBE only loads the HBB code to the HRMOR and
102-
* discards the header, leaving no trace of it in memory. When
103-
* HBB gets control, if in secure mode, it copies its own header
104-
* from HRMOR-4k and caches it in this object. Otherwise, if
105-
* not in secure mode, it pulls the header from PNOR and writes
106-
* it into this object. This API then returns the addresses of
107-
* the cached header.
95+
* During boot, SBE copies the boot loader (HBBL) into the cache
96+
* and hands off control to it. The boot loader then loads the
97+
* base image (HBB), including its secure header. After
98+
* verifying HBB, the boot loader copies hostboot to the trusted
99+
* memory location and passes control to HBB, which locates and
100+
* preserves the secure header (among other things) before
101+
* initializing the other non-preserved areas of the cache. In
102+
* secure mode, HBB then initializes this header object with the
103+
* preserved secure header.
104+
*
105+
* In non-secure mode, Hostboot pulls the header from PNOR and
106+
* and writes it into this object.
107+
*
108+
* This API then returns the addresses of the cached header.
108109
*
109110
* @param[out] o_pHeader Pointer to HBB header
110111
*
@@ -116,17 +117,22 @@ namespace SECUREBOOT
116117
private:
117118

118119
/**
119-
* @brief Returns base (HBB) image secure load address (the address
120-
* where SBE -always- loads hostboot regardless of security
121-
* state)
120+
* @brief Populate the base image (HBB) header (ECC removed)
121+
* to support extending HBB measurements to TPM
122122
*
123-
* @param[out] o_pCode Base (HBB) image secure load address
123+
* @param[in] i_pHeader Pointer to 4k HBB header
124+
*
125+
* @warning Asserts if input pointer is NULL (code bug)
126+
* @warning Asserts if header already cached (code bug)
127+
* @warning Memory violation if buffer data is less than 4k in size
128+
* (code bug)
129+
* @warning Ignores buffer data beyond 4k in size
124130
*/
125-
void _calcSecureLoadAddr(
126-
const void*& o_pCode) const;
131+
void _set(
132+
const void* i_pHeader);
127133

128134
// Pointer to copy of the base image's (HBB's) secureboot header
129-
void* iv_data;
135+
const void* iv_data;
130136

131137
// Don't allow copies / assignments
132138
Header(const Header& that);

src/usr/pnor/pnor_common.C

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -304,21 +304,26 @@ errlHndl_t PNOR::parseTOC( uint8_t* i_tocBuffer,SectionData_t * o_TOC)
304304
if ( o_TOC[l_secId].version == FFS_VERS_SHA512
305305
&& !isSecure)
306306
{
307-
// For non-secure sections with a SHA512 header, the
308-
// flash address has incremented past the header, so
309-
// back up by the header size (accounting for ECC) in order
310-
// to extend the header
311-
auto addr = o_TOC[l_secId].flashAddr;
312-
size_t headerSize =
313-
(o_TOC[l_secId].integrity == FFS_INTEG_ECC_PROTECT) ?
314-
PAGESIZE_PLUS_ECC : PAGESIZE;
315-
addr -= headerSize;
316-
317-
l_errhdl = PNOR::extendHash(addr, headerSize,
318-
cv_EYECATCHER[l_secId]);
319-
if (l_errhdl)
307+
// Never extend the base image through this path, it will be
308+
// handled elsewhere
309+
if(l_secId != PNOR::HB_BASE_CODE)
320310
{
321-
break;
311+
// For non-secure sections with a SHA512 header, the
312+
// flash address has incremented past the header, so
313+
// back up by the header size (accounting for ECC) in order
314+
// to extend the header
315+
auto addr = o_TOC[l_secId].flashAddr;
316+
size_t headerSize =
317+
(o_TOC[l_secId].integrity == FFS_INTEG_ECC_PROTECT) ?
318+
PAGESIZE_PLUS_ECC : PAGESIZE;
319+
addr -= headerSize;
320+
321+
l_errhdl = PNOR::extendHash(addr, headerSize,
322+
cv_EYECATCHER[l_secId]);
323+
if (l_errhdl)
324+
{
325+
break;
326+
}
322327
}
323328
}
324329
}

src/usr/pnor/pnorrp.C

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,7 @@ void PnorRP::initDaemon()
337337
// runtime code.
338338
#ifndef __HOSTBOOT_RUNTIME
339339
#ifdef CONFIG_SECUREBOOT
340-
//TODO: RTC 167581
341-
// When RTC 166848 is available, add restrictions back in when
342-
// base image header copy availability is detected
343-
// if(!SECUREBOOT::enabled())
340+
if(!SECUREBOOT::enabled())
344341
{
345342
// If compliant bootloader was present, it saved the HBB header
346343
// to a known location accessible to HBB. Until that bootloader

src/usr/secureboot/base/header.C

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <sys/mmio.h>
2828
#include <kernel/console.H>
2929
#include <errno.h>
30+
#include <kernel/bltohbdatamgr.H>
3031

3132
namespace SECUREBOOT
3233
{
@@ -39,27 +40,41 @@ namespace SECUREBOOT
3940
// header
4041
void Header::loadSecurely()
4142
{
42-
//@TODO RTC 167581
43-
// When RTC 166848 is available, pull in real header
43+
const void* const pSecureHeader = g_BlToHbDataManager.getHbbHeader();
4444

45-
return;
45+
// Fatal code bug if called with nullptr pointer
46+
assert(pSecureHeader != nullptr,
47+
"BUG! In Header::loadSecurely(), expected valid address for base "
48+
"image header in secure mode, but got nullptr.");
49+
_set(pSecureHeader);
4650
}
4751

4852
// @TODO RTC 168021 Converge on a single method of reading the secure
4953
// header
5054
void Header::setNonSecurely(
5155
const void* const i_pHeader)
56+
{
57+
// Fatal code bug if called with nullptr pointer
58+
assert(i_pHeader != nullptr,"BUG! In Header::setNonSecurely(), "
59+
"caller passed a nullptr header address.");
60+
_set(i_pHeader);
61+
}
62+
63+
void Header::_set(
64+
const void* const i_pHeader)
5265
{
5366
// Fatal code bug if already loaded
54-
assert(iv_data == nullptr,"BUG! In setNonSecurely(), "
67+
assert(iv_data == nullptr,"BUG! In Header::_set(), "
5568
"a cached header is already present.");
5669

5770
// Fatal code bug if called with nullptr pointer
58-
assert(i_pHeader != nullptr,"BUG! In setNonSecurely(), "
59-
"caller passed a nullptr header.");
71+
assert(i_pHeader != nullptr,"BUG! In Header::_set(), "
72+
"caller passed a nullptr header address.");
6073

61-
iv_data = calloc(1,PAGESIZE);
62-
memcpy(iv_data,i_pHeader,PAGE_SIZE);
74+
void* pData = malloc(PAGESIZE);
75+
memcpy(pData,i_pHeader,PAGE_SIZE);
76+
iv_data = pData;
77+
pData = nullptr;
6378
}
6479

6580
void Header::getHeader(
@@ -70,30 +85,4 @@ namespace SECUREBOOT
7085
"header is not present.");
7186
o_pHeader = iv_data;
7287
}
73-
74-
void Header::_calcSecureLoadAddr(
75-
const void*& o_pCode) const
76-
{
77-
//@TODO RTC 167581
78-
// When RTC 166848 is available, pull in real header
79-
80-
// Determine the secure address where the HBB image was loaded by SBE.
81-
// Regardless of whether security is enabled or not, HBB always ends up
82-
// at the secure load address (which corresponds to the HRMOR).
83-
//
84-
// Zero is purposefully not mapped into the VMM tables, so we
85-
// can't use that for the virtual-to-real translation. Since
86-
// this object is in the base (HBB) image, PA = HRMOR | EA, so we can
87-
// use PA - EA to find the HRMOR.
88-
const void* hrmor = reinterpret_cast<const void*>(
89-
mm_virt_to_phys(
90-
const_cast<SECUREBOOT::Header*>(this)) -
91-
reinterpret_cast<uint64_t>(this));
92-
93-
// HRMOR lookup should never fail
94-
assert( reinterpret_cast<uint64_t>(hrmor)
95-
!= static_cast<uint64_t>(-EFAULT));
96-
97-
o_pCode = hrmor;
98-
}
9988
}

0 commit comments

Comments
 (0)