Skip to content

Commit efd80db

Browse files
Stephen Cprekdcrowell77
authored andcommitted
Verify HBI pages via its hash page table
Change-Id: I43aeff07912d1744e3f5706a96fbe24ecfe18896 RTC: 125298 ForwardPort: yes Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/24097 Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com> Tested-by: Jenkins OP Build CI <op-jenkins+hostboot@us.ibm.com> Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com> Reviewed-by: Nicholas E. Bofferding <bofferdn@us.ibm.com> Tested-by: Jenkins OP HW <op-hw-jenkins+hostboot@us.ibm.com> Reviewed-by: Michael Baiocchi <mbaiocch@us.ibm.com> Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com>
1 parent ebe2d9b commit efd80db

File tree

18 files changed

+480
-45
lines changed

18 files changed

+480
-45
lines changed

img/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ errlparser
1818
*.prf
1919
test_signed_container
2020
secureboot_signed_container
21+
secureboot_hash_page_table_container

src/build/buildpnor/genPnorImages.pl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ sub manipulateImages
172172
PROTECTED_PAYLOAD => "$bin_dir/$parallelPrefix.protected_payload.bin"
173173
);
174174

175-
# @TODO RTC:125298 add HBI to this list, not supported until vfsrp code
176-
# is modified.
177-
my %hashPageTablePartitions = ();
175+
# Partitions that have a hash page table at the beginning of the section
176+
# for secureboot purposes.
177+
my %hashPageTablePartitions = (HBI => 1);
178178

179179
foreach my $key ( keys %{$i_binFilesRef})
180180
{
@@ -292,6 +292,13 @@ sub manipulateImages
292292
run_command("cp $tempImages{PAD_PHASE} $fsp_file");
293293
}
294294

