Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* This file is used to define the properties of the filesystem |
| 18 | ** images generated by build tools (mkbootfs and mkyaffs2image) and |
| 19 | ** by the device side of adb. |
| 20 | */ |
| 21 | |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 22 | #define LOG_TAG "fs_config" |
Mark Salyzyn | 4e5f71a | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 23 | |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 24 | #define _GNU_SOURCE |
| 25 | |
| 26 | #include <errno.h> |
| 27 | #include <fcntl.h> |
| 28 | #include <stdbool.h> |
| 29 | #include <stdint.h> |
| 30 | #include <stdio.h> |
| 31 | #include <stdlib.h> |
| 32 | #include <string.h> |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 33 | #include <sys/stat.h> |
| 34 | #include <sys/types.h> |
| 35 | |
Mark Salyzyn | 30f991f | 2017-01-10 13:19:54 -0800 | [diff] [blame] | 36 | #include <log/log.h> |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 37 | #include <private/android_filesystem_config.h> |
Mark Salyzyn | a53b83c | 2017-04-03 07:30:06 -0700 | [diff] [blame] | 38 | #include <private/fs_config.h> |
Mark Salyzyn | fd5b425 | 2015-04-16 08:13:32 -0700 | [diff] [blame] | 39 | #include <utils/Compat.h> |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 40 | |
Mark Salyzyn | 4232b37 | 2015-04-16 08:40:55 -0700 | [diff] [blame] | 41 | #ifndef O_BINARY |
| 42 | #define O_BINARY 0 |
| 43 | #endif |
| 44 | |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 45 | /* My kingdom for <endian.h> */ |
Mark Salyzyn | 166e24c | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 46 | static inline uint16_t get2LE(const uint8_t* src) { return src[0] | (src[1] << 8); } |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 47 | |
Mark Salyzyn | 166e24c | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 48 | static inline uint64_t get8LE(const uint8_t* src) { |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 49 | uint32_t low, high; |
| 50 | |
| 51 | low = src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24); |
| 52 | high = src[4] | (src[5] << 8) | (src[6] << 16) | (src[7] << 24); |
Mark Salyzyn | 166e24c | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 53 | return ((uint64_t)high << 32) | (uint64_t)low; |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Mark Salyzyn | 166e24c | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 56 | #define ALIGN(x, alignment) (((x) + ((alignment)-1)) & ~((alignment)-1)) |
Mark Salyzyn | 5d9e5ef | 2015-04-01 11:02:00 -0700 | [diff] [blame] | 57 | |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 58 | /* Rules for directories. |
| 59 | ** These rules are applied based on "first match", so they |
| 60 | ** should start with the most specific path and work their |
| 61 | ** way up to the root. |
| 62 | */ |
| 63 | |
| 64 | static const struct fs_path_config android_dirs[] = { |
Mark Salyzyn | 166e24c | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 65 | /* clang-format off */ |
Mark Salyzyn | c4f9f4c | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 66 | { 00770, AID_SYSTEM, AID_CACHE, 0, "cache" }, |
| 67 | { 00500, AID_ROOT, AID_ROOT, 0, "config" }, |
| 68 | { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app" }, |
| 69 | { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app-private" }, |
| 70 | { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app-ephemeral" }, |
| 71 | { 00771, AID_ROOT, AID_ROOT, 0, "data/dalvik-cache" }, |
| 72 | { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/data" }, |
| 73 | { 00771, AID_SHELL, AID_SHELL, 0, "data/local/tmp" }, |
| 74 | { 00771, AID_SHELL, AID_SHELL, 0, "data/local" }, |
| 75 | { 00770, AID_DHCP, AID_DHCP, 0, "data/misc/dhcp" }, |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 76 | { 00771, AID_SHARED_RELRO, AID_SHARED_RELRO, 0, "data/misc/shared_relro" }, |
Mark Salyzyn | c4f9f4c | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 77 | { 01771, AID_SYSTEM, AID_MISC, 0, "data/misc" }, |
| 78 | { 00775, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media/Music" }, |
| 79 | { 00775, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media" }, |
| 80 | { 00750, AID_ROOT, AID_SHELL, 0, "data/nativetest" }, |
| 81 | { 00750, AID_ROOT, AID_SHELL, 0, "data/nativetest64" }, |
| 82 | { 00775, AID_ROOT, AID_ROOT, 0, "data/preloads" }, |
| 83 | { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data" }, |
| 84 | { 00755, AID_ROOT, AID_SYSTEM, 0, "mnt" }, |
| 85 | { 00755, AID_ROOT, AID_ROOT, 0, "root" }, |
| 86 | { 00750, AID_ROOT, AID_SHELL, 0, "sbin" }, |
| 87 | { 00777, AID_ROOT, AID_ROOT, 0, "sdcard" }, |
| 88 | { 00751, AID_ROOT, AID_SDCARD_R, 0, "storage" }, |
| 89 | { 00755, AID_ROOT, AID_SHELL, 0, "system/bin" }, |
| 90 | { 00755, AID_ROOT, AID_ROOT, 0, "system/etc/ppp" }, |
| 91 | { 00755, AID_ROOT, AID_SHELL, 0, "system/vendor" }, |
| 92 | { 00755, AID_ROOT, AID_SHELL, 0, "system/xbin" }, |
| 93 | { 00755, AID_ROOT, AID_SHELL, 0, "vendor" }, |
| 94 | { 00755, AID_ROOT, AID_ROOT, 0, 0 }, |
Mark Salyzyn | 166e24c | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 95 | /* clang-format on */ |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | /* Rules for files. |
| 99 | ** These rules are applied based on "first match", so they |
| 100 | ** should start with the most specific path and work their |
| 101 | ** way up to the root. Prefixes ending in * denotes wildcard |
| 102 | ** and will allow partial matches. |
| 103 | */ |
Mark Salyzyn | 9ceadcb | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 104 | static const char sys_conf_dir[] = "/system/etc/fs_config_dirs"; |
| 105 | static const char sys_conf_file[] = "/system/etc/fs_config_files"; |
Mark Salyzyn | 62c701e | 2017-03-21 08:09:52 -0700 | [diff] [blame] | 106 | /* No restrictions are placed on the vendor and oem file-system config files, |
| 107 | * although the developer is advised to restrict the scope to the /vendor or |
| 108 | * oem/ file-system since the intent is to provide support for customized |
| 109 | * portions of a separate vendor.img or oem.img. Has to remain open so that |
Mark Salyzyn | 2b616ce | 2017-03-22 15:23:24 -0700 | [diff] [blame] | 110 | * customization can also land on /system/vendor, /system/oem or /system/odm. |
| 111 | * We expect build-time checking or filtering when constructing the associated |
| 112 | * fs_config_* files (see build/tools/fs_config/fs_config_generate.c) |
Mark Salyzyn | 9ceadcb | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 113 | */ |
| 114 | static const char ven_conf_dir[] = "/vendor/etc/fs_config_dirs"; |
| 115 | static const char ven_conf_file[] = "/vendor/etc/fs_config_files"; |
Mark Salyzyn | 62c701e | 2017-03-21 08:09:52 -0700 | [diff] [blame] | 116 | static const char oem_conf_dir[] = "/oem/etc/fs_config_dirs"; |
| 117 | static const char oem_conf_file[] = "/oem/etc/fs_config_files"; |
Mark Salyzyn | 2b616ce | 2017-03-22 15:23:24 -0700 | [diff] [blame] | 118 | static const char odm_conf_dir[] = "/odm/etc/fs_config_dirs"; |
| 119 | static const char odm_conf_file[] = "/odm/etc/fs_config_files"; |
Mark Salyzyn | 9ceadcb | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 120 | static const char* conf[][2] = { |
Mark Salyzyn | 2b616ce | 2017-03-22 15:23:24 -0700 | [diff] [blame] | 121 | {sys_conf_file, sys_conf_dir}, |
| 122 | {ven_conf_file, ven_conf_dir}, |
| 123 | {oem_conf_file, oem_conf_dir}, |
| 124 | {odm_conf_file, odm_conf_dir}, |
Mark Salyzyn | 9ceadcb | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 125 | }; |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 126 | |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 127 | static const struct fs_path_config android_files[] = { |
Mark Salyzyn | 166e24c | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 128 | /* clang-format off */ |
Mark Salyzyn | a45eae9 | 2017-03-20 08:53:24 -0700 | [diff] [blame] | 129 | { 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app/*" }, |
| 130 | { 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app-ephemeral/*" }, |
| 131 | { 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app-private/*" }, |
| 132 | { 00644, AID_APP, AID_APP, 0, "data/data/*" }, |
| 133 | { 00644, AID_MEDIA_RW, AID_MEDIA_RW, 0, "data/media/*" }, |
| 134 | { 00640, AID_ROOT, AID_SHELL, 0, "data/nativetest/tests.txt" }, |
| 135 | { 00640, AID_ROOT, AID_SHELL, 0, "data/nativetest64/tests.txt" }, |
| 136 | { 00750, AID_ROOT, AID_SHELL, 0, "data/nativetest/*" }, |
| 137 | { 00750, AID_ROOT, AID_SHELL, 0, "data/nativetest64/*" }, |
| 138 | { 00600, AID_ROOT, AID_ROOT, 0, "default.prop" }, |
| 139 | { 00600, AID_ROOT, AID_ROOT, 0, "odm/build.prop" }, |
| 140 | { 00600, AID_ROOT, AID_ROOT, 0, "odm/default.prop" }, |
Mark Salyzyn | 2b616ce | 2017-03-22 15:23:24 -0700 | [diff] [blame] | 141 | { 00444, AID_ROOT, AID_ROOT, 0, odm_conf_dir + 1 }, |
| 142 | { 00444, AID_ROOT, AID_ROOT, 0, odm_conf_file + 1 }, |
Mark Salyzyn | fde1942 | 2017-04-28 09:43:36 -0700 | [diff] [blame^] | 143 | { 00600, AID_ROOT, AID_ROOT, 0, "system/odm/build.prop" }, |
| 144 | { 00600, AID_ROOT, AID_ROOT, 0, "system/odm/default.prop" }, |
| 145 | { 00444, AID_ROOT, AID_ROOT, 0, "system/odm/etc/fs_config_dirs" }, |
| 146 | { 00444, AID_ROOT, AID_ROOT, 0, "system/odm/etc/fs_config_files" }, |
Mark Salyzyn | 62c701e | 2017-03-21 08:09:52 -0700 | [diff] [blame] | 147 | { 00444, AID_ROOT, AID_ROOT, 0, oem_conf_dir + 1 }, |
| 148 | { 00444, AID_ROOT, AID_ROOT, 0, oem_conf_file + 1 }, |
Mark Salyzyn | fde1942 | 2017-04-28 09:43:36 -0700 | [diff] [blame^] | 149 | { 00444, AID_ROOT, AID_ROOT, 0, "system/oem/etc/fs_config_dirs" }, |
| 150 | { 00444, AID_ROOT, AID_ROOT, 0, "system/oem/etc/fs_config_files" }, |
Mark Salyzyn | a45eae9 | 2017-03-20 08:53:24 -0700 | [diff] [blame] | 151 | { 00750, AID_ROOT, AID_SHELL, 0, "sbin/fs_mgr" }, |
| 152 | { 00755, AID_ROOT, AID_SHELL, 0, "system/bin/crash_dump32" }, |
| 153 | { 00755, AID_ROOT, AID_SHELL, 0, "system/bin/crash_dump64" }, |
| 154 | { 00755, AID_ROOT, AID_SHELL, 0, "system/bin/debuggerd" }, |
| 155 | { 00750, AID_ROOT, AID_ROOT, 0, "system/bin/install-recovery.sh" }, |
| 156 | { 00700, AID_ROOT, AID_ROOT, 0, "system/bin/secilc" }, |
| 157 | { 00750, AID_ROOT, AID_ROOT, 0, "system/bin/uncrypt" }, |
| 158 | { 00600, AID_ROOT, AID_ROOT, 0, "system/build.prop" }, |
Mark Salyzyn | 9ceadcb | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 159 | { 00444, AID_ROOT, AID_ROOT, 0, sys_conf_dir + 1 }, |
| 160 | { 00444, AID_ROOT, AID_ROOT, 0, sys_conf_file + 1 }, |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 161 | { 00440, AID_ROOT, AID_SHELL, 0, "system/etc/init.goldfish.rc" }, |
| 162 | { 00550, AID_ROOT, AID_SHELL, 0, "system/etc/init.goldfish.sh" }, |
| 163 | { 00550, AID_ROOT, AID_SHELL, 0, "system/etc/init.ril" }, |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 164 | { 00555, AID_ROOT, AID_ROOT, 0, "system/etc/ppp/*" }, |
| 165 | { 00555, AID_ROOT, AID_ROOT, 0, "system/etc/rc.*" }, |
Tao Bao | c6e93fe | 2015-07-18 19:46:16 -0700 | [diff] [blame] | 166 | { 00440, AID_ROOT, AID_ROOT, 0, "system/etc/recovery.img" }, |
Mark Salyzyn | fde1942 | 2017-04-28 09:43:36 -0700 | [diff] [blame^] | 167 | { 00600, AID_ROOT, AID_ROOT, 0, "system/vendor/build.prop" }, |
| 168 | { 00600, AID_ROOT, AID_ROOT, 0, "system/vendor/default.prop" }, |
| 169 | { 00444, AID_ROOT, AID_ROOT, 0, "system/vendor/etc/fs_config_dirs" }, |
| 170 | { 00444, AID_ROOT, AID_ROOT, 0, "system/vendor/etc/fs_config_files" }, |
Mark Salyzyn | a45eae9 | 2017-03-20 08:53:24 -0700 | [diff] [blame] | 171 | { 00600, AID_ROOT, AID_ROOT, 0, "vendor/build.prop" }, |
| 172 | { 00600, AID_ROOT, AID_ROOT, 0, "vendor/default.prop" }, |
Mark Salyzyn | 9ceadcb | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 173 | { 00444, AID_ROOT, AID_ROOT, 0, ven_conf_dir + 1 }, |
| 174 | { 00444, AID_ROOT, AID_ROOT, 0, ven_conf_file + 1 }, |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 175 | |
Nick Kralevich | cbbc661 | 2015-11-30 09:17:18 -0800 | [diff] [blame] | 176 | /* the following two files are INTENTIONALLY set-uid, but they |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 177 | * are NOT included on user builds. */ |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 178 | { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procmem" }, |
Mark Salyzyn | a45eae9 | 2017-03-20 08:53:24 -0700 | [diff] [blame] | 179 | { 04750, AID_ROOT, AID_SHELL, 0, "system/xbin/su" }, |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 180 | |
Mark Salyzyn | 166e24c | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 181 | /* the following files have enhanced capabilities and ARE included |
| 182 | * in user builds. */ |
Mark Salyzyn | a45eae9 | 2017-03-20 08:53:24 -0700 | [diff] [blame] | 183 | { 00700, AID_SYSTEM, AID_SHELL, CAP_MASK_LONG(CAP_BLOCK_SUSPEND), |
| 184 | "system/bin/inputflinger" }, |
Mark Salyzyn | 0d2a1dc | 2016-10-28 12:41:17 -0700 | [diff] [blame] | 185 | { 00550, AID_LOGD, AID_LOGD, CAP_MASK_LONG(CAP_SYSLOG) | |
| 186 | CAP_MASK_LONG(CAP_AUDIT_CONTROL) | |
| 187 | CAP_MASK_LONG(CAP_SETGID), |
| 188 | "system/bin/logd" }, |
| 189 | { 00750, AID_ROOT, AID_SHELL, CAP_MASK_LONG(CAP_SETUID) | |
| 190 | CAP_MASK_LONG(CAP_SETGID), |
| 191 | "system/bin/run-as" }, |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 192 | |
Tim Murray | 3a29e34 | 2016-06-17 14:02:16 -0700 | [diff] [blame] | 193 | /* Support FIFO scheduling mode in SurfaceFlinger. */ |
Mark Salyzyn | 325aa70 | 2016-10-28 12:41:17 -0700 | [diff] [blame] | 194 | { 00755, AID_SYSTEM, AID_GRAPHICS, CAP_MASK_LONG(CAP_SYS_NICE), |
| 195 | "system/bin/surfaceflinger" }, |
Tim Murray | 3a29e34 | 2016-06-17 14:02:16 -0700 | [diff] [blame] | 196 | |
Christopher Wiley | a760883 | 2016-07-12 14:30:21 -0700 | [diff] [blame] | 197 | /* Support hostapd administering a network interface. */ |
Mark Salyzyn | 0d2a1dc | 2016-10-28 12:41:17 -0700 | [diff] [blame] | 198 | { 00755, AID_WIFI, AID_WIFI, CAP_MASK_LONG(CAP_NET_ADMIN) | |
| 199 | CAP_MASK_LONG(CAP_NET_RAW), |
Mark Salyzyn | fde1942 | 2017-04-28 09:43:36 -0700 | [diff] [blame^] | 200 | "system/vendor/bin/hostapd" }, |
| 201 | { 00755, AID_WIFI, AID_WIFI, CAP_MASK_LONG(CAP_NET_ADMIN) | |
| 202 | CAP_MASK_LONG(CAP_NET_RAW), |
Po-Chien Hsueh | a030c33 | 2017-02-14 09:39:45 +0800 | [diff] [blame] | 203 | "vendor/bin/hostapd" }, |
Christopher Wiley | a760883 | 2016-07-12 14:30:21 -0700 | [diff] [blame] | 204 | |
Philip Cuadra | 1c268a8 | 2017-03-23 10:05:45 -0700 | [diff] [blame] | 205 | /* Support Bluetooth legacy hal accessing /sys/class/rfkill |
| 206 | * Support RT scheduling in Bluetooth */ |
| 207 | { 00700, AID_BLUETOOTH, AID_BLUETOOTH, CAP_MASK_LONG(CAP_NET_ADMIN) | |
| 208 | CAP_MASK_LONG(CAP_SYS_NICE), |
Mark Salyzyn | fde1942 | 2017-04-28 09:43:36 -0700 | [diff] [blame^] | 209 | "system/vendor/bin/hw/android.hardware.bluetooth@1.0-service" }, |
| 210 | { 00700, AID_BLUETOOTH, AID_BLUETOOTH, CAP_MASK_LONG(CAP_NET_ADMIN) | |
| 211 | CAP_MASK_LONG(CAP_SYS_NICE), |
Mark Salyzyn | a45eae9 | 2017-03-20 08:53:24 -0700 | [diff] [blame] | 212 | "vendor/bin/hw/android.hardware.bluetooth@1.0-service" }, |
| 213 | |
Randy Pan | b8f707d | 2017-04-26 18:24:48 -0700 | [diff] [blame] | 214 | /* Support wifi_hal_legacy administering a network interface. */ |
| 215 | { 00755, AID_WIFI, AID_WIFI, CAP_MASK_LONG(CAP_NET_ADMIN) | |
| 216 | CAP_MASK_LONG(CAP_NET_RAW), |
Mark Salyzyn | fde1942 | 2017-04-28 09:43:36 -0700 | [diff] [blame^] | 217 | "system/vendor/bin/hw/android.hardware.wifi@1.0-service" }, |
| 218 | { 00755, AID_WIFI, AID_WIFI, CAP_MASK_LONG(CAP_NET_ADMIN) | |
| 219 | CAP_MASK_LONG(CAP_NET_RAW), |
Randy Pan | b8f707d | 2017-04-26 18:24:48 -0700 | [diff] [blame] | 220 | "vendor/bin/hw/android.hardware.wifi@1.0-service" }, |
| 221 | |
Mark Salyzyn | 166e24c | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 222 | /* A non-privileged zygote that spawns |
| 223 | * isolated processes for web rendering. */ |
Robert Sesek | a2ceaf6 | 2016-09-21 17:01:36 -0400 | [diff] [blame] | 224 | { 0750, AID_ROOT, AID_ROOT, CAP_MASK_LONG(CAP_SETUID) | |
| 225 | CAP_MASK_LONG(CAP_SETGID) | |
Mark Salyzyn | 0d2a1dc | 2016-10-28 12:41:17 -0700 | [diff] [blame] | 226 | CAP_MASK_LONG(CAP_SETPCAP), |
| 227 | "system/bin/webview_zygote32" }, |
Robert Sesek | a2ceaf6 | 2016-09-21 17:01:36 -0400 | [diff] [blame] | 228 | { 0750, AID_ROOT, AID_ROOT, CAP_MASK_LONG(CAP_SETUID) | |
| 229 | CAP_MASK_LONG(CAP_SETGID) | |
Mark Salyzyn | 0d2a1dc | 2016-10-28 12:41:17 -0700 | [diff] [blame] | 230 | CAP_MASK_LONG(CAP_SETPCAP), |
| 231 | "system/bin/webview_zygote64" }, |
Robert Sesek | a2ceaf6 | 2016-09-21 17:01:36 -0400 | [diff] [blame] | 232 | |
Mark Salyzyn | a45eae9 | 2017-03-20 08:53:24 -0700 | [diff] [blame] | 233 | /* generic defaults */ |
| 234 | { 00755, AID_ROOT, AID_ROOT, 0, "bin/*" }, |
| 235 | { 00640, AID_ROOT, AID_SHELL, 0, "fstab.*" }, |
| 236 | { 00750, AID_ROOT, AID_SHELL, 0, "init*" }, |
| 237 | { 00750, AID_ROOT, AID_SHELL, 0, "sbin/*" }, |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 238 | { 00755, AID_ROOT, AID_SHELL, 0, "system/bin/*" }, |
| 239 | { 00755, AID_ROOT, AID_ROOT, 0, "system/lib/valgrind/*" }, |
| 240 | { 00755, AID_ROOT, AID_ROOT, 0, "system/lib64/valgrind/*" }, |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 241 | { 00755, AID_ROOT, AID_SHELL, 0, "system/vendor/bin/*" }, |
Erik Kline | a5a9c74 | 2016-05-27 13:13:07 +0900 | [diff] [blame] | 242 | { 00755, AID_ROOT, AID_SHELL, 0, "system/vendor/xbin/*" }, |
Mark Salyzyn | a45eae9 | 2017-03-20 08:53:24 -0700 | [diff] [blame] | 243 | { 00755, AID_ROOT, AID_SHELL, 0, "system/xbin/*" }, |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 244 | { 00755, AID_ROOT, AID_SHELL, 0, "vendor/bin/*" }, |
Erik Kline | a5a9c74 | 2016-05-27 13:13:07 +0900 | [diff] [blame] | 245 | { 00755, AID_ROOT, AID_SHELL, 0, "vendor/xbin/*" }, |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 246 | { 00644, AID_ROOT, AID_ROOT, 0, 0 }, |
Mark Salyzyn | 166e24c | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 247 | /* clang-format on */ |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 248 | }; |
| 249 | |
Mark Salyzyn | ffa7632 | 2017-04-05 12:15:49 -0700 | [diff] [blame] | 250 | static size_t strip(const char* path, size_t len, const char suffix[]) { |
| 251 | if (len < strlen(suffix)) return len; |
| 252 | if (strncmp(path + len - strlen(suffix), suffix, strlen(suffix))) return len; |
| 253 | return len - strlen(suffix); |
| 254 | } |
| 255 | |
Mark Salyzyn | 9ceadcb | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 256 | static int fs_config_open(int dir, int which, const char* target_out_path) { |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 257 | int fd = -1; |
| 258 | |
Thierry Strudel | df33ffa | 2015-07-09 09:50:31 -0700 | [diff] [blame] | 259 | if (target_out_path && *target_out_path) { |
Mark Salyzyn | 166e24c | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 260 | /* target_out_path is the path to the directory holding content of |
Mark Salyzyn | ffa7632 | 2017-04-05 12:15:49 -0700 | [diff] [blame] | 261 | * system partition but as we cannot guarantee it ends with '/system' |
| 262 | * or with or without a trailing slash, need to strip them carefully. */ |
Mark Salyzyn | 166e24c | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 263 | char* name = NULL; |
Mark Salyzyn | ffa7632 | 2017-04-05 12:15:49 -0700 | [diff] [blame] | 264 | size_t len = strlen(target_out_path); |
| 265 | len = strip(target_out_path, len, "/"); |
| 266 | len = strip(target_out_path, len, "/system"); |
| 267 | if (asprintf(&name, "%.*s%s", (int)len, target_out_path, conf[which][dir]) != -1) { |
Mark Salyzyn | 4232b37 | 2015-04-16 08:40:55 -0700 | [diff] [blame] | 268 | fd = TEMP_FAILURE_RETRY(open(name, O_RDONLY | O_BINARY)); |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 269 | free(name); |
| 270 | } |
| 271 | } |
| 272 | if (fd < 0) { |
Mark Salyzyn | 9ceadcb | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 273 | fd = TEMP_FAILURE_RETRY(open(conf[which][dir], O_RDONLY | O_BINARY)); |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 274 | } |
| 275 | return fd; |
| 276 | } |
| 277 | |
Mark Salyzyn | 166e24c | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 278 | static bool fs_config_cmp(bool dir, const char* prefix, size_t len, const char* path, size_t plen) { |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 279 | if (dir) { |
| 280 | if (plen < len) { |
| 281 | return false; |
| 282 | } |
| 283 | } else { |
| 284 | /* If name ends in * then allow partial matches. */ |
| 285 | if (prefix[len - 1] == '*') { |
| 286 | return !strncmp(prefix, path, len - 1); |
| 287 | } |
| 288 | if (plen != len) { |
| 289 | return false; |
| 290 | } |
| 291 | } |
| 292 | return !strncmp(prefix, path, len); |
| 293 | } |
| 294 | |
Mark Salyzyn | 166e24c | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 295 | void fs_config(const char* path, int dir, const char* target_out_path, unsigned* uid, unsigned* gid, |
| 296 | unsigned* mode, uint64_t* capabilities) { |
| 297 | const struct fs_path_config* pc; |
Mark Salyzyn | 9ceadcb | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 298 | size_t which, plen; |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 299 | |
| 300 | if (path[0] == '/') { |
| 301 | path++; |
| 302 | } |
| 303 | |
Mark Salyzyn | 7e82633 | 2015-04-15 22:30:30 +0000 | [diff] [blame] | 304 | plen = strlen(path); |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 305 | |
Mark Salyzyn | 9ceadcb | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 306 | for (which = 0; which < (sizeof(conf) / sizeof(conf[0])); ++which) { |
Mark Salyzyn | 7977cc6 | 2015-04-15 19:27:39 -0700 | [diff] [blame] | 307 | struct fs_path_config_from_file header; |
| 308 | |
Mark Salyzyn | 9ceadcb | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 309 | int fd = fs_config_open(dir, which, target_out_path); |
| 310 | if (fd < 0) continue; |
| 311 | |
Mark Salyzyn | 7977cc6 | 2015-04-15 19:27:39 -0700 | [diff] [blame] | 312 | while (TEMP_FAILURE_RETRY(read(fd, &header, sizeof(header))) == sizeof(header)) { |
Mark Salyzyn | 166e24c | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 313 | char* prefix; |
| 314 | uint16_t host_len = get2LE((const uint8_t*)&header.len); |
Mark Salyzyn | 7977cc6 | 2015-04-15 19:27:39 -0700 | [diff] [blame] | 315 | ssize_t len, remainder = host_len - sizeof(header); |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 316 | if (remainder <= 0) { |
Mark Salyzyn | 9ceadcb | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 317 | ALOGE("%s len is corrupted", conf[which][dir]); |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 318 | break; |
| 319 | } |
Mark Salyzyn | 7977cc6 | 2015-04-15 19:27:39 -0700 | [diff] [blame] | 320 | prefix = calloc(1, remainder); |
| 321 | if (!prefix) { |
Mark Salyzyn | 9ceadcb | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 322 | ALOGE("%s out of memory", conf[which][dir]); |
Mark Salyzyn | 7977cc6 | 2015-04-15 19:27:39 -0700 | [diff] [blame] | 323 | break; |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 324 | } |
Mark Salyzyn | 7977cc6 | 2015-04-15 19:27:39 -0700 | [diff] [blame] | 325 | if (TEMP_FAILURE_RETRY(read(fd, prefix, remainder)) != remainder) { |
| 326 | free(prefix); |
Mark Salyzyn | 9ceadcb | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 327 | ALOGE("%s prefix is truncated", conf[which][dir]); |
Mark Salyzyn | 7977cc6 | 2015-04-15 19:27:39 -0700 | [diff] [blame] | 328 | break; |
| 329 | } |
| 330 | len = strnlen(prefix, remainder); |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 331 | if (len >= remainder) { /* missing a terminating null */ |
Mark Salyzyn | 7977cc6 | 2015-04-15 19:27:39 -0700 | [diff] [blame] | 332 | free(prefix); |
Mark Salyzyn | 9ceadcb | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 333 | ALOGE("%s is corrupted", conf[which][dir]); |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 334 | break; |
| 335 | } |
Mark Salyzyn | 7977cc6 | 2015-04-15 19:27:39 -0700 | [diff] [blame] | 336 | if (fs_config_cmp(dir, prefix, len, path, plen)) { |
| 337 | free(prefix); |
| 338 | close(fd); |
Mark Salyzyn | 166e24c | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 339 | *uid = get2LE((const uint8_t*)&(header.uid)); |
| 340 | *gid = get2LE((const uint8_t*)&(header.gid)); |
| 341 | *mode = (*mode & (~07777)) | get2LE((const uint8_t*)&(header.mode)); |
| 342 | *capabilities = get8LE((const uint8_t*)&(header.capabilities)); |
Mark Salyzyn | 7977cc6 | 2015-04-15 19:27:39 -0700 | [diff] [blame] | 343 | return; |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 344 | } |
Mark Salyzyn | 7977cc6 | 2015-04-15 19:27:39 -0700 | [diff] [blame] | 345 | free(prefix); |
Mark Salyzyn | 7e82633 | 2015-04-15 22:30:30 +0000 | [diff] [blame] | 346 | } |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 347 | close(fd); |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Mark Salyzyn | 166e24c | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 350 | for (pc = dir ? android_dirs : android_files; pc->prefix; pc++) { |
Mark Salyzyn | 6865114 | 2015-04-01 09:24:22 -0700 | [diff] [blame] | 351 | if (fs_config_cmp(dir, pc->prefix, strlen(pc->prefix), path, plen)) { |
| 352 | break; |
Mark Salyzyn | 8b2c7de | 2015-04-01 07:42:01 -0700 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | *uid = pc->uid; |
| 356 | *gid = pc->gid; |
| 357 | *mode = (*mode & (~07777)) | pc->mode; |
| 358 | *capabilities = pc->capabilities; |
| 359 | } |
Mark Salyzyn | 5d9e5ef | 2015-04-01 11:02:00 -0700 | [diff] [blame] | 360 | |
Mark Salyzyn | 166e24c | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 361 | ssize_t fs_config_generate(char* buffer, size_t length, const struct fs_path_config* pc) { |
| 362 | struct fs_path_config_from_file* p = (struct fs_path_config_from_file*)buffer; |
Mark Salyzyn | 5d9e5ef | 2015-04-01 11:02:00 -0700 | [diff] [blame] | 363 | size_t len = ALIGN(sizeof(*p) + strlen(pc->prefix) + 1, sizeof(uint64_t)); |
| 364 | |
| 365 | if ((length < len) || (len > UINT16_MAX)) { |
| 366 | return -ENOSPC; |
| 367 | } |
| 368 | memset(p, 0, len); |
| 369 | uint16_t host_len = len; |
Mark Salyzyn | 166e24c | 2017-03-20 08:15:40 -0700 | [diff] [blame] | 370 | p->len = get2LE((const uint8_t*)&host_len); |
| 371 | p->mode = get2LE((const uint8_t*)&(pc->mode)); |
| 372 | p->uid = get2LE((const uint8_t*)&(pc->uid)); |
| 373 | p->gid = get2LE((const uint8_t*)&(pc->gid)); |
| 374 | p->capabilities = get8LE((const uint8_t*)&(pc->capabilities)); |
Mark Salyzyn | 5d9e5ef | 2015-04-01 11:02:00 -0700 | [diff] [blame] | 375 | strcpy(p->prefix, pc->prefix); |
| 376 | return len; |
| 377 | } |