summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Hurst <shurst@google.com>2018-04-26 12:42:31 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-05-01 08:31:57 -0700
commitae602dee78452ee2c9667ad9d71c54ac1668e743 (patch)
tree7d34afe033caf8132ad03fe5c26a39e53f5ebd7e
parent8c34ae60786f7ff28b24ceb1b065a3b42e63c3c9 (diff)
downloadvboot-ae602dee78452ee2c9667ad9d71c54ac1668e743.tar.gz
cgpt: Remove unnecessary 512-byte sector check and minimum lba count checks.
This was an oversight from a previous CL:1007498 that removed the 512 block size restrictions. BUG=b:77540192 BRANCH=none TEST=manual make runtests passed. Change-Id: I75b3ffebcc25afdde3774bcbb4a9600215a04436 Reviewed-on: https://chromium-review.googlesource.com/1031193 Commit-Ready: Sam Hurst <shurst@google.com> Tested-by: Sam Hurst <shurst@google.com> Reviewed-by: Julius Werner <jwerner@chromium.org>
-rw-r--r--firmware/lib/vboot_api_kernel.c15
-rw-r--r--tests/vboot_api_kernel_tests.c44
2 files changed, 48 insertions, 11 deletions
diff --git a/firmware/lib/vboot_api_kernel.c b/firmware/lib/vboot_api_kernel.c
index 8016fae0..3ae3cd4d 100644
--- a/firmware/lib/vboot_api_kernel.c
+++ b/firmware/lib/vboot_api_kernel.c
@@ -100,14 +100,15 @@ uint32_t VbTryLoadKernel(struct vb2_context *ctx, uint32_t get_info_flags)
* Sanity-check what we can. FWIW, VbTryLoadKernel() is always
* called with only a single bit set in get_info_flags.
*
- * Ensure 512-byte sectors and non-trivially sized disk (for
- * cgptlib) and that we got a partition with only the flags we
- * asked for.
+ * Ensure that we got a partition with only the flags we asked
+ * for.
*/
- if (512 != disk_info[i].bytes_per_lba ||
- 16 > disk_info[i].lba_count ||
- get_info_flags != (disk_info[i].flags &
- ~VB_DISK_FLAG_EXTERNAL_GPT)) {
+ if (disk_info[i].bytes_per_lba < 512 ||
+ (disk_info[i].bytes_per_lba &
+ (disk_info[i].bytes_per_lba - 1)) != 0 ||
+ 16 > disk_info[i].lba_count ||
+ get_info_flags != (disk_info[i].flags &
+ ~VB_DISK_FLAG_EXTERNAL_GPT)) {
VB2_DEBUG(" skipping: bytes_per_lba=%" PRIu64
" lba_count=%" PRIu64 " flags=0x%x\n",
disk_info[i].bytes_per_lba,
diff --git a/tests/vboot_api_kernel_tests.c b/tests/vboot_api_kernel_tests.c
index 3d8f48ad..133a778f 100644
--- a/tests/vboot_api_kernel_tests.c
+++ b/tests/vboot_api_kernel_tests.c
@@ -64,9 +64,41 @@ test_case_t test[] = {
.want_flags = VB_DISK_FLAG_REMOVABLE,
.disks_to_provide = {
/* too small */
- {512, 10, VB_DISK_FLAG_REMOVABLE, 0},
+ {512, 10, VB_DISK_FLAG_REMOVABLE, 0},
/* wrong LBA */
- {2048, 100, VB_DISK_FLAG_REMOVABLE, 0},
+ {511, 100, VB_DISK_FLAG_REMOVABLE, 0},
+ /* not a power of 2 */
+ {2047, 100, VB_DISK_FLAG_REMOVABLE, 0},
+ /* wrong type */
+ {512, 100, VB_DISK_FLAG_FIXED, 0},
+ /* wrong flags */
+ {512, 100, 0, 0},
+ /* still wrong flags */
+ {512, 100, -1, 0},
+ {4096, 100, VB_DISK_FLAG_REMOVABLE, pickme},
+ /* already got one */
+ {512, 100, VB_DISK_FLAG_REMOVABLE, "holygrail"},
+ },
+ .disk_count_to_return = DEFAULT_COUNT,
+ .diskgetinfo_return_val = VBERROR_SUCCESS,
+ .loadkernel_return_val = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1,},
+ .external_expected = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,},
+
+ .expected_recovery_request_val = VB2_RECOVERY_NOT_REQUESTED,
+ .expected_to_find_disk = pickme,
+ .expected_to_load_disk = pickme,
+ .expected_return_val = VBERROR_SUCCESS
+ },
+ {
+ .name = "first removable drive",
+ .want_flags = VB_DISK_FLAG_REMOVABLE,
+ .disks_to_provide = {
+ /* too small */
+ {512, 10, VB_DISK_FLAG_REMOVABLE, 0},
+ /* wrong LBA */
+ {511, 100, VB_DISK_FLAG_REMOVABLE, 0},
+ /* not a power of 2 */
+ {2047, 100, VB_DISK_FLAG_REMOVABLE, 0},
/* wrong type */
{512, 100, VB_DISK_FLAG_FIXED, 0},
/* wrong flags */
@@ -114,7 +146,9 @@ test_case_t test[] = {
/* too small */
{512, 10, VB_DISK_FLAG_FIXED, 0},
/* wrong LBA */
- {2048, 100, VB_DISK_FLAG_FIXED, 0},
+ {511, 100, VB_DISK_FLAG_FIXED, 0},
+ /* not a power of 2 */
+ {2047, 100, VB_DISK_FLAG_REMOVABLE, 0},
/* wrong type */
{512, 100, VB_DISK_FLAG_REMOVABLE, 0},
/* wrong flags */
@@ -157,7 +191,9 @@ test_case_t test[] = {
/* too small */
{512, 10, VB_DISK_FLAG_FIXED, 0},
/* wrong LBA */
- {2048, 100, VB_DISK_FLAG_FIXED, 0},
+ {511, 100, VB_DISK_FLAG_FIXED, 0},
+ /* not a power of 2 */
+ {2047, 100, VB_DISK_FLAG_FIXED, 0},
/* wrong type */
{512, 100, VB_DISK_FLAG_REMOVABLE, 0},
/* wrong flags */