295+
# Hack HBI page to fail verification, Ensure location is past hash page table
296+
if ($eyeCatch eq "HBI")
297+
{
298+
# Leave in here for now
299+
# run_command("printf \'\\xa1\' | dd conv=notrunc of=$tempImages{PAD_PHASE} bs=1 seek=\$((0x00013000))");
300+
}
301+
295302
# ECC Phase
296303
if( ($sectionHash{$layoutKey}{ecc} eq "yes") )
297304
{
@@ -436,7 +443,7 @@ sub gen_test_containers
436443
# Create a signed test container with a hash page table
437444
# name = secureboot_hash_page_table_container (no prefix in hb cacheadd)
438445
$test_container = "$bin_dir/secureboot_hash_page_table_container";
439-
run_command("dd if=/dev/urandom count=50 ibs=4096 | tr \"\\000\" \"\\377\" > $tempImages{TEST_CONTAINER_DATA}");
446+
run_command("dd if=/dev/urandom count=5 ibs=4096 | tr \"\\000\" \"\\377\" > $tempImages{TEST_CONTAINER_DATA}");
440447
$tempImages{hashPageTable} = genHashPageTable($tempImages{TEST_CONTAINER_DATA}, "secureboot_test");
441448
run_command("$SIGNING_DIR/build -good -if $SECUREBOOT_HDR -of $tempImages{PROTECTED_PAYLOAD} -bin $tempImages{hashPageTable} $SIGN_BUILD_PARAMS");
442449
run_command("cat $tempImages{PROTECTED_PAYLOAD} $tempImages{TEST_CONTAINER_DATA} > $test_container ");

src/include/errno.h

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
/* */
66
/* OpenPOWER HostBoot Project */
77
/* */
8-
/* COPYRIGHT International Business Machines Corp. 2011,2014 */
8+
/* Contributors Listed Below - COPYRIGHT 2011,2016 */
9+
/* [+] International Business Machines Corp. */
10+
/* */
911
/* */
1012
/* Licensed under the Apache License, Version 2.0 (the "License"); */
1113
/* you may not use this file except in compliance with the License. */
@@ -23,13 +25,20 @@
2325
#ifndef _ERRNO_H
2426
#define _ERRNO_H
2527

28+
#include <map>
29+
30+
// Map to to store strings of errorno codes
31+
typedef std::map<int, const char*> ErrorNoNames;
32+
33+
// Add new ERRNO's to ErrorNoNames init function
2634
#define ENOENT 2 // No such file or directory
2735
#define EIO 5 // I/O error
2836
#define ENXIO 6 // No such device or address
2937
#define ENOEXEC 8 // Exec format error
3038
#define EBADF 9 // Bad file descriptor
3139
#define EAGAIN 11 // Try again
32-
#define EFAULT 14 // Bad address
40+
#define EACCES 13 // Permission denied
41+
#define EFAULT 14 // Bad address
3342
#define EINVAL 22 // Invalid argument
3443
#define ENFILE 23 // Too many open files in system
3544
#define EDEADLK 35 // Operation would cause deadlock.
@@ -38,4 +47,27 @@
3847

3948
#define EWOULDBLOCK EAGAIN // operation would block
4049

50+
// @Brief Initialize an ErrorNoNames map
51+
// Note: All keys and values are preceded with a '-', this is because the
52+
// the errno's will be set to 2's complement when there's an error.
53+
inline ErrorNoNames init_map()
54+
{
55+
ErrorNoNames l_map;
56+
l_map[-ENOENT] = "-ENOENT";
57+
l_map[-EIO] = "-EIO";
58+
l_map[-ENXIO] = "-ENXIO";
59+
l_map[-ENOEXEC] = "-ENOEXEC";
60+
l_map[-EBADF] = "-EBADF";
61+
l_map[-EAGAIN] = "-EAGAIN";
62+
l_map[-EACCES] = "-EACCES";
63+
l_map[-EFAULT] = "-EFAULT";
64+
l_map[-EINVAL] = "-EINVAL";
65+
l_map[-ENFILE] = "-ENFILE";
66+
l_map[-EDEADLK] = "-EDEADLK";
67+
l_map[-ETIME] = "-ETIME";
68+
l_map[-EALREADY] = "-EALREADY";
69+
l_map[-EWOULDBLOCK] = "-EWOULDBLOCK";
70+
return l_map;
71+
};
72+
4173
#endif

src/include/kernel/msghandler.H

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
/* */
66
/* OpenPOWER HostBoot Project */
77
/* */
8-
/* COPYRIGHT International Business Machines Corp. 2011,2014 */
8+
/* Contributors Listed Below - COPYRIGHT 2011,2016 */
9+
/* [+] International Business Machines Corp. */
10+
/* */
911
/* */
1012
/* Licensed under the Apache License, Version 2.0 (the "License"); */
1113
/* you may not use this file except in compliance with the License. */
@@ -31,6 +33,8 @@
3133
#include <kernel/msg.H>
3234
#include <kernel/spinlock.H>
3335
#include <util/locked/list.H>
36+
#include <map>
37+
#include <errno.h>
3438

3539
// Forward declaration.
3640
namespace Systemcalls { void MsgRespond(task_t*); };
@@ -165,6 +169,9 @@ class MessageHandler
165169
virtual HandleResult handleResponse(msg_sys_types_t i_type, void* i_key,
166170
task_t* i_task, int i_rc);
167171

172+
// @brief Map to print out string of errorno received by msg handler
173+
static ErrorNoNames iv_errnoNames;
174+
168175
protected:
169176
/** @brief 'Recv message' interface.
170177
* Called by the msg_respond sys-call handler to relay the response

src/include/sys/vfs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ extern VfsSystemModule VFS_MODULES[VFS_MODULE_MAX];
100100

101101
extern uint64_t VFS_LAST_ADDRESS;
102102

103+
#define VFS_MODULE_TABLE_SIZE (VFS_EXTENDED_MODULE_MAX * sizeof(VfsSystemModule))
104+
103105
#ifdef __cplusplus
104106
}
105107
#endif

src/include/usr/secureboot/service.H

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,23 @@ namespace SECUREBOOT
8787
*/
8888
void getHwHashKeys(sha2_hash_t o_hash);
8989

90+
/*
91+
* @brief Hash the concatenation of two Blobs
92+
*
93+
* Asserts if either blobs are NULL
94+
*
95+
* @param[in] i_blob1 Void pointer to effective address of blob1
96+
* @param[in] i_blob1Size Size of blob1 in bytes
97+
* @param[in] i_blob2 Void pointer to effective address of blob2
98+
* @param[in] i_blob2Size Size of blob2 in bytes
99+
* @param[out] o_hash SHA512 hash
100+
*
101+
* @return errlHndl_t NULL on success
102+
*/
103+
errlHndl_t hashConcatBlobs (const void* i_blob1, size_t i_blob1Size,
104+
const void* i_blob2, size_t i_blob2Size,
105+
SHA512_t o_buf);
106+
90107
}
91108

92109
#endif

