summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShelley Chen <shchen@chromium.org>2015-09-14 15:39:29 -0700
committerchrome-bot <chrome-bot@chromium.org>2015-09-14 23:47:03 -0700
commit85f646613c7cb194a52608255e18cf827207c91a (patch)
treeecf2aed6b9f150f24b48402b8fc9cf4f1fa37680
parent82dec09bd5098715ddf9cd7d2e4abe87606d5249 (diff)
downloadvboot-85f646613c7cb194a52608255e18cf827207c91a.tar.gz
crossystem: Updated crossystem to accomodate Android
(resubmit) Previously crossystem assumed that mosys was located in /usr/sbin. In Android mosys is currently located in /system/bin. Using fixed paths as opposed to 'which' to prevent attacks where attacker could insert mosys in PATH. difference from previous commit: Removed the allocation of duplicate arrays. Kept with simplicity of original version, just returning correct constant depending on detected platform. BUG=chromium:527484 BRANCH=none TEST=ran crossystem, crossystem fw_try_count/ fw_try_next, crossystem fw_try_count/fw_try_next=x on smaug and daisy. Change-Id: I923206db1411a9a35c9c8e3f9ede5016f49b5f26 Signed-off-by: Shelley Chen <shchen@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/299801 Reviewed-by: danny chan <dchan@chromium.org>
-rw-r--r--host/arch/arm/lib/crossystem_arch.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/host/arch/arm/lib/crossystem_arch.c b/host/arch/arm/lib/crossystem_arch.c
index 6c745ff2..ff59da15 100644
--- a/host/arch/arm/lib/crossystem_arch.c
+++ b/host/arch/arm/lib/crossystem_arch.c
@@ -25,7 +25,8 @@
#include "crossystem.h"
#include "crossystem_arch.h"
-#define MOSYS_PATH "/usr/sbin/mosys"
+#define MOSYS_CROS_PATH "/usr/sbin/mosys"
+#define MOSYS_ANDROID_PATH "/system/bin/mosys"
/* Base name for firmware FDT files */
#define FDT_BASE_PATH "/proc/device-tree/firmware/chromeos"
@@ -69,6 +70,22 @@ const PlatformFamily platform_family_array[] = {
{NULL, NULL}
};
+static int InAndroid() {
+ int fd;
+ struct stat s;
+
+ /* In Android, mosys utility located in /system/bin
+ check if file exists. Using fstat because for some
+ reason, stat() was seg faulting in Android */
+ fd = open(MOSYS_ANDROID_PATH, O_RDONLY);
+ if (fstat(fd, &s) == 0) {
+ close(fd);
+ return 1;
+ }
+ close(fd);
+ return 0;
+}
+
static int FindEmmcDev(void) {
int mmcblk;
unsigned value;
@@ -313,7 +330,7 @@ static int ExecuteMosys(char * const argv[], char *buf, size_t bufsize) {
}
}
/* Execute mosys */
- execv(MOSYS_PATH, argv);
+ execv(InAndroid() ? MOSYS_ANDROID_PATH : MOSYS_CROS_PATH, argv);
/* We shouldn't be here; exit now! */
VBDEBUG(("execv() of mosys failed\n"));
close(mosys_to_crossystem[1]);
@@ -347,7 +364,8 @@ static int ExecuteMosys(char * const argv[], char *buf, size_t bufsize) {
static int VbReadNvStorage_mosys(VbNvContext* vnc) {
char hexstring[VBNV_BLOCK_SIZE * 2 + 32]; /* Reserve extra 32 bytes */
char * const argv[] = {
- MOSYS_PATH, "nvram", "vboot", "read", NULL
+ InAndroid() ? MOSYS_ANDROID_PATH : MOSYS_CROS_PATH,
+ "nvram", "vboot", "read", NULL
};
char hexdigit[3];
int i;
@@ -366,7 +384,8 @@ static int VbReadNvStorage_mosys(VbNvContext* vnc) {
static int VbWriteNvStorage_mosys(VbNvContext* vnc) {
char hexstring[VBNV_BLOCK_SIZE * 2 + 1];
char * const argv[] = {
- MOSYS_PATH, "nvram", "vboot", "write", hexstring, NULL
+ InAndroid() ? MOSYS_ANDROID_PATH : MOSYS_CROS_PATH,
+ "nvram", "vboot", "write", hexstring, NULL
};
int i;