Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: firmware/lib/vboot_kernel.c

Issue 3060004: Fix load_kernel_test, add check to LoadKernel to detect bad args. (Closed) Base URL: ssh://git@chromiumos-git//vboot_reference.git
Patch Set: Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | utility/load_kernel_test.c » ('j') | utility/load_kernel_test.c » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be 2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. 3 * found in the LICENSE file.
4 * 4 *
5 * Functions for loading a kernel from disk. 5 * Functions for loading a kernel from disk.
6 * (Firmware portion) 6 * (Firmware portion)
7 */ 7 */
8 8
9 #include "vboot_kernel.h" 9 #include "vboot_kernel.h"
10 10
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 105 }
106 106
107 /* Success */ 107 /* Success */
108 return 0; 108 return 0;
109 } 109 }
110 110
111 /* disable MSVC warning on const logical expression (as in } while(0);) */ 111 /* disable MSVC warning on const logical expression (as in } while(0);) */
112 __pragma(warning(disable: 4127)) 112 __pragma(warning(disable: 4127))
113 113
114 int LoadKernel(LoadKernelParams* params) { 114 int LoadKernel(LoadKernelParams* params) {
115 115 VbPublicKey* kernel_subkey;
116 VbPublicKey* kernel_subkey = (VbPublicKey*)params->header_sign_key_blob;
117
118 GptData gpt; 116 GptData gpt;
119 uint64_t part_start, part_size; 117 uint64_t part_start, part_size;
120 uint64_t blba = params->bytes_per_lba; 118 uint64_t blba;
121 uint64_t kbuf_sectors = KBUF_SIZE / blba; 119 uint64_t kbuf_sectors;
122 uint8_t* kbuf = NULL; 120 uint8_t* kbuf = NULL;
123 int found_partitions = 0; 121 int found_partitions = 0;
124 int good_partition = -1; 122 int good_partition = -1;
125 uint16_t tpm_key_version = 0; 123 uint16_t tpm_key_version = 0;
126 uint16_t tpm_kernel_version = 0; 124 uint16_t tpm_kernel_version = 0;
127 uint64_t lowest_key_version = 0xFFFF; 125 uint64_t lowest_key_version = 0xFFFF;
128 uint64_t lowest_kernel_version = 0xFFFF; 126 uint64_t lowest_kernel_version = 0xFFFF;
129 int is_dev = (BOOT_FLAG_DEVELOPER & params->boot_flags ? 1 : 0); 127 int is_dev;
130 int is_rec = (BOOT_FLAG_RECOVERY & params->boot_flags ? 1 : 0); 128 int is_rec;
131 int is_normal = (!is_dev && !is_rec); 129 int is_normal;
132 uint32_t status; 130 uint32_t status;
133 131
132 /* Sanity Checks */
133 if (!params ||
134 !params->header_sign_key_blob ||
135 !params->bytes_per_lba ||
136 !params->ending_lba ||
137 !params->kernel_buffer ||
138 !params->kernel_buffer_size) {
139 VBDEBUG(("LoadKernel() called with invalid params\n"));
140 return LOAD_KERNEL_INVALID;
141 }
142
143 /* Initialization */
144 kernel_subkey = (VbPublicKey*)params->header_sign_key_blob;
145 blba = params->bytes_per_lba;
146 kbuf_sectors = KBUF_SIZE / blba;
147 is_dev = (BOOT_FLAG_DEVELOPER & params->boot_flags ? 1 : 0);
148 is_rec = (BOOT_FLAG_RECOVERY & params->boot_flags ? 1 : 0);
149 is_normal = (!is_dev && !is_rec);
150
134 /* Clear output params in case we fail */ 151 /* Clear output params in case we fail */
135 params->partition_number = 0; 152 params->partition_number = 0;
136 params->bootloader_address = 0; 153 params->bootloader_address = 0;
137 params->bootloader_size = 0; 154 params->bootloader_size = 0;
138 155
139 if (!is_dev) { 156 if (!is_dev) {
140 /* TODO: should use the TPM all the time; for now, only use when 157 /* TODO: should use the TPM all the time; for now, only use when
141 * not in developer mode. */ 158 * not in developer mode. */
142 /* Let the TPM know if we're in recovery mode */ 159 /* Let the TPM know if we're in recovery mode */
143 if (is_rec) { 160 if (is_rec) {
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 /* Success! */ 423 /* Success! */
407 return LOAD_KERNEL_SUCCESS; 424 return LOAD_KERNEL_SUCCESS;
408 } 425 }
409 426
410 // Handle error cases 427 // Handle error cases
411 if (found_partitions) 428 if (found_partitions)
412 return LOAD_KERNEL_INVALID; 429 return LOAD_KERNEL_INVALID;
413 else 430 else
414 return LOAD_KERNEL_NOT_FOUND; 431 return LOAD_KERNEL_NOT_FOUND;
415 } 432 }
OLDNEW
« no previous file with comments | « no previous file | utility/load_kernel_test.c » ('j') | utility/load_kernel_test.c » ('J')

Powered by Google App Engine
This is Rietveld 408576698