Skip to content

Commit

Permalink
Merge tag 'android-6.0.0_r26' into cm-13.0
Browse files Browse the repository at this point in the history
Android 6.0.0 release 26

Change-Id: I93d1e3767cbacab2b18cff360065c91b9eaf1d96
  • Loading branch information
rmcc committed Nov 5, 2015
2 parents 22fffcc + f7f765f commit 31756a1
Show file tree
Hide file tree
Showing 23 changed files with 587 additions and 142 deletions.
56 changes: 44 additions & 12 deletions fastboot/fastboot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,17 +282,22 @@ void usage(void)
" flashall flash boot, system, vendor and if found,\n"
" recovery\n"
" flash <partition> [ <filename> ] write a file to a flash partition\n"
" flashing lock locks the device. Prevents flashing"
" flashing lock locks the device. Prevents flashing\n"
" partitions\n"
" flashing unlock unlocks the device. Allows user to"
" flash any partition except the ones"
" flashing unlock unlocks the device. Allows user to\n"
" flash any partition except the ones\n"
" that are related to bootloader\n"
" flashing lock_critical Prevents flashing bootloader related"
" flashing lock_critical Prevents flashing bootloader related\n"
" partitions\n"
" flashing unlock_critical Enables flashing bootloader related"
" flashing unlock_critical Enables flashing bootloader related\n"
" partitions\n"
" flashing get_unlock_ability Queries bootloader to see if the"
" flashing get_unlock_ability Queries bootloader to see if the\n"
" device is unlocked\n"
" flashing get_unlock_bootloader_nonce Queries the bootloader to get the\n"
" unlock nonce\n"
" flashing unlock_bootloader <request> Issue unlock bootloader using request\n"
" flashing lock_bootloader Locks the bootloader to prevent\n"
" bootloader version rollback\n"
" erase <partition> erase a flash partition\n"
" format[:[<fs type>][:[<size>]] <partition> format a flash partition.\n"
" Can override the fs type and/or\n"
Expand Down Expand Up @@ -834,6 +839,27 @@ void do_flashall(usb_handle *usb, int erase_first)
#define skip(n) do { argc -= (n); argv += (n); } while (0)
#define require(n) do { if (argc < (n)) {usage(); exit(1);}} while (0)

int do_bypass_unlock_command(int argc, char **argv)
{
unsigned sz;
void *data;

if (argc <= 2) return 0;
skip(2);

/*
* Process unlock_bootloader, we have to load the message file
* and send that to the remote device.
*/
require(1);
data = load_file(*argv, &sz);
if (data == 0) die("could not load '%s': %s", *argv, strerror(errno));
fb_queue_download("unlock_message", data, sz);
fb_queue_command("flashing unlock_bootloader", "unlocking bootloader");
skip(1);
return 0;
}

int do_oem_command(int argc, char **argv)
{
char command[256];
Expand Down Expand Up @@ -1233,12 +1259,18 @@ int main(int argc, char **argv)
wants_reboot = 1;
} else if(!strcmp(*argv, "oem")) {
argc = do_oem_command(argc, argv);
} else if(!strcmp(*argv, "flashing") && argc == 2) {
if(!strcmp(*(argv+1), "unlock") || !strcmp(*(argv+1), "lock")
|| !strcmp(*(argv+1), "unlock_critical")
|| !strcmp(*(argv+1), "lock_critical")
|| !strcmp(*(argv+1), "get_unlock_ability")) {
argc = do_oem_command(argc, argv);
} else if(!strcmp(*argv, "flashing")) {
if (argc == 2 && (!strcmp(*(argv+1), "unlock") ||
!strcmp(*(argv+1), "lock") ||
!strcmp(*(argv+1), "unlock_critical") ||
!strcmp(*(argv+1), "lock_critical") ||
!strcmp(*(argv+1), "get_unlock_ability") ||
!strcmp(*(argv+1), "get_unlock_bootloader_nonce") ||
!strcmp(*(argv+1), "lock_bootloader"))) {
argc = do_oem_command(argc, argv);
} else
if (argc == 3 && !strcmp(*(argv+1), "unlock_bootloader")) {
argc = do_bypass_unlock_command(argc, argv);
} else {
usage();
return 1;
Expand Down
70 changes: 58 additions & 12 deletions fs_mgr/fs_mgr_verity.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@

#define VERITY_METADATA_SIZE 32768
#define VERITY_TABLE_RSA_KEY "/verity_key"
#define VERITY_TABLE_HASH_IDX 8
#define VERITY_TABLE_SALT_IDX 9

#define METADATA_MAGIC 0x01564c54
#define METADATA_TAG_MAX_LENGTH 63
Expand Down Expand Up @@ -141,6 +143,33 @@ static int verify_table(char *signature, char *table, int table_length)
return retval;
}

static int invalidate_table(char *table, int table_length)
{
int n = 0;
int idx = 0;
int cleared = 0;

while (n < table_length) {
if (table[n++] == ' ') {
++idx;
}

if (idx != VERITY_TABLE_HASH_IDX && idx != VERITY_TABLE_SALT_IDX) {
continue;
}

while (n < table_length && table[n] != ' ') {
table[n++] = '0';
}

if (++cleared == 2) {
return 0;
}
}

return -1;
}

static int squashfs_get_target_device_size(char *blk_device, uint64_t *device_size)
{
struct squashfs_info sq_info;
Expand Down Expand Up @@ -859,6 +888,7 @@ int fs_mgr_load_verity_state(int *mode)
int fs_mgr_update_verity_state(fs_mgr_verity_state_callback callback)
{
_Alignas(struct dm_ioctl) char buffer[DM_BUF_SIZE];
bool use_state = true;
char fstab_filename[PROPERTY_VALUE_MAX + sizeof(FSTAB_PREFIX)];
char *mount_point;
char propbuf[PROPERTY_VALUE_MAX];
Expand All @@ -875,7 +905,10 @@ int fs_mgr_update_verity_state(fs_mgr_verity_state_callback callback)
property_get("ro.boot.veritymode", propbuf, "");

if (*propbuf != '\0') {
return 0; /* state is kept by the bootloader */
if (fs_mgr_load_verity_state(&mode) == -1) {
return -1;
}
use_state = false; /* state is kept by the bootloader */
}

fd = TEMP_FAILURE_RETRY(open("/dev/device-mapper", O_RDWR | O_CLOEXEC));
Expand All @@ -900,9 +933,11 @@ int fs_mgr_update_verity_state(fs_mgr_verity_state_callback callback)
continue;
}

if (get_verity_state_offset(&fstab->recs[i], &offset) < 0 ||
read_verity_state(fstab->recs[i].verity_loc, offset, &mode) < 0) {
continue;
if (use_state) {
if (get_verity_state_offset(&fstab->recs[i], &offset) < 0 ||
read_verity_state(fstab->recs[i].verity_loc, offset, &mode) < 0) {
continue;
}
}

mount_point = basename(fstab->recs[i].mount_point);
Expand All @@ -916,7 +951,7 @@ int fs_mgr_update_verity_state(fs_mgr_verity_state_callback callback)

status = &buffer[io->data_start + sizeof(struct dm_target_spec)];

if (*status == 'C') {
if (use_state && *status == 'C') {
if (write_verity_state(fstab->recs[i].verity_loc, offset,
VERITY_MODE_LOGGING) < 0) {
continue;
Expand Down Expand Up @@ -951,6 +986,7 @@ int fs_mgr_setup_verity(struct fstab_rec *fstab) {
char *verity_blk_name = 0;
char *verity_table = 0;
char *verity_table_signature = 0;
int verity_table_length = 0;
uint64_t device_size = 0;

_Alignas(struct dm_ioctl) char buffer[DM_BUF_SIZE];
Expand All @@ -977,6 +1013,7 @@ int fs_mgr_setup_verity(struct fstab_rec *fstab) {
}

retval = FS_MGR_SETUP_VERITY_FAIL;
verity_table_length = strlen(verity_table);

// get the device mapper fd
if ((fd = open("/dev/device-mapper", O_RDWR)) < 0) {
Expand All @@ -996,13 +1033,6 @@ int fs_mgr_setup_verity(struct fstab_rec *fstab) {
goto out;
}

// verify the signature on the table
if (verify_table(verity_table_signature,
verity_table,
strlen(verity_table)) < 0) {
goto out;
}

if (load_verity_state(fstab, &mode) < 0) {
/* if accessing or updating the state failed, switch to the default
* safe mode. This makes sure the device won't end up in an endless
Expand All @@ -1011,6 +1041,22 @@ int fs_mgr_setup_verity(struct fstab_rec *fstab) {
mode = VERITY_MODE_EIO;
}

// verify the signature on the table
if (verify_table(verity_table_signature,
verity_table,
verity_table_length) < 0) {
if (mode == VERITY_MODE_LOGGING) {
// the user has been warned, allow mounting without dm-verity
retval = FS_MGR_SETUP_VERITY_SUCCESS;
goto out;
}

// invalidate root hash and salt to trigger device-specific recovery
if (invalidate_table(verity_table, verity_table_length) < 0) {
goto out;
}
}

INFO("Enabling dm-verity for %s (mode %d)\n", mount_point, mode);

// load the verity mapping table
Expand Down
14 changes: 12 additions & 2 deletions healthd/BatteryMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ bool BatteryMonitor::update(void) {
props.chargerDockAcOnline = false;
props.batteryStatus = BATTERY_STATUS_UNKNOWN;
props.batteryHealth = BATTERY_HEALTH_UNKNOWN;
props.maxChargingCurrent = 0;
props.dockBatteryStatus = BATTERY_STATUS_UNKNOWN;
props.dockBatteryHealth = BATTERY_HEALTH_UNKNOWN;

Expand Down Expand Up @@ -297,6 +298,15 @@ bool BatteryMonitor::update(void) {
KLOG_WARNING(LOG_TAG, "%s: Unknown power supply type\n",
name);
}
path.clear();
path.appendFormat("%s/%s/current_max", POWER_SUPPLY_SYSFS_PATH,
name);
if (access(path.string(), R_OK) == 0) {
int maxChargingCurrent = getIntField(path);
if (props.maxChargingCurrent < maxChargingCurrent) {
props.maxChargingCurrent = maxChargingCurrent;
}
}
}
}
}
Expand Down Expand Up @@ -516,9 +526,9 @@ void BatteryMonitor::dumpState(int fd) {
int v;
char vs[128];

snprintf(vs, sizeof(vs), "ac: %d usb: %d wireless: %d dock-ac: %d\n",
snprintf(vs, sizeof(vs), "ac: %d usb: %d wireless: %d dock-ac: %d current_max: %d\n",
props.chargerAcOnline, props.chargerUsbOnline,
props.chargerWirelessOnline, props.chargerDockAcOnline);
props.chargerWirelessOnline, props.chargerDockAcOnline, props.maxChargingCurrent);
write(fd, vs, strlen(vs));
snprintf(vs, sizeof(vs), "status: %d health: %d present: %d\n",
props.batteryStatus, props.batteryHealth, props.batteryPresent);
Expand Down
27 changes: 20 additions & 7 deletions init/builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,9 +816,9 @@ int do_load_persist_props(int nargs, char **args) {
return -1;
}

int do_load_all_props(int nargs, char **args) {
int do_load_system_props(int nargs, char **args) {
if (nargs == 1) {
load_all_props();
load_system_props();
return 0;
}
return -1;
Expand Down Expand Up @@ -846,18 +846,31 @@ static int do_installkeys_ensure_dir_exists(const char* dir)
return 0;
}

static bool is_file_crypto() {
char prop_value[PROP_VALUE_MAX] = {0};
property_get("ro.crypto.type", prop_value);
return strcmp(prop_value, "file") == 0;
}

int do_installkey(int nargs, char **args)
{
if (nargs != 2) {
return -1;
}

char prop_value[PROP_VALUE_MAX] = {0};
property_get("ro.crypto.type", prop_value);
if (strcmp(prop_value, "file")) {
if (!is_file_crypto()) {
return 0;
}

return e4crypt_create_device_key(args[1],
do_installkeys_ensure_dir_exists);
}

int do_setusercryptopolicies(int nargs, char **args)
{
if (nargs != 2) {
return -1;
}
if (!is_file_crypto()) {
return 0;
}
return e4crypt_set_user_crypto_policies(args[1]);
}
50 changes: 25 additions & 25 deletions init/init_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ static int lookup_keyword(const char *s)
case 'l':
if (!strcmp(s, "oglevel")) return K_loglevel;
if (!strcmp(s, "oad_persist_props")) return K_load_persist_props;
if (!strcmp(s, "oad_all_props")) return K_load_all_props;
if (!strcmp(s, "oad_system_props")) return K_load_system_props;
break;
case 'm':
if (!strcmp(s, "kdir")) return K_mkdir;
Expand Down Expand Up @@ -188,6 +188,7 @@ static int lookup_keyword(const char *s)
if (!strcmp(s, "etenv")) return K_setenv;
if (!strcmp(s, "etprop")) return K_setprop;
if (!strcmp(s, "etrlimit")) return K_setrlimit;
if (!strcmp(s, "etusercryptopolicies")) return K_setusercryptopolicies;
if (!strcmp(s, "ocket")) return K_socket;
if (!strcmp(s, "tart")) return K_start;
if (!strcmp(s, "top")) return K_stop;
Expand Down Expand Up @@ -573,7 +574,7 @@ void queue_property_triggers(const char *name, const char *value)

list_for_each(node, &action_list) {
act = node_to_item(node, struct action, alist);
match = !name;
match = !name;
list_for_each(node2, &act->triggers) {
cur_trigger = node_to_item(node2, struct trigger, nlist);
if (!strncmp(cur_trigger->name, "property:", strlen("property:"))) {
Expand All @@ -587,29 +588,28 @@ void queue_property_triggers(const char *name, const char *value)
match = true;
continue;
}
} else {
const char* equals = strchr(test, '=');
if (equals) {
char prop_name[PROP_NAME_MAX + 1];
char value[PROP_VALUE_MAX];
int length = equals - test;
if (length <= PROP_NAME_MAX) {
int ret;
memcpy(prop_name, test, length);
prop_name[length] = 0;

/* does the property exist, and match the trigger value? */
ret = property_get(prop_name, value);
if (ret > 0 && (!strcmp(equals + 1, value) ||
!strcmp(equals + 1, "*"))) {
continue;
}
}
}
}
}
match = false;
break;
}
const char* equals = strchr(test, '=');
if (equals) {
char prop_name[PROP_NAME_MAX + 1];
char value[PROP_VALUE_MAX];
int length = equals - test;
if (length <= PROP_NAME_MAX) {
int ret;
memcpy(prop_name, test, length);
prop_name[length] = 0;

/* does the property exist, and match the trigger value? */
ret = property_get(prop_name, value);
if (ret > 0 && (!strcmp(equals + 1, value) ||
!strcmp(equals + 1, "*"))) {
continue;
}
}
}
}
match = false;
break;
}
if (match) {
action_add_queue_tail(act);
Expand Down
Loading

0 comments on commit 31756a1

Please sign in to comment.