src/include/usr/vfs/vfs_reasoncodes.H

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
/* */
66
/* OpenPOWER HostBoot Project */
77
/* */
8-
/* COPYRIGHT International Business Machines Corp. 2011,2014 */
8+
/* Contributors Listed Below - COPYRIGHT 2011,2016 */
9+
/* [+] International Business Machines Corp. */
10+
/* */
911
/* */
1012
/* Licensed under the Apache License, Version 2.0 (the "License"); */
1113
/* you may not use this file except in compliance with the License. */
@@ -45,7 +47,7 @@ namespace VFS
4547
VFS_PERMS_VMEM_FAILED = VFS_COMP_ID | 0x04,
4648
VFS_MODULE_DOES_NOT_EXIST = VFS_COMP_ID | 0x05,
4749
VFS_INVALID_DATA_MODULE = VFS_COMP_ID | 0x06,
48-
VFS_TASK_CRASHED = VFS_COMP_ID | 0x07,
50+
VFS_TASK_CRASHED = VFS_COMP_ID | 0x07
4951
};
5052
};
5153

src/kernel/msghandler.C

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
/* */
66
/* OpenPOWER HostBoot Project */
77
/* */
8-
/* COPYRIGHT International Business Machines Corp. 2011,2014 */
8+
/* Contributors Listed Below - COPYRIGHT 2011,2016 */
9+
/* [+] International Business Machines Corp. */
10+
/* */
911
/* */
1012
/* Licensed under the Apache License, Version 2.0 (the "License"); */
1113
/* you may not use this file except in compliance with the License. */
@@ -30,6 +32,8 @@
3032
#include <kernel/taskmgr.H>
3133
#include <kernel/console.H>
3234

35+
ErrorNoNames MessageHandler::iv_errnoNames = init_map();
36+
3337
void MessageHandler::sendMessage(msg_sys_types_t i_type, void* i_key,
3438
void* i_data, task_t* i_task)
3539
{
@@ -172,8 +176,18 @@ int MessageHandler::recvMessage(msg_t* i_msg)
172176
else if (UNHANDLED_RC == rc)
173177
{
174178
// Unsuccessful, unhandled response. Kill task.
175-
printk("Unhandled msg rc %d for key %p on task %d @ %p\n",
179+
// Print the errorno string if we have mapped it in errno.h
180+
if (iv_errnoNames.count(msg_rc) > 0)
181+
{
182+
printk("Unhandled msg rc %s for key %p on task %d @ %p\n",
183+
iv_errnoNames[msg_rc], key, deferred_task->tid,
184+
deferred_task->context.nip);
185+
}
186+
else
187+
{
188+
printk("Unhandled msg rc %d for key %p on task %d @ %p\n",
176189
msg_rc, key, deferred_task->tid, deferred_task->context.nip);
190+
}
177191
endTaskList.insert(deferred_task);
178192
}
179193
else if (CONTINUE_DEFER == rc)

src/makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ hbicore_test_DATA_MODULES += ${hbicore_DATA_MODULES}
307307
hbicore_test_DATA_MODULES += testdata
308308
ifndef SKIP_BINARY_FILES
309309
hbicore_test_DATA_MODULES += secureboot_signed_container
310+
hbicore_test_DATA_MODULES += secureboot_hash_page_table_container
310311
endif
311312

312313
hbirt_OBJECTS += ${RUNTIME_OBJECTS}

src/usr/pnor/pnor_common.C

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,10 @@ errlHndl_t PNOR::parseTOC(uint8_t* i_toc0Buffer, uint8_t* i_toc1Buffer,
449449
((o_TOC[secId].size * 8 ) / 9);
450450
}
451451

452-
// TODO RTC:96009 handle version header w/secureboot
453-
if (o_TOC[secId].version == FFS_VERS_SHA512)
452+
// @TODO RTC:153773 move header handling to secure pnor rp
453+
// Don't skip header if verification is needed.
454+
if (o_TOC[secId].version == FFS_VERS_SHA512
455+
&& strcmp(cur_entry->name,"HBI") != 0)
454456
{
455457
TRACFCOMP(g_trac_pnor, "PNOR::parseTOC: Incrementing"
456458
" Flash Address for SHA Header");
@@ -477,7 +479,6 @@ errlHndl_t PNOR::parseTOC(uint8_t* i_toc0Buffer, uint8_t* i_toc1Buffer,
477479
}
478480
}
479481

480-
481482
if((o_TOC[secId].flashAddr + o_TOC[secId].size) >
482483
(l_ffs_hdr->block_count*PAGESIZE))
483484
{

0 commit comments

Comments
 (0)