summaryrefslogtreecommitdiff
path: root/lib/chromeos
diff options
context:
space:
mode:
authorChe-Liang Chiou <clchiou@chromium.org>2011-07-25 14:39:35 +0800
committerSimon Glass <sjg@chromium.org>2011-08-29 10:59:13 -0700
commit34b7b623417dc1ba47f9d18a2e59e05787f6839c (patch)
tree073a193dd9f8099bf70ed8cee0540129fbc642f6 /lib/chromeos
parentd62fd066dbf5af9d6f44ce1d2f7e75f563b4fa9a (diff)
CHROMIUM: add cros_vboot/cros_legacy to kernel command line
Some scripts, like those in factory process, detect whether Chrome OS is booted from a verified boot or a legacy boot by overloading crossystem. If crossystem returns a valid hardware id, the scripts believe that Chrome OS is booted from a verified boot. Although this trick works, it does not sound right. This patch adds "cros_vboot" and "cros_legacy" to kernel command line of verified boot firmware and legacy firmware so that the scripts can grep the value, or the crossystem may do the grep. This patch also fixes unsafe use of strncpy. BUG=chromium-os:15700,chromium-os:18139 TEST=verified boot and grep cros_vboot /proc/cmdline TEST=boot from legacy and grep cros_legacy /proc/cmdline Change-Id: Id5182c2f4e05fc566a17b1e50f9157f96c50f866 Reviewed-on: http://gerrit.chromium.org/gerrit/4645 Reviewed-by: Che-Liang Chiou <clchiou@chromium.org> Tested-by: Che-Liang Chiou <clchiou@chromium.org>
Diffstat (limited to 'lib/chromeos')
-rw-r--r--lib/chromeos/boot_kernel.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/chromeos/boot_kernel.c b/lib/chromeos/boot_kernel.c
index 69ea6a169c..54ff83dcde 100644
--- a/lib/chromeos/boot_kernel.c
+++ b/lib/chromeos/boot_kernel.c
@@ -167,12 +167,17 @@ static void update_cmdline(char *src, int devnum, int partnum, uint8_t *guid,
int boot_kernel(VbSelectAndLoadKernelParams *kparams, crossystem_data_t *cdata)
{
- char cmdline_buf[CROS_CONFIG_SIZE + EXTRA_BUFFER];
- char cmdline_out[CROS_CONFIG_SIZE + EXTRA_BUFFER];
+ /* sizeof(CHROMEOS_BOOTARGS) reserves extra 1 byte */
+ char cmdline_buf[sizeof(CHROMEOS_BOOTARGS) + CROS_CONFIG_SIZE];
+ /* Reserve EXTRA_BUFFER bytes for update_cmdline's string replacement */
+ char cmdline_out[sizeof(CHROMEOS_BOOTARGS) + CROS_CONFIG_SIZE +
+ EXTRA_BUFFER];
char load_address[32];
char *argv[2] = {"bootm", load_address};
char *cmdline;
+ strcpy(cmdline_buf, CHROMEOS_BOOTARGS);
+
/*
* casting bootloader_address of uint64_t type to uintptr_t before
* further casting it to char * to avoid compiler warning "cast to
@@ -180,16 +185,15 @@ int boot_kernel(VbSelectAndLoadKernelParams *kparams, crossystem_data_t *cdata)
*/
cmdline = get_kernel_config((char *)
(uintptr_t)kparams->bootloader_address);
- strncpy(cmdline_buf, cmdline, CROS_CONFIG_SIZE);
-
- /* if we have init bootargs, append it */
- if ((cmdline = getenv("bootargs"))) {
- strcat(cmdline_buf, " ");
- strncat(cmdline_buf, cmdline, EXTRA_BUFFER - 1);
- }
+ /*
+ * strncat could write CROS_CONFIG_SIZE + 1 bytes to cmdline_buf. This
+ * is okay because the extra 1 byte has been reserved in sizeof().
+ */
+ strncat(cmdline_buf, cmdline, CROS_CONFIG_SIZE);
VBDEBUG(PREFIX "cmdline before update: %s\n", cmdline_buf);
+ /* TODO fix potential buffer overflow */
update_cmdline(cmdline_buf,
get_dev_num(kparams->disk_handle),
kparams->partition_number + 1,