Ensure that u-boot data is missing in non-pVM
u-boot uses instance disk only when protected VM. Bug: 218461230 Test: atest MicrodroidTests Change-Id: I66956f3b4a5c6bf6d134662d4ede652f46e2dcc3
This commit is contained in:
parent
87751bba76
commit
3eb0a6d5ed
|
@ -486,27 +486,37 @@ public class MicrodroidTests {
|
||||||
return payloadStarted.getNow(false);
|
return payloadStarted.getNow(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flips a bit of given partition, and then see if boot fails. The partition must exist.
|
private RandomAccessFile prepareInstanceImage(String vmName)
|
||||||
private void tryCompromisingInstanceDiskPartition(UUID partitionUuid)
|
|
||||||
throws VirtualMachineException, InterruptedException, IOException {
|
throws VirtualMachineException, InterruptedException, IOException {
|
||||||
VirtualMachineConfig config = mInner.newVmConfigBuilder("assets/vm_config.json")
|
VirtualMachineConfig config = mInner.newVmConfigBuilder("assets/vm_config.json")
|
||||||
.debugLevel(DebugLevel.NONE)
|
.debugLevel(DebugLevel.NONE)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Remove any existing VM so we can start from scratch
|
// Remove any existing VM so we can start from scratch
|
||||||
VirtualMachine oldVm = mInner.mVmm.getOrCreate("test_vm_integrity", config);
|
VirtualMachine oldVm = mInner.mVmm.getOrCreate(vmName, config);
|
||||||
oldVm.delete();
|
oldVm.delete();
|
||||||
mInner.mVmm.getOrCreate("test_vm_integrity", config);
|
mInner.mVmm.getOrCreate(vmName, config);
|
||||||
|
|
||||||
assertThat(tryBootVm("test_vm_integrity")).isTrue();
|
assertThat(tryBootVm(vmName)).isTrue();
|
||||||
|
|
||||||
// Launch the same VM after flipping a bit of the instance image.
|
|
||||||
// Flip actual data, as flipping trivial bits like the magic string isn't interesting.
|
|
||||||
File vmRoot = new File(mInner.mContext.getFilesDir(), "vm");
|
File vmRoot = new File(mInner.mContext.getFilesDir(), "vm");
|
||||||
File vmDir = new File(vmRoot, "test_vm_integrity");
|
File vmDir = new File(vmRoot, vmName);
|
||||||
File instanceImgPath = new File(vmDir, "instance.img");
|
File instanceImgPath = new File(vmDir, "instance.img");
|
||||||
RandomAccessFile instanceFile = new RandomAccessFile(instanceImgPath, "rw");
|
return new RandomAccessFile(instanceImgPath, "rw");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertThatPartitionIsMissing(UUID partitionUuid)
|
||||||
|
throws VirtualMachineException, InterruptedException, IOException {
|
||||||
|
RandomAccessFile instanceFile = prepareInstanceImage("test_vm_integrity");
|
||||||
|
assertThat(findPartitionDataOffset(instanceFile, partitionUuid).isPresent())
|
||||||
|
.isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flips a bit of given partition, and then see if boot fails.
|
||||||
|
private void assertThatBootFailsAfterCompromisingPartition(UUID partitionUuid)
|
||||||
|
throws VirtualMachineException, InterruptedException, IOException {
|
||||||
|
RandomAccessFile instanceFile = prepareInstanceImage("test_vm_integrity");
|
||||||
OptionalLong offset = findPartitionDataOffset(instanceFile, partitionUuid);
|
OptionalLong offset = findPartitionDataOffset(instanceFile, partitionUuid);
|
||||||
assertThat(offset.isPresent()).isTrue();
|
assertThat(offset.isPresent()).isTrue();
|
||||||
|
|
||||||
|
@ -521,11 +531,9 @@ public class MicrodroidTests {
|
||||||
.that(android.os.Build.DEVICE)
|
.that(android.os.Build.DEVICE)
|
||||||
.isNotEqualTo("vsoc_x86_64");
|
.isNotEqualTo("vsoc_x86_64");
|
||||||
|
|
||||||
tryCompromisingInstanceDiskPartition(MICRODROID_PARTITION_UUID);
|
assertThatBootFailsAfterCompromisingPartition(MICRODROID_PARTITION_UUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
// TODO(b/218461230): uncomment these after u-boot update
|
|
||||||
@Test
|
@Test
|
||||||
public void bootFailsWhenUBootAvbDataIsCompromised()
|
public void bootFailsWhenUBootAvbDataIsCompromised()
|
||||||
throws VirtualMachineException, InterruptedException, IOException {
|
throws VirtualMachineException, InterruptedException, IOException {
|
||||||
|
@ -533,11 +541,13 @@ public class MicrodroidTests {
|
||||||
.that(android.os.Build.DEVICE)
|
.that(android.os.Build.DEVICE)
|
||||||
.isNotEqualTo("vsoc_x86_64");
|
.isNotEqualTo("vsoc_x86_64");
|
||||||
|
|
||||||
assume().withMessage("Skip where protected VMs aren't support")
|
if (mProtectedVm) {
|
||||||
.that(mProtectedVm)
|
// TODO(b/218461230): uncomment this after u-boot update
|
||||||
.isTrue();
|
// assertThatBootFailsAfterCompromisingPartition(U_BOOT_AVB_PARTITION_UUID);
|
||||||
|
} else {
|
||||||
tryCompromisingInstanceDiskPartition(U_BOOT_AVB_PARTITION_UUID);
|
// non-protected VM shouldn't have u-boot avb data
|
||||||
|
assertThatPartitionIsMissing(U_BOOT_AVB_PARTITION_UUID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -547,11 +557,12 @@ public class MicrodroidTests {
|
||||||
.that(android.os.Build.DEVICE)
|
.that(android.os.Build.DEVICE)
|
||||||
.isNotEqualTo("vsoc_x86_64");
|
.isNotEqualTo("vsoc_x86_64");
|
||||||
|
|
||||||
assume().withMessage("Skip where protected VMs aren't support")
|
if (mProtectedVm) {
|
||||||
.that(mProtectedVm)
|
// TODO(b/218461230): uncomment this after u-boot update
|
||||||
.isTrue();
|
// assertThatBootFailsAfterCompromisingPartition(U_BOOT_ENV_PARTITION_UUID);
|
||||||
|
} else {
|
||||||
tryCompromisingInstanceDiskPartition(U_BOOT_ENV_PARTITION_UUID);
|
// non-protected VM shouldn't have u-boot env data
|
||||||
|
assertThatPartitionIsMissing(U_BOOT_ENV_PARTITION_UUID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue