@@ -87,6 +87,11 @@ struct owner_flash_config_8 {
8787 owner_flash_region_t config[8 ];
8888};
8989
90+ struct owner_flash_config_9 {
91+ tlv_header_t header;
92+ owner_flash_region_t config[9 ];
93+ };
94+
9095struct owner_flash_info_config_2 {
9196 tlv_header_t header;
9297 owner_info_page_t config[2 ];
@@ -174,6 +179,18 @@ const owner_flash_config_4 simple_flash_config_wrapped = {
174179const owner_flash_config_t &simple_flash_config =
175180 reinterpret_cast <const owner_flash_config_t &>(simple_flash_config_wrapped);
176181
182+ const owner_flash_config_9 flash_config_too_many_entries_wrapped = {
183+ .header =
184+ {
185+ .tag = kTlvTagFlashConfig ,
186+ .length = sizeof (owner_flash_config_9),
187+ },
188+ };
189+
190+ const owner_flash_config_t &flash_config_too_many_entries =
191+ reinterpret_cast <const owner_flash_config_t &>(
192+ flash_config_too_many_entries_wrapped);
193+
177194const owner_flash_info_config_2 info_config_wrapped = {
178195 .header =
179196 {
@@ -224,6 +241,14 @@ const owner_flash_info_config_2 info_config_wrapped = {
224241const owner_flash_info_config_t &info_config =
225242 reinterpret_cast <const owner_flash_info_config_t &>(info_config_wrapped);
226243
244+ TEST_F (OwnerBlockTest, FlashConfigTooManyEntries) {
245+ uint32_t mp_index = 0 ;
246+ rom_error_t error =
247+ owner_block_flash_apply (&flash_config_too_many_entries, kBootSlotA ,
248+ /* owner_lockdown=*/ 0 , &mp_index);
249+ EXPECT_EQ (error, kErrorOwnershipFlashConfigLength );
250+ }
251+
227252// Tests that the flash parameters get applied for side A.
228253TEST_F (OwnerBlockTest, FlashConfigApplySideA) {
229254 // The ROM_EXT always uses regions 0-1 to protect itself, The items in
@@ -480,6 +505,48 @@ TEST_F(OwnerBlockTest, ParseBlockDupIsfb) {
480505 EXPECT_EQ (error, kErrorOwnershipDuplicateItem );
481506}
482507
508+ TEST_F (OwnerBlockTest, IsfbEraseEnableInvalidState) {
509+ boot_data_t bootdata = {};
510+ bootdata.ownership_state = kOwnershipStateUnlockedAny ;
511+ owner_config_t owner_config = {};
512+ EXPECT_EQ (owner_block_info_isfb_erase_enable (&bootdata, &owner_config),
513+ kErrorOk );
514+ }
515+
516+ TEST_F (OwnerBlockTest, NonExistIsfbConfig) {
517+ boot_data_t bootdata = {};
518+ bootdata.ownership_state = kOwnershipStateLockedOwner ;
519+ owner_config_t owner_config = {};
520+ owner_config.isfb = (const owner_isfb_config_t *)kHardenedBoolFalse ;
521+ EXPECT_EQ (owner_block_info_isfb_erase_enable (&bootdata, &owner_config),
522+ kErrorOk );
523+ }
524+
525+ TEST_F (OwnerBlockTest, NonExistInfoConfig) {
526+ boot_data_t bootdata = {};
527+ bootdata.ownership_state = kOwnershipStateLockedOwner ;
528+ owner_config_t owner_config = {};
529+ owner_config.isfb = (const owner_isfb_config_t *)kHardenedBoolTrue ;
530+ owner_config.info = (const owner_flash_info_config_t *)kHardenedBoolFalse ;
531+ EXPECT_EQ (owner_block_info_isfb_erase_enable (&bootdata, &owner_config),
532+ kErrorOk );
533+ }
534+
535+ TEST (OwnerBlockTransferTest, ValidTransfer) {
536+ owner_page_valid[1 ] = kOwnerPageStatusSealed ;
537+ boot_data_t bootdata = {};
538+ bootdata.ownership_state = kOwnershipStateLockedOwner ;
539+ EXPECT_EQ (owner_block_page1_valid_for_transfer (&bootdata), kHardenedBoolTrue );
540+ }
541+
542+ const owner_isfb_config_t isfb_config_bad_length = {
543+ .header =
544+ {
545+ .tag = kTlvTagIntegrationSpecificFirmwareBinding ,
546+ .length = 0 ,
547+ },
548+ };
549+
483550const owner_isfb_config_t isfb_config_bad_page = {
484551 .header =
485552 {
@@ -521,6 +588,8 @@ TEST_P(OwnerBlockBadIsfbTest, ParseBlockBadIsfb) {
521588INSTANTIATE_TEST_SUITE_P (
522589 AllCases, OwnerBlockBadIsfbTest,
523590 testing::Values (IsfbError{isfb_config_bad_page, kErrorOwnershipISFBPage },
591+ IsfbError{isfb_config_bad_length,
592+ kErrorOwnershipInvalidTagLength },
524593 IsfbError{isfb_config_bad_product_word_count,
525594 kErrorOwnershipISFBSize }));
526595
@@ -926,6 +995,30 @@ const owner_flash_config_4 invalid_flash_7_wrapped = {
926995const owner_flash_config_t &invalid_flash_7 =
927996 reinterpret_cast <const owner_flash_config_t &>(invalid_flash_7_wrapped);
928997
998+ // Flash configuration has a zero length.
999+ const owner_flash_config_4 invalid_flash_8_wrapped = {
1000+ .header =
1001+ {
1002+ .tag = kTlvTagFlashConfig ,
1003+ .length = 0 ,
1004+ },
1005+ };
1006+
1007+ const owner_flash_config_t &invalid_flash_8 =
1008+ reinterpret_cast <const owner_flash_config_t &>(invalid_flash_8_wrapped);
1009+
1010+ // Flash configuration has mis-aligned length.
1011+ const owner_flash_config_4 invalid_flash_9_wrapped = {
1012+ .header =
1013+ {
1014+ .tag = kTlvTagFlashConfig ,
1015+ .length = sizeof (owner_flash_config_4) + 1 ,
1016+ },
1017+ };
1018+
1019+ const owner_flash_config_t &invalid_flash_9 =
1020+ reinterpret_cast <const owner_flash_config_t &>(invalid_flash_9_wrapped);
1021+
9291022class RomExtFlashConfigTest
9301023 : public OwnerBlockTest,
9311024 public testing::WithParamInterface<
@@ -952,7 +1045,9 @@ INSTANTIATE_TEST_SUITE_P(
9521045 std::make_tuple(&invalid_flash_4, kErrorOwnershipFlashConfigLength ),
9531046 std::make_tuple(&invalid_flash_5, kErrorOwnershipFlashConfigBounds ),
9541047 std::make_tuple(&invalid_flash_6, kErrorOwnershipFlashConfigSlots ),
955- std::make_tuple(&invalid_flash_7, kErrorOwnershipFlashConfigSlots )));
1048+ std::make_tuple(&invalid_flash_7, kErrorOwnershipFlashConfigSlots ),
1049+ std::make_tuple(&invalid_flash_8, kErrorOwnershipInvalidTagLength ),
1050+ std::make_tuple(&invalid_flash_9, kErrorOwnershipInvalidTagLength )));
9561051
9571052struct FlashRegion {
9581053 uint32_t start;
@@ -1041,6 +1136,8 @@ testing::Values(
10411136 OwnerBlockLengths{kTlvTagApplicationKey , 512 , kErrorOwnershipInvalidTagLength },
10421137 OwnerBlockLengths{kTlvTagFlashConfig , 4 , kErrorOwnershipInvalidTagLength },
10431138 OwnerBlockLengths{kTlvTagInfoConfig , 4 , kErrorOwnershipInvalidTagLength },
1139+ OwnerBlockLengths{kTlvTagFlashConfig , 12 , kErrorOwnershipInvalidTagLength },
1140+ OwnerBlockLengths{kTlvTagInfoConfig , 12 , kErrorOwnershipInvalidTagLength },
10441141 OwnerBlockLengths{kTlvTagRescueConfig , 12 , kErrorOwnershipInvalidTagLength }
10451142));
10461143// clang-format on
@@ -1123,6 +1220,17 @@ class FlashInfoCheckTest : public OwnerBlockTest,
11231220 public testing::WithParamInterface<
11241221 std::tuple<uint8_t , uint8_t , rom_error_t >> {};
11251222
1223+ TEST_F (FlashInfoCheckTest, FlashInfoCheckInvalidLength) {
1224+ const owner_flash_info_config_t info = {
1225+ .header =
1226+ {
1227+ .length = 0 ,
1228+ },
1229+ };
1230+ EXPECT_EQ (owner_block_flash_info_check (&info),
1231+ kErrorOwnershipInvalidTagLength );
1232+ }
1233+
11261234TEST_P (FlashInfoCheckTest, ValidPage) {
11271235 uint16_t bank, page;
11281236 rom_error_t expect;
0 commit comments