summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 */