@@ -76,17 +76,17 @@ class FilesystemVerifierActionTest : public ::testing::Test {
76
76
utils::DivRoundUp (fec_data_size / BLOCK_SIZE, FEC_RSM - FEC_ROOTS);
77
77
fec_size = fec_rounds * FEC_ROOTS * BLOCK_SIZE;
78
78
79
- fec_data .resize (fec_size);
80
- hash_tree_data .resize (hash_tree_size);
79
+ fec_data_ .resize (fec_size);
80
+ hash_tree_data_ .resize (hash_tree_size);
81
81
brillo::Blob part_data (PARTITION_SIZE);
82
82
test_utils::FillWithData (&part_data);
83
83
ASSERT_TRUE (utils::WriteFile (
84
- source_part .path ().c_str (), part_data.data (), part_data.size ()));
84
+ source_part_ .path ().c_str (), part_data.data (), part_data.size ()));
85
85
// FillWithData() will fill with different data next call. We want
86
86
// source/target partitions to contain different data for testing.
87
87
test_utils::FillWithData (&part_data);
88
88
ASSERT_TRUE (utils::WriteFile (
89
- target_part .path ().c_str (), part_data.data (), part_data.size ()));
89
+ target_part_ .path ().c_str (), part_data.data (), part_data.size ()));
90
90
loop_.SetAsCurrent ();
91
91
}
92
92
@@ -107,16 +107,16 @@ class FilesystemVerifierActionTest : public ::testing::Test {
107
107
std::string name = " fake_part" ) {
108
108
InstallPlan::Partition& part = install_plan->partitions .emplace_back ();
109
109
part.name = name;
110
- part.target_path = target_part .path ();
110
+ part.target_path = target_part_ .path ();
111
111
part.readonly_target_path = part.target_path ;
112
112
part.target_size = PARTITION_SIZE;
113
113
part.block_size = BLOCK_SIZE;
114
- part.source_path = source_part .path ();
114
+ part.source_path = source_part_ .path ();
115
115
part.source_size = PARTITION_SIZE;
116
116
EXPECT_TRUE (
117
- HashCalculator::RawHashOfFile (source_part .path (), &part.source_hash ));
117
+ HashCalculator::RawHashOfFile (source_part_ .path (), &part.source_hash ));
118
118
EXPECT_TRUE (
119
- HashCalculator::RawHashOfFile (target_part .path (), &part.target_hash ));
119
+ HashCalculator::RawHashOfFile (target_part_ .path (), &part.target_hash ));
120
120
return ∂
121
121
}
122
122
static void ZeroRange (FileDescriptorPtr fd,
@@ -164,16 +164,16 @@ class FilesystemVerifierActionTest : public ::testing::Test {
164
164
}
165
165
ASSERT_TRUE (verity_writer.Finalize (fd, fd));
166
166
ASSERT_TRUE (fd->IsOpen ());
167
- ASSERT_TRUE (HashCalculator::RawHashOfFile (target_part .path (),
167
+ ASSERT_TRUE (HashCalculator::RawHashOfFile (target_part_ .path (),
168
168
&partition->target_hash ));
169
169
170
170
ASSERT_TRUE (fd->Seek (HASH_TREE_START_OFFSET, SEEK_SET));
171
- ASSERT_EQ (fd->Read (hash_tree_data .data (), hash_tree_data .size ()),
172
- static_cast <ssize_t >(hash_tree_data .size ()))
171
+ ASSERT_EQ (fd->Read (hash_tree_data_ .data (), hash_tree_data_ .size ()),
172
+ static_cast <ssize_t >(hash_tree_data_ .size ()))
173
173
<< " Failed to read hashtree " << strerror (errno);
174
174
ASSERT_TRUE (fd->Seek (fec_start_offset, SEEK_SET));
175
- ASSERT_EQ (fd->Read (fec_data .data (), fec_data .size ()),
176
- static_cast <ssize_t >(fec_data .size ()))
175
+ ASSERT_EQ (fd->Read (fec_data_ .data (), fec_data_ .size ()),
176
+ static_cast <ssize_t >(fec_data_ .size ()))
177
177
<< " Failed to read FEC " << strerror (errno);
178
178
// Fs verification action is expected to write them, so clear verity data to
179
179
// ensure that they are re-created correctly.
@@ -185,17 +185,28 @@ class FilesystemVerifierActionTest : public ::testing::Test {
185
185
brillo::FakeMessageLoop loop_{nullptr };
186
186
ActionProcessor processor_;
187
187
DynamicPartitionControlStub dynamic_control_stub_;
188
- std::vector<unsigned char > fec_data;
189
- std::vector<unsigned char > hash_tree_data;
190
- static ScopedTempFile source_part;
191
- static ScopedTempFile target_part;
188
+ std::vector<unsigned char > fec_data_;
189
+ std::vector<unsigned char > hash_tree_data_;
190
+ static ScopedTempFile source_part_;
191
+ static ScopedTempFile target_part_;
192
+ InstallPlan install_plan_;
192
193
};
193
194
194
- ScopedTempFile FilesystemVerifierActionTest::source_part {
195
+ ScopedTempFile FilesystemVerifierActionTest::source_part_ {
195
196
" source_part.XXXXXX" , false , PARTITION_SIZE};
196
- ScopedTempFile FilesystemVerifierActionTest::target_part {
197
+ ScopedTempFile FilesystemVerifierActionTest::target_part_ {
197
198
" target_part.XXXXXX" , false , PARTITION_SIZE};
198
199
200
+ static void EnableVABC (MockDynamicPartitionControl* dynamic_control,
201
+ const std::string& part_name) {
202
+ ON_CALL (*dynamic_control, GetDynamicPartitionsFeatureFlag ())
203
+ .WillByDefault (Return (FeatureFlag (FeatureFlag::Value::LAUNCH)));
204
+ ON_CALL (*dynamic_control, UpdateUsesSnapshotCompression ())
205
+ .WillByDefault (Return (true ));
206
+ ON_CALL (*dynamic_control, IsDynamicPartition (part_name, _))
207
+ .WillByDefault (Return (true ));
208
+ }
209
+
199
210
class FilesystemVerifierActionTestDelegate : public ActionProcessorDelegate {
200
211
public:
201
212
FilesystemVerifierActionTestDelegate ()
@@ -261,9 +272,8 @@ bool FilesystemVerifierActionTest::DoTest(bool terminate_early,
261
272
bool success = true ;
262
273
263
274
// Set up the action objects
264
- InstallPlan install_plan;
265
- install_plan.source_slot = 0 ;
266
- install_plan.target_slot = 1 ;
275
+ install_plan_.source_slot = 0 ;
276
+ install_plan_.target_slot = 1 ;
267
277
InstallPlan::Partition part;
268
278
part.name = " part" ;
269
279
part.target_size = kLoopFileSize - (hash_fail ? 1 : 0 );
@@ -278,9 +288,9 @@ bool FilesystemVerifierActionTest::DoTest(bool terminate_early,
278
288
ADD_FAILURE ();
279
289
success = false ;
280
290
}
281
- install_plan .partitions = {part};
291
+ install_plan_ .partitions = {part};
282
292
283
- BuildActions (install_plan );
293
+ BuildActions (install_plan_ );
284
294
285
295
FilesystemVerifierActionTestDelegate delegate;
286
296
processor_.set_delegate (&delegate);
@@ -323,7 +333,7 @@ bool FilesystemVerifierActionTest::DoTest(bool terminate_early,
323
333
EXPECT_TRUE (is_a_file_reading_eq);
324
334
success = success && is_a_file_reading_eq;
325
335
326
- bool is_install_plan_eq = (*delegate.install_plan_ == install_plan );
336
+ bool is_install_plan_eq = (*delegate.install_plan_ == install_plan_ );
327
337
EXPECT_TRUE (is_install_plan_eq);
328
338
success = success && is_install_plan_eq;
329
339
return success;
@@ -388,14 +398,13 @@ TEST_F(FilesystemVerifierActionTest, MissingInputObjectTest) {
388
398
}
389
399
390
400
TEST_F (FilesystemVerifierActionTest, NonExistentDriveTest) {
391
- InstallPlan install_plan;
392
401
InstallPlan::Partition part;
393
402
part.name = " nope" ;
394
403
part.source_path = " /no/such/file" ;
395
404
part.target_path = " /no/such/file" ;
396
- install_plan .partitions = {part};
405
+ install_plan_ .partitions = {part};
397
406
398
- BuildActions (install_plan );
407
+ BuildActions (install_plan_ );
399
408
400
409
FilesystemVerifierActionTest2Delegate delegate;
401
410
processor_.set_delegate (&delegate);
@@ -436,7 +445,6 @@ TEST_F(FilesystemVerifierActionTest, RunAsRootWriteVerityTest) {
436
445
test_utils::ScopedLoopbackDeviceBinder target_device (
437
446
part_file.path (), true , &target_path);
438
447
439
- InstallPlan install_plan;
440
448
InstallPlan::Partition part;
441
449
part.name = " part" ;
442
450
part.target_path = target_path;
@@ -467,9 +475,9 @@ TEST_F(FilesystemVerifierActionTest, RunAsRootWriteVerityTest) {
467
475
part.hash_tree_salt = {0x9e , 0xcb , 0xf8 , 0xd5 , 0x0b , 0xb4 , 0x43 ,
468
476
0x0a , 0x7a , 0x10 , 0xad , 0x96 , 0xd7 , 0x15 ,
469
477
0x70 , 0xba , 0xed , 0x27 , 0xe2 , 0xae };
470
- install_plan .partitions = {part};
478
+ install_plan_ .partitions = {part};
471
479
472
- BuildActions (install_plan );
480
+ BuildActions (install_plan_ );
473
481
474
482
FilesystemVerifierActionTestDelegate delegate;
475
483
processor_.set_delegate (&delegate);
@@ -498,8 +506,7 @@ TEST_F(FilesystemVerifierActionTest, RunAsRootSkipWriteVerityTest) {
498
506
test_utils::ScopedLoopbackDeviceBinder target_device (
499
507
part_file.path (), true , &target_path);
500
508
501
- InstallPlan install_plan;
502
- install_plan.write_verity = false ;
509
+ install_plan_.write_verity = false ;
503
510
InstallPlan::Partition part;
504
511
part.name = " part" ;
505
512
part.target_path = target_path;
@@ -514,9 +521,9 @@ TEST_F(FilesystemVerifierActionTest, RunAsRootSkipWriteVerityTest) {
514
521
part.fec_offset = part.fec_data_size ;
515
522
part.fec_size = 2 * 4096 ;
516
523
EXPECT_TRUE (HashCalculator::RawHashOfData (part_data, &part.target_hash ));
517
- install_plan .partitions = {part};
524
+ install_plan_ .partitions = {part};
518
525
519
- BuildActions (install_plan );
526
+ BuildActions (install_plan_ );
520
527
521
528
FilesystemVerifierActionTestDelegate delegate;
522
529
processor_.set_delegate (&delegate);
@@ -535,33 +542,24 @@ TEST_F(FilesystemVerifierActionTest, RunAsRootSkipWriteVerityTest) {
535
542
536
543
void FilesystemVerifierActionTest::DoTestVABC (bool clear_target_hash,
537
544
bool enable_verity) {
538
- InstallPlan install_plan;
539
- auto part_ptr = AddFakePartition (&install_plan);
545
+ auto part_ptr = AddFakePartition (&install_plan_);
540
546
if (::testing::Test::HasFailure ()) {
541
547
return ;
542
548
}
543
549
ASSERT_NE (part_ptr, nullptr );
544
550
InstallPlan::Partition& part = *part_ptr;
545
551
part.target_path = " Shouldn't attempt to open this path" ;
546
552
if (enable_verity) {
547
- install_plan.write_verity = true ;
548
- SetHashWithVerity (&part);
549
- if (::testing::Test::HasFailure ()) {
550
- return ;
551
- }
553
+ install_plan_.write_verity = true ;
554
+ ASSERT_NO_FATAL_FAILURE (SetHashWithVerity (&part));
552
555
}
553
556
if (clear_target_hash) {
554
557
part.target_hash .clear ();
555
558
}
556
559
557
560
NiceMock<MockDynamicPartitionControl> dynamic_control;
558
561
559
- ON_CALL (dynamic_control, GetDynamicPartitionsFeatureFlag ())
560
- .WillByDefault (Return (FeatureFlag (FeatureFlag::Value::LAUNCH)));
561
- ON_CALL (dynamic_control, UpdateUsesSnapshotCompression ())
562
- .WillByDefault (Return (true ));
563
- ON_CALL (dynamic_control, IsDynamicPartition (part.name , _))
564
- .WillByDefault (Return (true ));
562
+ EnableVABC (&dynamic_control, part.name );
565
563
566
564
EXPECT_CALL (dynamic_control, UpdateUsesSnapshotCompression ())
567
565
.Times (AtLeast (1 ));
@@ -589,7 +587,7 @@ void FilesystemVerifierActionTest::DoTestVABC(bool clear_target_hash,
589
587
DoAll (SetArgPointee<2 , std::vector<std::string>>({part.name }),
590
588
Return (true )));
591
589
592
- BuildActions (install_plan , &dynamic_control);
590
+ BuildActions (install_plan_ , &dynamic_control);
593
591
594
592
FilesystemVerifierActionTestDelegate delegate;
595
593
processor_.set_delegate (&delegate);
@@ -611,14 +609,14 @@ void FilesystemVerifierActionTest::DoTestVABC(bool clear_target_hash,
611
609
actual_fec.size (),
612
610
fec_start_offset,
613
611
&bytes_read));
614
- ASSERT_EQ (actual_fec, fec_data );
612
+ ASSERT_EQ (actual_fec, fec_data_ );
615
613
std::vector<unsigned char > actual_hash_tree (hash_tree_size);
616
614
ASSERT_TRUE (utils::PReadAll (cow_fd,
617
615
actual_hash_tree.data (),
618
616
actual_hash_tree.size (),
619
617
HASH_TREE_START_OFFSET,
620
618
&bytes_read));
621
- ASSERT_EQ (actual_hash_tree, hash_tree_data );
619
+ ASSERT_EQ (actual_hash_tree, hash_tree_data_ );
622
620
}
623
621
if (clear_target_hash) {
624
622
ASSERT_EQ (ErrorCode::kNewRootfsVerificationError , delegate.code ());
@@ -639,6 +637,37 @@ TEST_F(FilesystemVerifierActionTest, VABC_Verity_Success) {
639
637
DoTestVABC (false , true );
640
638
}
641
639
640
+ TEST_F (FilesystemVerifierActionTest, VABC_Verity_ReadAfterWrite) {
641
+ ASSERT_NO_FATAL_FAILURE (DoTestVABC (false , true ));
642
+ // Run FS verification again, w/o writing verity. We have seen a bug where
643
+ // attempting to run fs again will cause previously written verity data to be
644
+ // dropped, so cover this scenario.
645
+ ASSERT_GE (install_plan_.partitions .size (), 1UL );
646
+ auto & part = install_plan_.partitions [0 ];
647
+ install_plan_.write_verity = false ;
648
+ part.readonly_target_path = target_part_.path ();
649
+ NiceMock<MockDynamicPartitionControl> dynamic_control;
650
+ EnableVABC (&dynamic_control, part.name );
651
+
652
+ // b/186196758 is only visible if we repeatedely run FS verification w/o
653
+ // writing verity
654
+ for (int i = 0 ; i < 3 ; i++) {
655
+ BuildActions (install_plan_, &dynamic_control);
656
+
657
+ FilesystemVerifierActionTestDelegate delegate;
658
+ processor_.set_delegate (&delegate);
659
+ loop_.PostTask (
660
+ FROM_HERE,
661
+ base::Bind (
662
+ [](ActionProcessor* processor) { processor->StartProcessing (); },
663
+ base::Unretained (&processor_)));
664
+ loop_.Run ();
665
+ ASSERT_FALSE (processor_.IsRunning ());
666
+ ASSERT_TRUE (delegate.ran ());
667
+ ASSERT_EQ (ErrorCode::kSuccess , delegate.code ());
668
+ }
669
+ }
670
+
642
671
TEST_F (FilesystemVerifierActionTest, VABC_Verity_Target_Mismatch) {
643
672
DoTestVABC (true , true );
644
673
}
0 commit comments