diff options
-rw-r--r-- | adb/usb_vendors.c | 7 | ||||
-rw-r--r-- | fastboot/usb_linux.c | 181 | ||||
-rw-r--r-- | fs_mgr/fs_mgr.c | 94 | ||||
-rw-r--r-- | init/devices.c | 11 | ||||
-rw-r--r-- | init/init.c | 5 | ||||
-rw-r--r-- | init/init.h | 1 | ||||
-rw-r--r-- | init/init_parser.c | 4 | ||||
-rw-r--r-- | init/property_service.c | 25 | ||||
-rw-r--r-- | init/readme.txt | 5 | ||||
-rw-r--r-- | init/util.c | 59 | ||||
-rw-r--r-- | init/util.h | 2 | ||||
-rw-r--r-- | libcorkscrew/Android.mk | 4 | ||||
-rwxr-xr-x | libcorkscrew/arch-x86/backtrace-x86.c | 29 | ||||
-rw-r--r-- | libcutils/ashmem-dev.c | 2 | ||||
-rw-r--r-- | libsparse/output_file.c | 9 | ||||
-rw-r--r-- | mkbootimg/bootimg.h | 7 | ||||
-rw-r--r-- | mkbootimg/mkbootimg.c | 13 | ||||
-rw-r--r-- | rootdir/init.rc | 5 |
18 files changed, 246 insertions, 217 deletions
diff --git a/adb/usb_vendors.c b/adb/usb_vendors.c index 68bb23284..19b302274 100644 --- a/adb/usb_vendors.c +++ b/adb/usb_vendors.c @@ -155,7 +155,10 @@ #define VENDOR_ID_QISDA 0x1D45 // ECS's USB Vendor ID #define VENDOR_ID_ECS 0x03fc - +// MSI's USB Vendor ID +#define VENDOR_ID_MSI 0x0DB0 +// Wacom's USB Vendor ID +#define VENDOR_ID_WACOM 0x0531 /** built-in vendor list */ int builtInVendorIds[] = { @@ -219,6 +222,8 @@ int builtInVendorIds[] = { VENDOR_ID_NOOK, VENDOR_ID_QISDA, VENDOR_ID_ECS, + VENDOR_ID_MSI, + VENDOR_ID_WACOM, }; #define BUILT_IN_VENDOR_COUNT (sizeof(builtInVendorIds)/sizeof(builtInVendorIds[0])) diff --git a/fastboot/usb_linux.c b/fastboot/usb_linux.c index b7a9ca33a..9153c8d6c 100644 --- a/fastboot/usb_linux.c +++ b/fastboot/usb_linux.c @@ -75,10 +75,18 @@ struct usb_handle unsigned char ep_out; }; +/* True if name isn't a valid name for a USB device in /sys/bus/usb/devices. + * Device names are made up of numbers, dots, and dashes, e.g., '7-1.5'. + * We reject interfaces (e.g., '7-1.5:1.0') and host controllers (e.g. 'usb1'). + * The name must also start with a digit, to disallow '.' and '..' + */ static inline int badname(const char *name) { - while(*name) { - if(!isdigit(*name++)) return 1; + if (!isdigit(*name)) + return 1; + while(*++name) { + if(!isdigit(*name) && *name != '.' && *name != '-') + return 1; } return 0; } @@ -95,7 +103,8 @@ static int check(void *_desc, int len, unsigned type, int size) return 0; } -static int filter_usb_device(int fd, char *ptr, int len, int writable, +static int filter_usb_device(int fd, char* sysfs_name, + char *ptr, int len, int writable, ifc_match_func callback, int *ept_in_id, int *ept_out_id, int *ifc_id) { @@ -131,69 +140,35 @@ static int filter_usb_device(int fd, char *ptr, int len, int writable, info.dev_protocol = dev->bDeviceProtocol; info.writable = writable; - // read device serial number (if there is one) - info.serial_number[0] = 0; - if (dev->iSerialNumber) { - struct usbdevfs_ctrltransfer ctrl; - // Keep it short enough because some bootloaders are borked if the URB len is > 255 - // 128 is too big by 1. - __u16 buffer[127]; - - memset(buffer, 0, sizeof(buffer)); - - ctrl.bRequestType = USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_DEVICE; - ctrl.bRequest = USB_REQ_GET_DESCRIPTOR; - ctrl.wValue = (USB_DT_STRING << 8) | dev->iSerialNumber; - //language ID (en-us) for serial number string - ctrl.wIndex = 0x0409; - ctrl.wLength = sizeof(buffer); - ctrl.data = buffer; - ctrl.timeout = 50; - - result = ioctl(fd, USBDEVFS_CONTROL, &ctrl); - if (result > 0) { - int i; - // skip first word, and copy the rest to the serial string, changing shorts to bytes. - result /= 2; - for (i = 1; i < result; i++) - info.serial_number[i - 1] = buffer[i]; - info.serial_number[i - 1] = 0; - } - } + snprintf(info.device_path, sizeof(info.device_path), "usb:%s", sysfs_name); - /* We need to get a path that represents a particular port on a particular - * hub. We are passed an fd that was obtained by opening an entry under - * /dev/bus/usb. Unfortunately, the names of those entries change each - * time devices are plugged and unplugged. So how to get a repeatable - * path? udevadm provided the inspiration. We can get the major and - * minor of the device file, read the symlink that can be found here: - * /sys/dev/char/<major>:<minor> - * and then use the last element of that path. As a concrete example, I - * have an Android device at /dev/bus/usb/001/027 so working with bash: - * $ ls -l /dev/bus/usb/001/027 - * crw-rw-r-- 1 root plugdev 189, 26 Apr 9 11:03 /dev/bus/usb/001/027 - * $ ls -l /sys/dev/char/189:26 - * lrwxrwxrwx 1 root root 0 Apr 9 11:03 /sys/dev/char/189:26 -> - * ../../devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4.2/1-4.2.3 - * So our device_path would be 1-4.2.3 which says my device is connected - * to port 3 of a hub on port 2 of a hub on port 4 of bus 1 (per - * http://www.linux-usb.org/FAQ.html). + /* Read device serial number (if there is one). + * We read the serial number from sysfs, since it's faster and more + * reliable than issuing a control pipe read, and also won't + * cause problems for devices which don't like getting descriptor + * requests while they're in the middle of flashing. */ - info.device_path[0] = '\0'; - result = fstat(fd, &st); - if (!result && S_ISCHR(st.st_mode)) { - char cdev[128]; - char link[256]; - char *slash; - ssize_t link_len; - snprintf(cdev, sizeof(cdev), "/sys/dev/char/%d:%d", - major(st.st_rdev), minor(st.st_rdev)); - link_len = readlink(cdev, link, sizeof(link) - 1); - if (link_len > 0) { - link[link_len] = '\0'; - slash = strrchr(link, '/'); - if (slash) - snprintf(info.device_path, sizeof(info.device_path), "usb:%s", slash+1); + info.serial_number[0] = '\0'; + if (dev->iSerialNumber) { + char path[80]; + int fd; + + snprintf(path, sizeof(path), + "/sys/bus/usb/devices/%s/serial", sysfs_name); + path[sizeof(path) - 1] = '\0'; + + fd = open(path, O_RDONLY); + if (fd >= 0) { + int chars_read = read(fd, info.serial_number, + sizeof(info.serial_number) - 1); + close(fd); + + if (chars_read <= 0) + info.serial_number[0] = '\0'; + else if (info.serial_number[chars_read - 1] == '\n') { + // strip trailing newline + info.serial_number[chars_read - 1] = '\0'; + } } } @@ -241,14 +216,73 @@ static int filter_usb_device(int fd, char *ptr, int len, int writable, return -1; } +static int read_sysfs_string(const char *sysfs_name, const char *sysfs_node, + char* buf, int bufsize) +{ + char path[80]; + int fd, n; + + snprintf(path, sizeof(path), + "/sys/bus/usb/devices/%s/%s", sysfs_name, sysfs_node); + path[sizeof(path) - 1] = '\0'; + + fd = open(path, O_RDONLY); + if (fd < 0) + return -1; + + n = read(fd, buf, bufsize - 1); + close(fd); + + if (n < 0) + return -1; + + buf[n] = '\0'; + + return n; +} + +static int read_sysfs_number(const char *sysfs_name, const char *sysfs_node) +{ + char buf[16]; + int value; + + if (read_sysfs_string(sysfs_name, sysfs_node, buf, sizeof(buf)) < 0) + return -1; + + if (sscanf(buf, "%d", &value) != 1) + return -1; + + return value; +} + +/* Given the name of a USB device in sysfs, get the name for the same + * device in devfs. Returns 0 for success, -1 for failure. + */ +static int convert_to_devfs_name(const char* sysfs_name, + char* devname, int devname_size) +{ + int busnum, devnum; + + busnum = read_sysfs_number(sysfs_name, "busnum"); + if (busnum < 0) + return -1; + + devnum = read_sysfs_number(sysfs_name, "devnum"); + if (devnum < 0) + return -1; + + snprintf(devname, devname_size, "/dev/bus/usb/%03d/%03d", busnum, devnum); + return 0; +} + static usb_handle *find_usb_device(const char *base, ifc_match_func callback) { usb_handle *usb = 0; - char busname[64], devname[64]; + char devname[64]; char desc[1024]; int n, in, out, ifc; - DIR *busdir, *devdir; + DIR *busdir; struct dirent *de; int fd; int writable; @@ -259,15 +293,7 @@ static usb_handle *find_usb_device(const char *base, ifc_match_func callback) while((de = readdir(busdir)) && (usb == 0)) { if(badname(de->d_name)) continue; - sprintf(busname, "%s/%s", base, de->d_name); - devdir = opendir(busname); - if(devdir == 0) continue; - -// DBG("[ scanning %s ]\n", busname); - while((de = readdir(devdir)) && (usb == 0)) { - - if(badname(de->d_name)) continue; - sprintf(devname, "%s/%s", busname, de->d_name); + if(!convert_to_devfs_name(de->d_name, devname, sizeof(devname))) { // DBG("[ scanning %s ]\n", devname); writable = 1; @@ -282,7 +308,7 @@ static usb_handle *find_usb_device(const char *base, ifc_match_func callback) n = read(fd, desc, sizeof(desc)); - if(filter_usb_device(fd, desc, n, writable, callback, + if(filter_usb_device(fd, de->d_name, desc, n, writable, callback, &in, &out, &ifc) == 0) { usb = calloc(1, sizeof(usb_handle)); strcpy(usb->fname, devname); @@ -301,7 +327,6 @@ static usb_handle *find_usb_device(const char *base, ifc_match_func callback) close(fd); } } - closedir(devdir); } closedir(busdir); @@ -431,5 +456,5 @@ int usb_close(usb_handle *h) usb_handle *usb_open(ifc_match_func callback) { - return find_usb_device("/dev/bus/usb", callback); + return find_usb_device("/sys/bus/usb/devices", callback); } diff --git a/fs_mgr/fs_mgr.c b/fs_mgr/fs_mgr.c index 82c579821..9a84a4ec5 100644 --- a/fs_mgr/fs_mgr.c +++ b/fs_mgr/fs_mgr.c @@ -235,74 +235,16 @@ out: return f; } -/* Read a line of text till the next newline character. - * If no newline is found before the buffer is full, continue reading till a new line is seen, - * then return an empty buffer. This effectively ignores lines that are too long. - * On EOF, return null. - */ -static char *fs_getline(char *buf, int size, FILE *file) -{ - int cnt = 0; - int eof = 0; - int eol = 0; - int c; - - if (size < 1) { - return NULL; - } - - while (cnt < (size - 1)) { - c = getc(file); - if (c == EOF) { - eof = 1; - break; - } - - *(buf + cnt) = c; - cnt++; - - if (c == '\n') { - eol = 1; - break; - } - } - - /* Null terminate what we've read */ - *(buf + cnt) = '\0'; - - if (eof) { - if (cnt) { - return buf; - } else { - return NULL; - } - } else if (eol) { - return buf; - } else { - /* The line is too long. Read till a newline or EOF. - * If EOF, return null, if newline, return an empty buffer. - */ - while(1) { - c = getc(file); - if (c == EOF) { - return NULL; - } else if (c == '\n') { - *buf = '\0'; - return buf; - } - } - } -} - struct fstab *fs_mgr_read_fstab(const char *fstab_path) { FILE *fstab_file; int cnt, entries; - int len; - char line[256]; + ssize_t len; + size_t alloc_len = 0; + char *line = NULL; const char *delim = " \t"; char *save_ptr, *p; - struct fstab *fstab; + struct fstab *fstab = NULL; struct fstab_rec *recs; struct fs_mgr_flag_values flag_vals; #define FS_OPTIONS_LEN 1024 @@ -315,9 +257,8 @@ struct fstab *fs_mgr_read_fstab(const char *fstab_path) } entries = 0; - while (fs_getline(line, sizeof(line), fstab_file)) { + while ((len = getline(&line, &alloc_len, fstab_file)) != -1) { /* if the last character is a newline, shorten the string by 1 byte */ - len = strlen(line); if (line[len - 1] == '\n') { line[len - 1] = '\0'; } @@ -334,7 +275,7 @@ struct fstab *fs_mgr_read_fstab(const char *fstab_path) if (!entries) { ERROR("No entries found in fstab\n"); - return 0; + goto err; } /* Allocate and init the fstab structure */ @@ -346,9 +287,8 @@ struct fstab *fs_mgr_read_fstab(const char *fstab_path) fseek(fstab_file, 0, SEEK_SET); cnt = 0; - while (fs_getline(line, sizeof(line), fstab_file)) { + while ((len = getline(&line, &alloc_len, fstab_file)) != -1) { /* if the last character is a newline, shorten the string by 1 byte */ - len = strlen(line); if (line[len - 1] == '\n') { line[len - 1] = '\0'; } @@ -373,25 +313,25 @@ struct fstab *fs_mgr_read_fstab(const char *fstab_path) if (!(p = strtok_r(line, delim, &save_ptr))) { ERROR("Error parsing mount source\n"); - return 0; + goto err; } fstab->recs[cnt].blk_device = strdup(p); if (!(p = strtok_r(NULL, delim, &save_ptr))) { ERROR("Error parsing mount_point\n"); - return 0; + goto err; } fstab->recs[cnt].mount_point = strdup(p); if (!(p = strtok_r(NULL, delim, &save_ptr))) { ERROR("Error parsing fs_type\n"); - return 0; + goto err; } fstab->recs[cnt].fs_type = strdup(p); if (!(p = strtok_r(NULL, delim, &save_ptr))) { ERROR("Error parsing mount_flags\n"); - return 0; + goto err; } tmp_fs_options[0] = '\0'; fstab->recs[cnt].flags = parse_flags(p, mount_flags, NULL, @@ -406,7 +346,7 @@ struct fstab *fs_mgr_read_fstab(const char *fstab_path) if (!(p = strtok_r(NULL, delim, &save_ptr))) { ERROR("Error parsing fs_mgr_options\n"); - return 0; + goto err; } fstab->recs[cnt].fs_mgr_flags = parse_flags(p, fs_mgr_flags, &flag_vals, NULL, 0); @@ -419,8 +359,15 @@ struct fstab *fs_mgr_read_fstab(const char *fstab_path) cnt++; } fclose(fstab_file); - + free(line); return fstab; + +err: + fclose(fstab_file); + free(line); + if (fstab) + fs_mgr_free_fstab(fstab); + return NULL; } void fs_mgr_free_fstab(struct fstab *fstab) @@ -435,7 +382,6 @@ void fs_mgr_free_fstab(struct fstab *fstab) free(fstab->recs[i].fs_options); free(fstab->recs[i].key_loc); free(fstab->recs[i].label); - i++; } /* Free the fstab_recs array created by calloc(3) */ diff --git a/init/devices.c b/init/devices.c index 189364201..af88c5f09 100644 --- a/init/devices.c +++ b/init/devices.c @@ -33,6 +33,7 @@ #include <selinux/selinux.h> #include <selinux/label.h> #include <selinux/android.h> +#include <selinux/avc.h> #include <private/android_filesystem_config.h> #include <sys/time.h> @@ -830,6 +831,15 @@ void handle_device_fd() struct uevent uevent; parse_event(msg, &uevent); + if (sehandle && selinux_status_updated() > 0) { + struct selabel_handle *sehandle2; + sehandle2 = selinux_android_file_context_handle(); + if (sehandle2) { + selabel_close(sehandle); + sehandle = sehandle2; + } + } + handle_device_event(&uevent); handle_firmware_event(&uevent); } @@ -896,6 +906,7 @@ void device_init(void) sehandle = NULL; if (is_selinux_enabled() > 0) { sehandle = selinux_android_file_context_handle(); + selinux_status_open(true); } /* is 256K enough? udev uses 16MB! */ diff --git a/init/init.c b/init/init.c index 94a201196..feac8ad8e 100644 --- a/init/init.c +++ b/init/init.c @@ -250,14 +250,12 @@ void service_start(struct service *svc, const char *dynamic_args) for (ei = svc->envvars; ei; ei = ei->next) add_environment(ei->name, ei->value); - setsockcreatecon(scon); - for (si = svc->sockets; si; si = si->next) { int socket_type = ( !strcmp(si->type, "stream") ? SOCK_STREAM : (!strcmp(si->type, "dgram") ? SOCK_DGRAM : SOCK_SEQPACKET)); int s = create_socket(si->name, socket_type, - si->perm, si->uid, si->gid); + si->perm, si->uid, si->gid, si->socketcon ?: scon); if (s >= 0) { publish_socket(si->name, s); } @@ -265,7 +263,6 @@ void service_start(struct service *svc, const char *dynamic_args) freecon(scon); scon = NULL; - setsockcreatecon(NULL); if (svc->ioprio_class != IoSchedClass_NONE) { if (android_set_ioprio(getpid(), svc->ioprio_class, svc->ioprio_pri)) { diff --git a/init/init.h b/init/init.h index aa6a4ab02..3928d52b4 100644 --- a/init/init.h +++ b/init/init.h @@ -55,6 +55,7 @@ struct socketinfo { uid_t uid; gid_t gid; int perm; + const char *socketcon; }; struct svcenvinfo { diff --git a/init/init_parser.c b/init/init_parser.c index 776c699aa..7c2fa8c80 100644 --- a/init/init_parser.c +++ b/init/init_parser.c @@ -771,7 +771,7 @@ static void parse_line_service(struct parse_state *state, int nargs, char **args svc->envvars = ei; break; } - case K_socket: {/* name type perm [ uid gid ] */ + case K_socket: {/* name type perm [ uid gid context ] */ struct socketinfo *si; if (nargs < 4) { parse_error(state, "socket option requires name, type, perm arguments\n"); @@ -794,6 +794,8 @@ static void parse_line_service(struct parse_state *state, int nargs, char **args si->uid = decode_uid(args[4]); if (nargs > 5) si->gid = decode_uid(args[5]); + if (nargs > 6) + si->socketcon = args[6]; si->next = svc->sockets; svc->sockets = si; break; diff --git a/init/property_service.c b/init/property_service.c index 9ac278169..c3707691f 100644 --- a/init/property_service.c +++ b/init/property_service.c @@ -81,6 +81,7 @@ struct { { "sys.powerctl", AID_SHELL, 0 }, { "service.", AID_SYSTEM, 0 }, { "wlan.", AID_SYSTEM, 0 }, + { "gps.", AID_GPS, 0 }, { "bluetooth.", AID_BLUETOOTH, 0 }, { "dhcp.", AID_SYSTEM, 0 }, { "dhcp.", AID_DHCP, 0 }, @@ -92,6 +93,7 @@ struct { { "persist.sys.", AID_SYSTEM, 0 }, { "persist.service.", AID_SYSTEM, 0 }, { "persist.security.", AID_SYSTEM, 0 }, + { "persist.gps.", AID_GPS, 0 }, { "persist.service.bdroid.", AID_BLUETOOTH, 0 }, { "selinux." , AID_SYSTEM, 0 }, { NULL, 0, 0 } @@ -437,10 +439,13 @@ void get_property_workspace(int *fd, int *sz) *sz = pa_workspace.size; } -static void load_properties(char *data) +static void load_properties(char *data, char *prefix) { char *key, *value, *eol, *sol, *tmp; + size_t plen; + if (prefix) + plen = strlen(prefix); sol = data; while((eol = strchr(sol, '\n'))) { key = sol; @@ -456,6 +461,9 @@ static void load_properties(char *data) tmp = value - 2; while((tmp > key) && isspace(*tmp)) *tmp-- = 0; + if (prefix && strncmp(key, prefix, plen)) + continue; + while(isspace(*value)) value++; tmp = eol - 2; while((tmp > value) && isspace(*tmp)) *tmp-- = 0; @@ -464,7 +472,7 @@ static void load_properties(char *data) } } -static void load_properties_from_file(const char *fn) +static void load_properties_from_file(const char *fn, char *prefix) { char *data; unsigned sz; @@ -472,7 +480,7 @@ static void load_properties_from_file(const char *fn) data = read_file(fn, &sz); if(data != 0) { - load_properties(data); + load_properties(data, prefix); free(data); } } @@ -545,7 +553,7 @@ void property_init(void) void property_load_boot_defaults(void) { - load_properties_from_file(PROP_PATH_RAMDISK_DEFAULT); + load_properties_from_file(PROP_PATH_RAMDISK_DEFAULT, NULL); } int properties_inited(void) @@ -560,7 +568,7 @@ static void load_override_properties() { ret = property_get("ro.debuggable", debuggable); if (ret && (strcmp(debuggable, "1") == 0)) { - load_properties_from_file(PROP_PATH_LOCAL_OVERRIDE); + load_properties_from_file(PROP_PATH_LOCAL_OVERRIDE, NULL); } #endif /* ALLOW_LOCAL_PROP_OVERRIDE */ } @@ -582,13 +590,14 @@ void start_property_service(void) { int fd; - load_properties_from_file(PROP_PATH_SYSTEM_BUILD); - load_properties_from_file(PROP_PATH_SYSTEM_DEFAULT); + load_properties_from_file(PROP_PATH_SYSTEM_BUILD, NULL); + load_properties_from_file(PROP_PATH_SYSTEM_DEFAULT, NULL); + load_properties_from_file(PROP_PATH_FACTORY, "ro."); load_override_properties(); /* Read persistent properties after all default values have been loaded. */ load_persistent_properties(); - fd = create_socket(PROP_SERVICE_NAME, SOCK_STREAM, 0666, 0, 0); + fd = create_socket(PROP_SERVICE_NAME, SOCK_STREAM, 0666, 0, 0, NULL); if(fd < 0) return; fcntl(fd, F_SETFD, FD_CLOEXEC); fcntl(fd, F_SETFL, O_NONBLOCK); diff --git a/init/readme.txt b/init/readme.txt index 7a5997d26..1e8c3920d 100644 --- a/init/readme.txt +++ b/init/readme.txt @@ -70,10 +70,13 @@ disabled setenv <name> <value> Set the environment variable <name> to <value> in the launched process. -socket <name> <type> <perm> [ <user> [ <group> ] ] +socket <name> <type> <perm> [ <user> [ <group> [ <context> ] ] ] Create a unix domain socket named /dev/socket/<name> and pass its fd to the launched process. <type> must be "dgram", "stream" or "seqpacket". User and group default to 0. + Context is the SELinux security context for the socket. + It defaults to the service security context, as specified by seclabel or + computed based on the service executable file security context. user <username> Change to username before exec'ing this service. diff --git a/init/util.c b/init/util.c index 1908b3a9a..9aaa77d47 100644 --- a/init/util.c +++ b/init/util.c @@ -84,11 +84,15 @@ unsigned int decode_uid(const char *s) * daemon. We communicate the file descriptor's value via the environment * variable ANDROID_SOCKET_ENV_PREFIX<name> ("ANDROID_SOCKET_foo"). */ -int create_socket(const char *name, int type, mode_t perm, uid_t uid, gid_t gid) +int create_socket(const char *name, int type, mode_t perm, uid_t uid, + gid_t gid, const char *socketcon) { struct sockaddr_un addr; int fd, ret; - char *secon; + char *filecon; + + if (socketcon) + setsockcreatecon(socketcon); fd = socket(PF_UNIX, type, 0); if (fd < 0) { @@ -96,6 +100,9 @@ int create_socket(const char *name, int type, mode_t perm, uid_t uid, gid_t gid) return -1; } + if (socketcon) + setsockcreatecon(NULL); + memset(&addr, 0 , sizeof(addr)); addr.sun_family = AF_UNIX; snprintf(addr.sun_path, sizeof(addr.sun_path), ANDROID_SOCKET_DIR"/%s", @@ -107,11 +114,11 @@ int create_socket(const char *name, int type, mode_t perm, uid_t uid, gid_t gid) goto out_close; } - secon = NULL; + filecon = NULL; if (sehandle) { - ret = selabel_lookup(sehandle, &secon, addr.sun_path, S_IFSOCK); + ret = selabel_lookup(sehandle, &filecon, addr.sun_path, S_IFSOCK); if (ret == 0) - setfscreatecon(secon); + setfscreatecon(filecon); } ret = bind(fd, (struct sockaddr *) &addr, sizeof (addr)); @@ -121,7 +128,7 @@ int create_socket(const char *name, int type, mode_t perm, uid_t uid, gid_t gid) } setfscreatecon(NULL); - freecon(secon); + freecon(filecon); chown(addr.sun_path, uid, gid); chmod(addr.sun_path, perm); @@ -398,7 +405,9 @@ void open_devnull_stdio(void) void get_hardware_name(char *hardware, unsigned int *revision) { - char data[1024]; + const char *cpuinfo = "/proc/cpuinfo"; + char *data = NULL; + size_t len = 0, limit = 1024; int fd, n; char *x, *hw, *rev; @@ -406,14 +415,32 @@ void get_hardware_name(char *hardware, unsigned int *revision) if (hardware[0]) return; - fd = open("/proc/cpuinfo", O_RDONLY); + fd = open(cpuinfo, O_RDONLY); if (fd < 0) return; - n = read(fd, data, 1023); - close(fd); - if (n < 0) return; + for (;;) { + x = realloc(data, limit); + if (!x) { + ERROR("Failed to allocate memory to read %s\n", cpuinfo); + goto done; + } + data = x; + + n = read(fd, data + len, limit - len); + if (n < 0) { + ERROR("Failed reading %s: %s (%d)\n", cpuinfo, strerror(errno), errno); + goto done; + } + len += n; - data[n] = 0; + if (len < limit) + break; + + /* We filled the buffer, so increase size and loop to read more */ + limit *= 2; + } + + data[len] = 0; hw = strstr(data, "\nHardware"); rev = strstr(data, "\nRevision"); @@ -438,18 +465,22 @@ void get_hardware_name(char *hardware, unsigned int *revision) *revision = strtoul(x + 2, 0, 16); } } + +done: + close(fd); + free(data); } void import_kernel_cmdline(int in_qemu, void (*import_kernel_nv)(char *name, int in_qemu)) { - char cmdline[1024]; + char cmdline[2048]; char *ptr; int fd; fd = open("/proc/cmdline", O_RDONLY); if (fd >= 0) { - int n = read(fd, cmdline, 1023); + int n = read(fd, cmdline, sizeof(cmdline) - 1); if (n < 0) n = 0; /* get rid of trailing newline, it happens */ diff --git a/init/util.h b/init/util.h index 6bca4e689..04b8129ba 100644 --- a/init/util.h +++ b/init/util.h @@ -26,7 +26,7 @@ static const char *coldboot_done = "/dev/.coldboot_done"; int mtd_name_to_number(const char *name); int create_socket(const char *name, int type, mode_t perm, - uid_t uid, gid_t gid); + uid_t uid, gid_t gid, const char *socketcon); void *read_file(const char *fn, unsigned *_sz); time_t gettime(void); unsigned int decode_uid(const char *s); diff --git a/libcorkscrew/Android.mk b/libcorkscrew/Android.mk index d62c2d5af..e27531766 100644 --- a/libcorkscrew/Android.mk +++ b/libcorkscrew/Android.mk @@ -51,7 +51,7 @@ endif LOCAL_SHARED_LIBRARIES += libdl libcutils liblog libgccdemangle -LOCAL_CFLAGS += -std=gnu99 -Werror +LOCAL_CFLAGS += -std=gnu99 -Werror -Wno-unused-parameter LOCAL_MODULE := libcorkscrew LOCAL_MODULE_TAGS := optional @@ -81,7 +81,7 @@ ifeq ($(HOST_OS),linux) LOCAL_SHARED_LIBRARIES += libgccdemangle # TODO: is this even needed on Linux? LOCAL_LDLIBS += -lrt endif -LOCAL_CFLAGS += -std=gnu99 -Werror +LOCAL_CFLAGS += -std=gnu99 -Werror -Wno-unused-parameter LOCAL_MODULE := libcorkscrew LOCAL_MODULE_TAGS := optional include $(BUILD_HOST_SHARED_LIBRARY) diff --git a/libcorkscrew/arch-x86/backtrace-x86.c b/libcorkscrew/arch-x86/backtrace-x86.c index e133ab6ff..ef2282137 100755 --- a/libcorkscrew/arch-x86/backtrace-x86.c +++ b/libcorkscrew/arch-x86/backtrace-x86.c @@ -380,7 +380,7 @@ static bool execute_dwarf(const memory_t* memory, uintptr_t ptr, cie_info_t* cie case DW_CFA_offset_extended: // probably we don't have it on x86. if (!try_get_uleb128(memory, ptr, ®, cursor)) return false; if (!try_get_uleb128(memory, ptr, &offset, cursor)) return false; - if (reg > DWARF_REGISTERS) { + if (reg >= DWARF_REGISTERS) { ALOGE("DW_CFA_offset_extended: r%d exceeds supported number of registers (%d)", reg, DWARF_REGISTERS); return false; } @@ -390,39 +390,39 @@ static bool execute_dwarf(const memory_t* memory, uintptr_t ptr, cie_info_t* cie break; case DW_CFA_restore_extended: // probably we don't have it on x86. if (!try_get_uleb128(memory, ptr, ®, cursor)) return false; - dstate->regs[reg].rule = stack->regs[reg].rule; - dstate->regs[reg].value = stack->regs[reg].value; - if (reg > DWARF_REGISTERS) { + if (reg >= DWARF_REGISTERS) { ALOGE("DW_CFA_restore_extended: r%d exceeds supported number of registers (%d)", reg, DWARF_REGISTERS); return false; } + dstate->regs[reg].rule = stack->regs[reg].rule; + dstate->regs[reg].value = stack->regs[reg].value; ALOGV("DW_CFA_restore: r%d = %c(%d)", reg, dstate->regs[reg].rule, dstate->regs[reg].value); break; case DW_CFA_undefined: // probably we don't have it on x86. if (!try_get_uleb128(memory, ptr, ®, cursor)) return false; - dstate->regs[reg].rule = 'u'; - dstate->regs[reg].value = 0; - if (reg > DWARF_REGISTERS) { + if (reg >= DWARF_REGISTERS) { ALOGE("DW_CFA_undefined: r%d exceeds supported number of registers (%d)", reg, DWARF_REGISTERS); return false; } + dstate->regs[reg].rule = 'u'; + dstate->regs[reg].value = 0; ALOGV("DW_CFA_undefined: r%d", reg); break; case DW_CFA_same_value: // probably we don't have it on x86. if (!try_get_uleb128(memory, ptr, ®, cursor)) return false; - dstate->regs[reg].rule = 's'; - dstate->regs[reg].value = 0; - if (reg > DWARF_REGISTERS) { + if (reg >= DWARF_REGISTERS) { ALOGE("DW_CFA_undefined: r%d exceeds supported number of registers (%d)", reg, DWARF_REGISTERS); return false; } + dstate->regs[reg].rule = 's'; + dstate->regs[reg].value = 0; ALOGV("DW_CFA_same_value: r%d", reg); break; case DW_CFA_register: // probably we don't have it on x86. if (!try_get_uleb128(memory, ptr, ®, cursor)) return false; /* that's new register actually, not offset */ if (!try_get_uleb128(memory, ptr, &offset, cursor)) return false; - if (reg > DWARF_REGISTERS || offset > DWARF_REGISTERS) { + if (reg >= DWARF_REGISTERS || offset >= DWARF_REGISTERS) { ALOGE("DW_CFA_register: r%d or r%d exceeds supported number of registers (%d)", reg, offset, DWARF_REGISTERS); return false; } @@ -520,7 +520,7 @@ static bool get_old_register_value(const memory_t* memory, uint32_t cfa, /* Updaing state based on dwarf state. */ static bool update_state(const memory_t* memory, unwind_state_t* state, - dwarf_state_t* dstate, cie_info_t* cie_info) { + dwarf_state_t* dstate) { unwind_state_t newstate; /* We can restore more registers here if we need them. Meanwile doing minimal work here. */ /* Getting CFA. */ @@ -550,7 +550,6 @@ static bool update_state(const memory_t* memory, unwind_state_t* state, /* Execute CIE and FDE instructions for FDE found with find_fde. */ static bool execute_fde(const memory_t* memory, - const map_info_t* map_info_list, uintptr_t fde, unwind_state_t* state) { uint32_t fde_length = 0; @@ -753,7 +752,7 @@ static bool execute_fde(const memory_t* memory, ALOGV("IP: %x, LOC: %x", state->reg[DWARF_EIP], dstate->loc); } - return update_state(memory, state, dstate, cie_info); + return update_state(memory, state, dstate); } static ssize_t unwind_backtrace_common(const memory_t* memory, @@ -805,7 +804,7 @@ static ssize_t unwind_backtrace_common(const memory_t* memory, uint32_t stack_top = state->reg[DWARF_ESP]; - if (!execute_fde(memory, map_info_list, fde, state)) break; + if (!execute_fde(memory, fde, state)) break; if (frame) { frame->stack_top = stack_top; diff --git a/libcutils/ashmem-dev.c b/libcutils/ashmem-dev.c index 8b71f87de..3089a942d 100644 --- a/libcutils/ashmem-dev.c +++ b/libcutils/ashmem-dev.c @@ -48,7 +48,7 @@ int ashmem_create_region(const char *name, size_t size) return fd; if (name) { - char buf[ASHMEM_NAME_LEN]; + char buf[ASHMEM_NAME_LEN] = {0}; strlcpy(buf, name, sizeof(buf)); ret = ioctl(fd, ASHMEM_SET_NAME, buf); diff --git a/libsparse/output_file.c b/libsparse/output_file.c index 5014e4a87..24280227e 100644 --- a/libsparse/output_file.c +++ b/libsparse/output_file.c @@ -46,15 +46,6 @@ #define off64_t off_t #endif -#ifdef __BIONIC__ -extern void* __mmap2(void *, size_t, int, int, int, off_t); -static inline void *mmap64(void *addr, size_t length, int prot, int flags, - int fd, off64_t offset) -{ - return __mmap2(addr, length, prot, flags, fd, offset >> 12); -} -#endif - #define min(a, b) \ ({ typeof(a) _a = (a); typeof(b) _b = (b); (_a < _b) ? _a : _b; }) diff --git a/mkbootimg/bootimg.h b/mkbootimg/bootimg.h index 242ab35db..9171d85a7 100644 --- a/mkbootimg/bootimg.h +++ b/mkbootimg/bootimg.h @@ -24,6 +24,7 @@ typedef struct boot_img_hdr boot_img_hdr; #define BOOT_MAGIC_SIZE 8 #define BOOT_NAME_SIZE 16 #define BOOT_ARGS_SIZE 512 +#define BOOT_EXTRA_ARGS_SIZE 1024 struct boot_img_hdr { @@ -43,10 +44,14 @@ struct boot_img_hdr unsigned unused[2]; /* future expansion: should be 0 */ unsigned char name[BOOT_NAME_SIZE]; /* asciiz product name */ - + unsigned char cmdline[BOOT_ARGS_SIZE]; unsigned id[8]; /* timestamp / checksum / sha1 / etc */ + + /* Supplemental command line data; kept here to maintain + * binary compatibility with older versions of mkbootimg */ + unsigned char extra_cmdline[BOOT_EXTRA_ARGS_SIZE]; }; /* diff --git a/mkbootimg/mkbootimg.c b/mkbootimg/mkbootimg.c index 34a879b5a..d598f0395 100644 --- a/mkbootimg/mkbootimg.c +++ b/mkbootimg/mkbootimg.c @@ -114,6 +114,7 @@ int main(int argc, char **argv) unsigned ramdisk_offset = 0x01000000; unsigned second_offset = 0x00f00000; unsigned tags_offset = 0x00000100; + size_t cmdlen; argc--; argv++; @@ -192,11 +193,19 @@ int main(int argc, char **argv) memcpy(hdr.magic, BOOT_MAGIC, BOOT_MAGIC_SIZE); - if(strlen(cmdline) > (BOOT_ARGS_SIZE - 1)) { + cmdlen = strlen(cmdline); + if(cmdlen > (BOOT_ARGS_SIZE + BOOT_EXTRA_ARGS_SIZE - 2)) { fprintf(stderr,"error: kernel commandline too large\n"); return 1; } - strcpy((char*)hdr.cmdline, cmdline); + /* Even if we need to use the supplemental field, ensure we + * are still NULL-terminated */ + strncpy((char *)hdr.cmdline, cmdline, BOOT_ARGS_SIZE - 1); + hdr.cmdline[BOOT_ARGS_SIZE - 1] = '\0'; + if (cmdlen >= (BOOT_ARGS_SIZE - 1)) { + cmdline += (BOOT_ARGS_SIZE - 1); + strncpy((char *)hdr.extra_cmdline, cmdline, BOOT_EXTRA_ARGS_SIZE); + } kernel_data = load_file(kernel_fn, &hdr.kernel_size); if(kernel_data == 0) { diff --git a/rootdir/init.rc b/rootdir/init.rc index cd995742f..580077220 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -345,7 +345,6 @@ on boot chown root radio /proc/cmdline # Set these so we can remotely update SELinux policy - chown system system /sys/fs/selinux/load chown system system /sys/fs/selinux/enforce # Define TCP buffer sizes for various networks @@ -415,10 +414,6 @@ service healthd-charger /sbin/healthd -n critical seclabel u:r:healthd:s0 -on property:selinux.reload_policy=1 - restart ueventd - restart installd - service console /system/bin/sh class core console |