Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 17 | #define ATRACE_TAG ATRACE_TAG_PACKAGE_MANAGER |
| 18 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 19 | #include "VoldNativeService.h" |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 20 | #include "Benchmark.h" |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 21 | #include "CheckEncryption.h" |
| 22 | #include "IdleMaint.h" |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 23 | #include "MoveStorage.h" |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 24 | #include "Process.h" |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 25 | #include "VolumeManager.h" |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 26 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 27 | #include "cryptfs.h" |
| 28 | #include "Ext4Crypt.h" |
| 29 | #include "MetadataCrypt.h" |
| 30 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 31 | #include <fstream> |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 32 | #include <thread> |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 33 | |
| 34 | #include <android-base/logging.h> |
| 35 | #include <android-base/stringprintf.h> |
| 36 | #include <android-base/strings.h> |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 37 | #include <ext4_utils/ext4_crypt.h> |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 38 | #include <fs_mgr.h> |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 39 | #include <private/android_filesystem_config.h> |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 40 | #include <utils/Trace.h> |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 41 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 42 | using android::base::StringPrintf; |
| 43 | using std::endl; |
| 44 | |
| 45 | namespace android { |
| 46 | namespace vold { |
| 47 | |
| 48 | namespace { |
| 49 | |
| 50 | constexpr const char* kDump = "android.permission.DUMP"; |
| 51 | |
| 52 | static binder::Status ok() { |
| 53 | return binder::Status::ok(); |
| 54 | } |
| 55 | |
| 56 | static binder::Status exception(uint32_t code, const std::string& msg) { |
| 57 | return binder::Status::fromExceptionCode(code, String8(msg.c_str())); |
| 58 | } |
| 59 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 60 | static binder::Status error(const std::string& msg) { |
| 61 | PLOG(ERROR) << msg; |
| 62 | return binder::Status::fromServiceSpecificError(errno, String8(msg.c_str())); |
| 63 | } |
| 64 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 65 | static binder::Status translate(int status) { |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 66 | if (status == 0) { |
| 67 | return binder::Status::ok(); |
| 68 | } else { |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 69 | return binder::Status::fromServiceSpecificError(status); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 73 | static binder::Status translateBool(bool status) { |
| 74 | if (status) { |
| 75 | return binder::Status::ok(); |
| 76 | } else { |
| 77 | return binder::Status::fromServiceSpecificError(status); |
| 78 | } |
| 79 | } |
| 80 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 81 | binder::Status checkPermission(const char* permission) { |
| 82 | pid_t pid; |
| 83 | uid_t uid; |
| 84 | |
| 85 | if (checkCallingPermission(String16(permission), reinterpret_cast<int32_t*>(&pid), |
| 86 | reinterpret_cast<int32_t*>(&uid))) { |
| 87 | return ok(); |
| 88 | } else { |
| 89 | return exception(binder::Status::EX_SECURITY, |
| 90 | StringPrintf("UID %d / PID %d lacks permission %s", uid, pid, permission)); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | binder::Status checkUid(uid_t expectedUid) { |
| 95 | uid_t uid = IPCThreadState::self()->getCallingUid(); |
| 96 | if (uid == expectedUid || uid == AID_ROOT) { |
| 97 | return ok(); |
| 98 | } else { |
| 99 | return exception(binder::Status::EX_SECURITY, |
| 100 | StringPrintf("UID %d is not expected UID %d", uid, expectedUid)); |
| 101 | } |
| 102 | } |
| 103 | |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 104 | binder::Status checkArgumentId(const std::string& id) { |
| 105 | if (id.empty()) { |
| 106 | return exception(binder::Status::EX_ILLEGAL_ARGUMENT, "Missing ID"); |
| 107 | } |
| 108 | for (const char& c : id) { |
| 109 | if (!std::isalnum(c) && c != ':' && c != ',') { |
| 110 | return exception(binder::Status::EX_ILLEGAL_ARGUMENT, |
| 111 | StringPrintf("ID %s is malformed", id.c_str())); |
| 112 | } |
| 113 | } |
| 114 | return ok(); |
| 115 | } |
| 116 | |
| 117 | binder::Status checkArgumentPath(const std::string& path) { |
| 118 | if (path.empty()) { |
| 119 | return exception(binder::Status::EX_ILLEGAL_ARGUMENT, "Missing path"); |
| 120 | } |
| 121 | if (path[0] != '/') { |
| 122 | return exception(binder::Status::EX_ILLEGAL_ARGUMENT, |
| 123 | StringPrintf("Path %s is relative", path.c_str())); |
| 124 | } |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 125 | if ((path + '/').find("/../") != std::string::npos) { |
| 126 | return exception(binder::Status::EX_ILLEGAL_ARGUMENT, |
| 127 | StringPrintf("Path %s is shady", path.c_str())); |
| 128 | } |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 129 | for (const char& c : path) { |
| 130 | if (c == '\0' || c == '\n') { |
| 131 | return exception(binder::Status::EX_ILLEGAL_ARGUMENT, |
| 132 | StringPrintf("Path %s is malformed", path.c_str())); |
| 133 | } |
| 134 | } |
| 135 | return ok(); |
| 136 | } |
| 137 | |
| 138 | binder::Status checkArgumentHex(const std::string& hex) { |
| 139 | // Empty hex strings are allowed |
| 140 | for (const char& c : hex) { |
| 141 | if (!std::isxdigit(c) && c != ':' && c != '-') { |
| 142 | return exception(binder::Status::EX_ILLEGAL_ARGUMENT, |
| 143 | StringPrintf("Hex %s is malformed", hex.c_str())); |
| 144 | } |
| 145 | } |
| 146 | return ok(); |
| 147 | } |
| 148 | |
Sudheer Shanka | cc0df59 | 2018-08-02 10:21:42 -0700 | [diff] [blame] | 149 | binder::Status checkArgumentPackageName(const std::string& packageName) { |
| 150 | // This logic is borrowed from PackageParser.java |
| 151 | bool hasSep = false; |
| 152 | bool front = true; |
| 153 | |
| 154 | for (size_t i = 0; i < packageName.length(); ++i) { |
| 155 | char c = packageName[i]; |
| 156 | if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { |
| 157 | front = false; |
| 158 | continue; |
| 159 | } |
| 160 | if (!front) { |
| 161 | if ((c >= '0' && c <= '9') || c == '_') { |
| 162 | continue; |
| 163 | } |
| 164 | } |
| 165 | if (c == '.') { |
| 166 | hasSep = true; |
| 167 | front = true; |
| 168 | continue; |
| 169 | } |
| 170 | return exception(binder::Status::EX_ILLEGAL_ARGUMENT, |
| 171 | StringPrintf("Bad package character %c in %s", c, packageName.c_str())); |
| 172 | } |
| 173 | |
| 174 | if (front) { |
| 175 | return exception(binder::Status::EX_ILLEGAL_ARGUMENT, |
| 176 | StringPrintf("Missing separator in %s", packageName.c_str())); |
| 177 | } |
| 178 | |
| 179 | return ok(); |
| 180 | } |
| 181 | |
| 182 | binder::Status checkArgumentPackageNames(const std::vector<std::string>& packageNames) { |
| 183 | for (size_t i = 0; i < packageNames.size(); ++i) { |
| 184 | binder::Status status = checkArgumentPackageName(packageNames[i]); |
| 185 | if (!status.isOk()) { |
| 186 | return status; |
| 187 | } |
| 188 | } |
| 189 | return ok(); |
| 190 | } |
| 191 | |
| 192 | binder::Status checkArgumentSandboxId(const std::string& sandboxId) { |
| 193 | // sandboxId will be in either the format shared:<shared-user-id> or <package-name> |
| 194 | // and <shared-user-id> name has same requirements as <package-name>. |
| 195 | std::size_t nameStartIndex = 0; |
Greg Kaiser | e3f5932 | 2018-08-06 06:16:29 -0700 | [diff] [blame] | 196 | if (android::base::StartsWith(sandboxId, "shared:")) { |
| 197 | nameStartIndex = 7; // len("shared:") |
Sudheer Shanka | cc0df59 | 2018-08-02 10:21:42 -0700 | [diff] [blame] | 198 | } |
| 199 | return checkArgumentPackageName(sandboxId.substr(nameStartIndex)); |
| 200 | } |
| 201 | |
| 202 | binder::Status checkArgumentSandboxIds(const std::vector<std::string>& sandboxIds) { |
| 203 | for (size_t i = 0; i < sandboxIds.size(); ++i) { |
| 204 | binder::Status status = checkArgumentSandboxId(sandboxIds[i]); |
| 205 | if (!status.isOk()) { |
| 206 | return status; |
| 207 | } |
| 208 | } |
| 209 | return ok(); |
| 210 | } |
| 211 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 212 | #define ENFORCE_UID(uid) { \ |
| 213 | binder::Status status = checkUid((uid)); \ |
| 214 | if (!status.isOk()) { \ |
| 215 | return status; \ |
| 216 | } \ |
| 217 | } |
| 218 | |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 219 | #define CHECK_ARGUMENT_ID(id) { \ |
| 220 | binder::Status status = checkArgumentId((id)); \ |
| 221 | if (!status.isOk()) { \ |
| 222 | return status; \ |
| 223 | } \ |
| 224 | } |
| 225 | |
| 226 | #define CHECK_ARGUMENT_PATH(path) { \ |
| 227 | binder::Status status = checkArgumentPath((path)); \ |
| 228 | if (!status.isOk()) { \ |
| 229 | return status; \ |
| 230 | } \ |
| 231 | } |
| 232 | |
| 233 | #define CHECK_ARGUMENT_HEX(hex) { \ |
| 234 | binder::Status status = checkArgumentHex((hex)); \ |
| 235 | if (!status.isOk()) { \ |
| 236 | return status; \ |
| 237 | } \ |
| 238 | } |
| 239 | |
Sudheer Shanka | cc0df59 | 2018-08-02 10:21:42 -0700 | [diff] [blame] | 240 | #define CHECK_ARGUMENT_PACKAGE_NAMES(packageNames) { \ |
| 241 | binder::Status status = checkArgumentPackageNames((packageNames)); \ |
| 242 | if (!status.isOk()) { \ |
| 243 | return status; \ |
| 244 | } \ |
| 245 | } |
| 246 | |
| 247 | #define CHECK_ARGUMENT_SANDBOX_IDS(sandboxIds) { \ |
| 248 | binder::Status status = checkArgumentSandboxIds((sandboxIds)); \ |
| 249 | if (!status.isOk()) { \ |
| 250 | return status; \ |
| 251 | } \ |
| 252 | } |
| 253 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 254 | #define ACQUIRE_LOCK \ |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 255 | std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getLock()); \ |
| 256 | ATRACE_CALL(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 257 | |
| 258 | #define ACQUIRE_CRYPT_LOCK \ |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 259 | std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getCryptLock()); \ |
| 260 | ATRACE_CALL(); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 261 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 262 | } // namespace |
| 263 | |
| 264 | status_t VoldNativeService::start() { |
| 265 | IPCThreadState::self()->disableBackgroundScheduling(true); |
| 266 | status_t ret = BinderService<VoldNativeService>::publish(); |
| 267 | if (ret != android::OK) { |
| 268 | return ret; |
| 269 | } |
| 270 | sp<ProcessState> ps(ProcessState::self()); |
| 271 | ps->startThreadPool(); |
| 272 | ps->giveThreadPoolName(); |
| 273 | return android::OK; |
| 274 | } |
| 275 | |
| 276 | status_t VoldNativeService::dump(int fd, const Vector<String16> & /* args */) { |
| 277 | auto out = std::fstream(StringPrintf("/proc/self/fd/%d", fd)); |
| 278 | const binder::Status dump_permission = checkPermission(kDump); |
| 279 | if (!dump_permission.isOk()) { |
| 280 | out << dump_permission.toString8() << endl; |
| 281 | return PERMISSION_DENIED; |
| 282 | } |
| 283 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 284 | ACQUIRE_LOCK; |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 285 | out << "vold is happy!" << endl; |
| 286 | out.flush(); |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 287 | return NO_ERROR; |
| 288 | } |
| 289 | |
Jeff Sharkey | 814e9d3 | 2017-09-13 11:49:44 -0600 | [diff] [blame] | 290 | binder::Status VoldNativeService::setListener( |
| 291 | const android::sp<android::os::IVoldListener>& listener) { |
| 292 | ENFORCE_UID(AID_SYSTEM); |
| 293 | ACQUIRE_LOCK; |
| 294 | |
| 295 | VolumeManager::Instance()->setListener(listener); |
| 296 | return ok(); |
| 297 | } |
| 298 | |
Jeff Sharkey | cbe69fc | 2017-09-15 16:50:28 -0600 | [diff] [blame] | 299 | binder::Status VoldNativeService::monitor() { |
| 300 | ENFORCE_UID(AID_SYSTEM); |
| 301 | |
| 302 | // Simply acquire/release each lock for watchdog |
| 303 | { |
| 304 | ACQUIRE_LOCK; |
| 305 | } |
| 306 | { |
| 307 | ACQUIRE_CRYPT_LOCK; |
| 308 | } |
| 309 | |
| 310 | return ok(); |
| 311 | } |
| 312 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 313 | binder::Status VoldNativeService::reset() { |
| 314 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 315 | ACQUIRE_LOCK; |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 316 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 317 | return translate(VolumeManager::Instance()->reset()); |
| 318 | } |
| 319 | |
| 320 | binder::Status VoldNativeService::shutdown() { |
| 321 | ENFORCE_UID(AID_SYSTEM); |
| 322 | ACQUIRE_LOCK; |
| 323 | |
| 324 | return translate(VolumeManager::Instance()->shutdown()); |
| 325 | } |
| 326 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 327 | binder::Status VoldNativeService::onUserAdded(int32_t userId, int32_t userSerial) { |
| 328 | ENFORCE_UID(AID_SYSTEM); |
| 329 | ACQUIRE_LOCK; |
| 330 | |
| 331 | return translate(VolumeManager::Instance()->onUserAdded(userId, userSerial)); |
| 332 | } |
| 333 | |
| 334 | binder::Status VoldNativeService::onUserRemoved(int32_t userId) { |
| 335 | ENFORCE_UID(AID_SYSTEM); |
| 336 | ACQUIRE_LOCK; |
| 337 | |
| 338 | return translate(VolumeManager::Instance()->onUserRemoved(userId)); |
| 339 | } |
| 340 | |
Sudheer Shanka | ebaad1c | 2018-07-31 16:39:59 -0700 | [diff] [blame] | 341 | binder::Status VoldNativeService::onUserStarted(int32_t userId, |
| 342 | const std::vector<std::string>& packageNames) { |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 343 | ENFORCE_UID(AID_SYSTEM); |
Sudheer Shanka | cc0df59 | 2018-08-02 10:21:42 -0700 | [diff] [blame] | 344 | CHECK_ARGUMENT_PACKAGE_NAMES(packageNames); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 345 | ACQUIRE_LOCK; |
| 346 | |
Sudheer Shanka | ebaad1c | 2018-07-31 16:39:59 -0700 | [diff] [blame] | 347 | return translate(VolumeManager::Instance()->onUserStarted(userId, packageNames)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | binder::Status VoldNativeService::onUserStopped(int32_t userId) { |
| 351 | ENFORCE_UID(AID_SYSTEM); |
| 352 | ACQUIRE_LOCK; |
| 353 | |
| 354 | return translate(VolumeManager::Instance()->onUserStopped(userId)); |
| 355 | } |
| 356 | |
Sudheer Shanka | d484aa9 | 2018-07-31 10:07:34 -0700 | [diff] [blame] | 357 | binder::Status VoldNativeService::addAppIds(const std::vector<std::string>& packageNames, |
| 358 | const std::vector<int32_t>& appIds) { |
| 359 | ENFORCE_UID(AID_SYSTEM); |
Sudheer Shanka | cc0df59 | 2018-08-02 10:21:42 -0700 | [diff] [blame] | 360 | CHECK_ARGUMENT_PACKAGE_NAMES(packageNames); |
Sudheer Shanka | d484aa9 | 2018-07-31 10:07:34 -0700 | [diff] [blame] | 361 | ACQUIRE_LOCK; |
| 362 | |
| 363 | return translate(VolumeManager::Instance()->addAppIds(packageNames, appIds)); |
| 364 | } |
| 365 | |
Sudheer Shanka | d484aa9 | 2018-07-31 10:07:34 -0700 | [diff] [blame] | 366 | binder::Status VoldNativeService::addSandboxIds(const std::vector<int32_t>& appIds, |
| 367 | const std::vector<std::string>& sandboxIds) { |
| 368 | ENFORCE_UID(AID_SYSTEM); |
Sudheer Shanka | cc0df59 | 2018-08-02 10:21:42 -0700 | [diff] [blame] | 369 | CHECK_ARGUMENT_SANDBOX_IDS(sandboxIds); |
Sudheer Shanka | d484aa9 | 2018-07-31 10:07:34 -0700 | [diff] [blame] | 370 | ACQUIRE_LOCK; |
| 371 | |
| 372 | return translate(VolumeManager::Instance()->addSandboxIds(appIds, sandboxIds)); |
| 373 | } |
| 374 | |
Jeff Sharkey | 401b260 | 2017-12-14 22:15:20 -0700 | [diff] [blame] | 375 | binder::Status VoldNativeService::onSecureKeyguardStateChanged(bool isShowing) { |
| 376 | ENFORCE_UID(AID_SYSTEM); |
| 377 | ACQUIRE_LOCK; |
| 378 | |
| 379 | return translate(VolumeManager::Instance()->onSecureKeyguardStateChanged(isShowing)); |
| 380 | } |
| 381 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 382 | binder::Status VoldNativeService::partition(const std::string& diskId, int32_t partitionType, |
| 383 | int32_t ratio) { |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 384 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 385 | CHECK_ARGUMENT_ID(diskId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 386 | ACQUIRE_LOCK; |
| 387 | |
| 388 | auto disk = VolumeManager::Instance()->findDisk(diskId); |
| 389 | if (disk == nullptr) { |
| 390 | return error("Failed to find disk " + diskId); |
| 391 | } |
| 392 | switch (partitionType) { |
| 393 | case PARTITION_TYPE_PUBLIC: return translate(disk->partitionPublic()); |
| 394 | case PARTITION_TYPE_PRIVATE: return translate(disk->partitionPrivate()); |
| 395 | case PARTITION_TYPE_MIXED: return translate(disk->partitionMixed(ratio)); |
| 396 | default: return error("Unknown type " + std::to_string(partitionType)); |
| 397 | } |
| 398 | } |
| 399 | |
Jeff Sharkey | 3ce1825 | 2017-10-24 11:08:45 -0600 | [diff] [blame] | 400 | binder::Status VoldNativeService::forgetPartition(const std::string& partGuid, |
| 401 | const std::string& fsUuid) { |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 402 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 403 | CHECK_ARGUMENT_HEX(partGuid); |
Jeff Sharkey | 3ce1825 | 2017-10-24 11:08:45 -0600 | [diff] [blame] | 404 | CHECK_ARGUMENT_HEX(fsUuid); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 405 | ACQUIRE_LOCK; |
| 406 | |
Jeff Sharkey | 3ce1825 | 2017-10-24 11:08:45 -0600 | [diff] [blame] | 407 | return translate(VolumeManager::Instance()->forgetPartition(partGuid, fsUuid)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 408 | } |
| 409 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 410 | binder::Status VoldNativeService::mount(const std::string& volId, int32_t mountFlags, |
| 411 | int32_t mountUserId) { |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 412 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 413 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 414 | ACQUIRE_LOCK; |
| 415 | |
| 416 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 417 | if (vol == nullptr) { |
| 418 | return error("Failed to find volume " + volId); |
| 419 | } |
| 420 | |
| 421 | vol->setMountFlags(mountFlags); |
| 422 | vol->setMountUserId(mountUserId); |
| 423 | |
| 424 | int res = vol->mount(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 425 | if ((mountFlags & MOUNT_FLAG_PRIMARY) != 0) { |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 426 | VolumeManager::Instance()->setPrimary(vol); |
| 427 | } |
| 428 | return translate(res); |
| 429 | } |
| 430 | |
| 431 | binder::Status VoldNativeService::unmount(const std::string& volId) { |
| 432 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 433 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 434 | ACQUIRE_LOCK; |
| 435 | |
| 436 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 437 | if (vol == nullptr) { |
| 438 | return error("Failed to find volume " + volId); |
| 439 | } |
| 440 | return translate(vol->unmount()); |
| 441 | } |
| 442 | |
| 443 | binder::Status VoldNativeService::format(const std::string& volId, const std::string& fsType) { |
| 444 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 445 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 446 | ACQUIRE_LOCK; |
| 447 | |
| 448 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 449 | if (vol == nullptr) { |
| 450 | return error("Failed to find volume " + volId); |
| 451 | } |
| 452 | return translate(vol->format(fsType)); |
| 453 | } |
| 454 | |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 455 | static binder::Status pathForVolId(const std::string& volId, std::string* path) { |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 456 | if (volId == "private" || volId == "null") { |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 457 | *path = "/data"; |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 458 | } else { |
| 459 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 460 | if (vol == nullptr) { |
| 461 | return error("Failed to find volume " + volId); |
| 462 | } |
| 463 | if (vol->getType() != VolumeBase::Type::kPrivate) { |
| 464 | return error("Volume " + volId + " not private"); |
| 465 | } |
| 466 | if (vol->getState() != VolumeBase::State::kMounted) { |
| 467 | return error("Volume " + volId + " not mounted"); |
| 468 | } |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 469 | *path = vol->getPath(); |
| 470 | if (path->empty()) { |
| 471 | return error("Volume " + volId + " missing path"); |
| 472 | } |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 473 | } |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 474 | return ok(); |
| 475 | } |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 476 | |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 477 | binder::Status VoldNativeService::benchmark( |
| 478 | const std::string& volId, const android::sp<android::os::IVoldTaskListener>& listener) { |
| 479 | ENFORCE_UID(AID_SYSTEM); |
| 480 | CHECK_ARGUMENT_ID(volId); |
| 481 | ACQUIRE_LOCK; |
| 482 | |
| 483 | std::string path; |
| 484 | auto status = pathForVolId(volId, &path); |
| 485 | if (!status.isOk()) return status; |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 486 | |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 487 | std::thread([=]() { |
| 488 | android::vold::Benchmark(path, listener); |
| 489 | }).detach(); |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 490 | return ok(); |
| 491 | } |
| 492 | |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 493 | binder::Status VoldNativeService::checkEncryption(const std::string& volId) { |
| 494 | ENFORCE_UID(AID_SYSTEM); |
| 495 | CHECK_ARGUMENT_ID(volId); |
| 496 | ACQUIRE_LOCK; |
| 497 | |
| 498 | std::string path; |
| 499 | auto status = pathForVolId(volId, &path); |
| 500 | if (!status.isOk()) return status; |
| 501 | return translate(android::vold::CheckEncryption(path)); |
| 502 | } |
| 503 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 504 | binder::Status VoldNativeService::moveStorage(const std::string& fromVolId, |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 505 | const std::string& toVolId, const android::sp<android::os::IVoldTaskListener>& listener) { |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 506 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 507 | CHECK_ARGUMENT_ID(fromVolId); |
| 508 | CHECK_ARGUMENT_ID(toVolId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 509 | ACQUIRE_LOCK; |
| 510 | |
| 511 | auto fromVol = VolumeManager::Instance()->findVolume(fromVolId); |
| 512 | auto toVol = VolumeManager::Instance()->findVolume(toVolId); |
| 513 | if (fromVol == nullptr) { |
| 514 | return error("Failed to find volume " + fromVolId); |
| 515 | } else if (toVol == nullptr) { |
| 516 | return error("Failed to find volume " + toVolId); |
| 517 | } |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 518 | |
| 519 | std::thread([=]() { |
| 520 | android::vold::MoveStorage(fromVol, toVol, listener); |
| 521 | }).detach(); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 522 | return ok(); |
| 523 | } |
| 524 | |
| 525 | binder::Status VoldNativeService::remountUid(int32_t uid, int32_t remountMode) { |
| 526 | ENFORCE_UID(AID_SYSTEM); |
| 527 | ACQUIRE_LOCK; |
| 528 | |
| 529 | std::string tmp; |
| 530 | switch (remountMode) { |
| 531 | case REMOUNT_MODE_NONE: tmp = "none"; break; |
| 532 | case REMOUNT_MODE_DEFAULT: tmp = "default"; break; |
| 533 | case REMOUNT_MODE_READ: tmp = "read"; break; |
| 534 | case REMOUNT_MODE_WRITE: tmp = "write"; break; |
| 535 | default: return error("Unknown mode " + std::to_string(remountMode)); |
| 536 | } |
| 537 | return translate(VolumeManager::Instance()->remountUid(uid, tmp)); |
| 538 | } |
| 539 | |
| 540 | binder::Status VoldNativeService::mkdirs(const std::string& path) { |
| 541 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 542 | CHECK_ARGUMENT_PATH(path); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 543 | ACQUIRE_LOCK; |
| 544 | |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 545 | return translate(VolumeManager::Instance()->mkdirs(path)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 546 | } |
| 547 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 548 | binder::Status VoldNativeService::createObb(const std::string& sourcePath, |
| 549 | const std::string& sourceKey, int32_t ownerGid, std::string* _aidl_return) { |
| 550 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 551 | CHECK_ARGUMENT_PATH(sourcePath); |
| 552 | CHECK_ARGUMENT_HEX(sourceKey); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 553 | ACQUIRE_LOCK; |
| 554 | |
| 555 | return translate( |
| 556 | VolumeManager::Instance()->createObb(sourcePath, sourceKey, ownerGid, _aidl_return)); |
| 557 | } |
| 558 | |
| 559 | binder::Status VoldNativeService::destroyObb(const std::string& volId) { |
| 560 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 561 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 562 | ACQUIRE_LOCK; |
| 563 | |
| 564 | return translate(VolumeManager::Instance()->destroyObb(volId)); |
| 565 | } |
| 566 | |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 567 | binder::Status VoldNativeService::fstrim(int32_t fstrimFlags, |
| 568 | const android::sp<android::os::IVoldTaskListener>& listener) { |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 569 | ENFORCE_UID(AID_SYSTEM); |
| 570 | ACQUIRE_LOCK; |
| 571 | |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 572 | std::thread([=]() { |
| 573 | android::vold::Trim(listener); |
| 574 | }).detach(); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 575 | return ok(); |
| 576 | } |
| 577 | |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 578 | binder::Status VoldNativeService::runIdleMaint( |
| 579 | const android::sp<android::os::IVoldTaskListener>& listener) { |
| 580 | ENFORCE_UID(AID_SYSTEM); |
| 581 | ACQUIRE_LOCK; |
| 582 | |
| 583 | std::thread([=]() { |
| 584 | android::vold::RunIdleMaint(listener); |
| 585 | }).detach(); |
| 586 | return ok(); |
| 587 | } |
| 588 | |
| 589 | binder::Status VoldNativeService::abortIdleMaint( |
| 590 | const android::sp<android::os::IVoldTaskListener>& listener) { |
| 591 | ENFORCE_UID(AID_SYSTEM); |
| 592 | ACQUIRE_LOCK; |
| 593 | |
| 594 | std::thread([=]() { |
| 595 | android::vold::AbortIdleMaint(listener); |
| 596 | }).detach(); |
| 597 | return ok(); |
| 598 | } |
| 599 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 600 | binder::Status VoldNativeService::mountAppFuse(int32_t uid, int32_t pid, int32_t mountId, |
| 601 | android::base::unique_fd* _aidl_return) { |
| 602 | ENFORCE_UID(AID_SYSTEM); |
| 603 | ACQUIRE_LOCK; |
| 604 | |
| 605 | return translate(VolumeManager::Instance()->mountAppFuse(uid, pid, mountId, _aidl_return)); |
| 606 | } |
| 607 | |
| 608 | binder::Status VoldNativeService::unmountAppFuse(int32_t uid, int32_t pid, int32_t mountId) { |
| 609 | ENFORCE_UID(AID_SYSTEM); |
| 610 | ACQUIRE_LOCK; |
| 611 | |
| 612 | return translate(VolumeManager::Instance()->unmountAppFuse(uid, pid, mountId)); |
| 613 | } |
| 614 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 615 | binder::Status VoldNativeService::fdeCheckPassword(const std::string& password) { |
| 616 | ENFORCE_UID(AID_SYSTEM); |
| 617 | ACQUIRE_CRYPT_LOCK; |
| 618 | |
| 619 | return translate(cryptfs_check_passwd(password.c_str())); |
| 620 | } |
| 621 | |
| 622 | binder::Status VoldNativeService::fdeRestart() { |
| 623 | ENFORCE_UID(AID_SYSTEM); |
| 624 | ACQUIRE_CRYPT_LOCK; |
| 625 | |
| 626 | // Spawn as thread so init can issue commands back to vold without |
| 627 | // causing deadlock, usually as a result of prep_data_fs. |
| 628 | std::thread(&cryptfs_restart).detach(); |
| 629 | return ok(); |
| 630 | } |
| 631 | |
| 632 | binder::Status VoldNativeService::fdeComplete(int32_t* _aidl_return) { |
| 633 | ENFORCE_UID(AID_SYSTEM); |
| 634 | ACQUIRE_CRYPT_LOCK; |
| 635 | |
| 636 | *_aidl_return = cryptfs_crypto_complete(); |
| 637 | return ok(); |
| 638 | } |
| 639 | |
| 640 | static int fdeEnableInternal(int32_t passwordType, const std::string& password, |
| 641 | int32_t encryptionFlags) { |
| 642 | bool noUi = (encryptionFlags & VoldNativeService::ENCRYPTION_FLAG_NO_UI) != 0; |
| 643 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 644 | for (int tries = 0; tries < 2; ++tries) { |
| 645 | int rc; |
| 646 | if (passwordType == VoldNativeService::PASSWORD_TYPE_DEFAULT) { |
Paul Lawrence | 7ee87cf | 2017-12-22 10:12:06 -0800 | [diff] [blame] | 647 | rc = cryptfs_enable_default(noUi); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 648 | } else { |
Paul Lawrence | 7ee87cf | 2017-12-22 10:12:06 -0800 | [diff] [blame] | 649 | rc = cryptfs_enable(passwordType, password.c_str(), noUi); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | if (rc == 0) { |
| 653 | return 0; |
| 654 | } else if (tries == 0) { |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 655 | KillProcessesWithOpenFiles(DATA_MNT_POINT, SIGKILL); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 656 | } |
| 657 | } |
| 658 | |
| 659 | return -1; |
| 660 | } |
| 661 | |
| 662 | binder::Status VoldNativeService::fdeEnable(int32_t passwordType, |
| 663 | const std::string& password, int32_t encryptionFlags) { |
| 664 | ENFORCE_UID(AID_SYSTEM); |
| 665 | ACQUIRE_CRYPT_LOCK; |
| 666 | |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 667 | LOG(DEBUG) << "fdeEnable(" << passwordType << ", *, " << encryptionFlags << ")"; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 668 | if (e4crypt_is_native()) { |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 669 | LOG(ERROR) << "e4crypt_is_native, fdeEnable invalid"; |
| 670 | return error("e4crypt_is_native, fdeEnable invalid"); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 671 | } |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 672 | LOG(DEBUG) << "!e4crypt_is_native, spawning fdeEnableInternal"; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 673 | |
| 674 | // Spawn as thread so init can issue commands back to vold without |
| 675 | // causing deadlock, usually as a result of prep_data_fs. |
| 676 | std::thread(&fdeEnableInternal, passwordType, password, encryptionFlags).detach(); |
| 677 | return ok(); |
| 678 | } |
| 679 | |
| 680 | binder::Status VoldNativeService::fdeChangePassword(int32_t passwordType, |
| 681 | const std::string& password) { |
| 682 | ENFORCE_UID(AID_SYSTEM); |
| 683 | ACQUIRE_CRYPT_LOCK; |
| 684 | |
| 685 | return translate(cryptfs_changepw(passwordType, password.c_str())); |
| 686 | } |
| 687 | |
| 688 | binder::Status VoldNativeService::fdeVerifyPassword(const std::string& password) { |
| 689 | ENFORCE_UID(AID_SYSTEM); |
| 690 | ACQUIRE_CRYPT_LOCK; |
| 691 | |
| 692 | return translate(cryptfs_verify_passwd(password.c_str())); |
| 693 | } |
| 694 | |
| 695 | binder::Status VoldNativeService::fdeGetField(const std::string& key, |
| 696 | std::string* _aidl_return) { |
| 697 | ENFORCE_UID(AID_SYSTEM); |
| 698 | ACQUIRE_CRYPT_LOCK; |
| 699 | |
| 700 | char buf[PROPERTY_VALUE_MAX]; |
| 701 | if (cryptfs_getfield(key.c_str(), buf, sizeof(buf)) != CRYPTO_GETFIELD_OK) { |
| 702 | return error(StringPrintf("Failed to read field %s", key.c_str())); |
| 703 | } else { |
| 704 | *_aidl_return = buf; |
| 705 | return ok(); |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | binder::Status VoldNativeService::fdeSetField(const std::string& key, |
| 710 | const std::string& value) { |
| 711 | ENFORCE_UID(AID_SYSTEM); |
| 712 | ACQUIRE_CRYPT_LOCK; |
| 713 | |
| 714 | return translate(cryptfs_setfield(key.c_str(), value.c_str())); |
| 715 | } |
| 716 | |
| 717 | binder::Status VoldNativeService::fdeGetPasswordType(int32_t* _aidl_return) { |
| 718 | ENFORCE_UID(AID_SYSTEM); |
| 719 | ACQUIRE_CRYPT_LOCK; |
| 720 | |
| 721 | *_aidl_return = cryptfs_get_password_type(); |
| 722 | return ok(); |
| 723 | } |
| 724 | |
| 725 | binder::Status VoldNativeService::fdeGetPassword(std::string* _aidl_return) { |
| 726 | ENFORCE_UID(AID_SYSTEM); |
| 727 | ACQUIRE_CRYPT_LOCK; |
| 728 | |
| 729 | const char* res = cryptfs_get_password(); |
| 730 | if (res != nullptr) { |
| 731 | *_aidl_return = res; |
| 732 | } |
| 733 | return ok(); |
| 734 | } |
| 735 | |
| 736 | binder::Status VoldNativeService::fdeClearPassword() { |
| 737 | ENFORCE_UID(AID_SYSTEM); |
| 738 | ACQUIRE_CRYPT_LOCK; |
| 739 | |
| 740 | cryptfs_clear_password(); |
| 741 | return ok(); |
| 742 | } |
| 743 | |
| 744 | binder::Status VoldNativeService::fbeEnable() { |
| 745 | ENFORCE_UID(AID_SYSTEM); |
| 746 | ACQUIRE_CRYPT_LOCK; |
| 747 | |
| 748 | return translateBool(e4crypt_initialize_global_de()); |
| 749 | } |
| 750 | |
| 751 | binder::Status VoldNativeService::mountDefaultEncrypted() { |
| 752 | ENFORCE_UID(AID_SYSTEM); |
| 753 | ACQUIRE_CRYPT_LOCK; |
| 754 | |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 755 | if (!e4crypt_is_native()) { |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 756 | // Spawn as thread so init can issue commands back to vold without |
| 757 | // causing deadlock, usually as a result of prep_data_fs. |
| 758 | std::thread(&cryptfs_mount_default_encrypted).detach(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 759 | } |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 760 | return ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | binder::Status VoldNativeService::initUser0() { |
| 764 | ENFORCE_UID(AID_SYSTEM); |
| 765 | ACQUIRE_CRYPT_LOCK; |
| 766 | |
| 767 | return translateBool(e4crypt_init_user0()); |
| 768 | } |
| 769 | |
| 770 | binder::Status VoldNativeService::isConvertibleToFbe(bool* _aidl_return) { |
| 771 | ENFORCE_UID(AID_SYSTEM); |
| 772 | ACQUIRE_CRYPT_LOCK; |
| 773 | |
| 774 | *_aidl_return = cryptfs_isConvertibleToFBE() != 0; |
| 775 | return ok(); |
| 776 | } |
| 777 | |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 778 | binder::Status VoldNativeService::mountFstab(const std::string& mountPoint) { |
| 779 | ENFORCE_UID(AID_SYSTEM); |
| 780 | ACQUIRE_LOCK; |
| 781 | |
| 782 | return translateBool(e4crypt_mount_metadata_encrypted(mountPoint, false)); |
| 783 | } |
| 784 | |
| 785 | binder::Status VoldNativeService::encryptFstab(const std::string& mountPoint) { |
| 786 | ENFORCE_UID(AID_SYSTEM); |
| 787 | ACQUIRE_LOCK; |
| 788 | |
| 789 | return translateBool(e4crypt_mount_metadata_encrypted(mountPoint, true)); |
| 790 | } |
| 791 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 792 | binder::Status VoldNativeService::createUserKey(int32_t userId, int32_t userSerial, |
| 793 | bool ephemeral) { |
| 794 | ENFORCE_UID(AID_SYSTEM); |
| 795 | ACQUIRE_CRYPT_LOCK; |
| 796 | |
| 797 | return translateBool(e4crypt_vold_create_user_key(userId, userSerial, ephemeral)); |
| 798 | } |
| 799 | |
| 800 | binder::Status VoldNativeService::destroyUserKey(int32_t userId) { |
| 801 | ENFORCE_UID(AID_SYSTEM); |
| 802 | ACQUIRE_CRYPT_LOCK; |
| 803 | |
| 804 | return translateBool(e4crypt_destroy_user_key(userId)); |
| 805 | } |
| 806 | |
| 807 | binder::Status VoldNativeService::addUserKeyAuth(int32_t userId, int32_t userSerial, |
| 808 | const std::string& token, const std::string& secret) { |
| 809 | ENFORCE_UID(AID_SYSTEM); |
| 810 | ACQUIRE_CRYPT_LOCK; |
| 811 | |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 812 | return translateBool(e4crypt_add_user_key_auth(userId, userSerial, token, secret)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | binder::Status VoldNativeService::fixateNewestUserKeyAuth(int32_t userId) { |
| 816 | ENFORCE_UID(AID_SYSTEM); |
| 817 | ACQUIRE_CRYPT_LOCK; |
| 818 | |
| 819 | return translateBool(e4crypt_fixate_newest_user_key_auth(userId)); |
| 820 | } |
| 821 | |
| 822 | binder::Status VoldNativeService::unlockUserKey(int32_t userId, int32_t userSerial, |
| 823 | const std::string& token, const std::string& secret) { |
| 824 | ENFORCE_UID(AID_SYSTEM); |
| 825 | ACQUIRE_CRYPT_LOCK; |
| 826 | |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 827 | return translateBool(e4crypt_unlock_user_key(userId, userSerial, token, secret)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | binder::Status VoldNativeService::lockUserKey(int32_t userId) { |
| 831 | ENFORCE_UID(AID_SYSTEM); |
| 832 | ACQUIRE_CRYPT_LOCK; |
| 833 | |
| 834 | return translateBool(e4crypt_lock_user_key(userId)); |
| 835 | } |
| 836 | |
| 837 | binder::Status VoldNativeService::prepareUserStorage(const std::unique_ptr<std::string>& uuid, |
| 838 | int32_t userId, int32_t userSerial, int32_t flags) { |
| 839 | ENFORCE_UID(AID_SYSTEM); |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 840 | std::string empty_string = ""; |
| 841 | auto uuid_ = uuid ? *uuid : empty_string; |
Paul Crowley | 06f762d | 2017-10-16 10:59:51 -0700 | [diff] [blame] | 842 | CHECK_ARGUMENT_HEX(uuid_); |
| 843 | |
| 844 | ACQUIRE_CRYPT_LOCK; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 845 | return translateBool(e4crypt_prepare_user_storage(uuid_, userId, userSerial, flags)); |
| 846 | } |
| 847 | |
| 848 | binder::Status VoldNativeService::destroyUserStorage(const std::unique_ptr<std::string>& uuid, |
| 849 | int32_t userId, int32_t flags) { |
| 850 | ENFORCE_UID(AID_SYSTEM); |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 851 | std::string empty_string = ""; |
| 852 | auto uuid_ = uuid ? *uuid : empty_string; |
Paul Crowley | 06f762d | 2017-10-16 10:59:51 -0700 | [diff] [blame] | 853 | CHECK_ARGUMENT_HEX(uuid_); |
| 854 | |
| 855 | ACQUIRE_CRYPT_LOCK; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 856 | return translateBool(e4crypt_destroy_user_storage(uuid_, userId, flags)); |
| 857 | } |
| 858 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 859 | } // namespace vold |
| 860 | } // namespace android |