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 "Ext4Crypt.h" |
| 28 | #include "MetadataCrypt.h" |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 29 | #include "cryptfs.h" |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 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), |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 86 | reinterpret_cast<int32_t*>(&uid))) { |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 87 | return ok(); |
| 88 | } else { |
| 89 | return exception(binder::Status::EX_SECURITY, |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 90 | StringPrintf("UID %d / PID %d lacks permission %s", uid, pid, permission)); |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 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, |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 100 | StringPrintf("UID %d is not expected UID %d", uid, expectedUid)); |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 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, |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 111 | StringPrintf("ID %s is malformed", id.c_str())); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 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, |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 123 | StringPrintf("Path %s is relative", path.c_str())); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 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, |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 127 | StringPrintf("Path %s is shady", path.c_str())); |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 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, |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 132 | StringPrintf("Path %s is malformed", path.c_str())); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 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, |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 143 | StringPrintf("Hex %s is malformed", hex.c_str())); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | return ok(); |
| 147 | } |
| 148 | |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 149 | #define ENFORCE_UID(uid) \ |
| 150 | { \ |
| 151 | binder::Status status = checkUid((uid)); \ |
| 152 | if (!status.isOk()) { \ |
| 153 | return status; \ |
| 154 | } \ |
| 155 | } |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 156 | |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 157 | #define CHECK_ARGUMENT_ID(id) \ |
| 158 | { \ |
| 159 | binder::Status status = checkArgumentId((id)); \ |
| 160 | if (!status.isOk()) { \ |
| 161 | return status; \ |
| 162 | } \ |
| 163 | } |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 164 | |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 165 | #define CHECK_ARGUMENT_PATH(path) \ |
| 166 | { \ |
| 167 | binder::Status status = checkArgumentPath((path)); \ |
| 168 | if (!status.isOk()) { \ |
| 169 | return status; \ |
| 170 | } \ |
| 171 | } |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 172 | |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 173 | #define CHECK_ARGUMENT_HEX(hex) \ |
| 174 | { \ |
| 175 | binder::Status status = checkArgumentHex((hex)); \ |
| 176 | if (!status.isOk()) { \ |
| 177 | return status; \ |
| 178 | } \ |
| 179 | } |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 180 | |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 181 | #define ACQUIRE_LOCK \ |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 182 | std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getLock()); \ |
| 183 | ATRACE_CALL(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 184 | |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 185 | #define ACQUIRE_CRYPT_LOCK \ |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 186 | std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getCryptLock()); \ |
| 187 | ATRACE_CALL(); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 188 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 189 | } // namespace |
| 190 | |
| 191 | status_t VoldNativeService::start() { |
| 192 | IPCThreadState::self()->disableBackgroundScheduling(true); |
| 193 | status_t ret = BinderService<VoldNativeService>::publish(); |
| 194 | if (ret != android::OK) { |
| 195 | return ret; |
| 196 | } |
| 197 | sp<ProcessState> ps(ProcessState::self()); |
| 198 | ps->startThreadPool(); |
| 199 | ps->giveThreadPoolName(); |
| 200 | return android::OK; |
| 201 | } |
| 202 | |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 203 | status_t VoldNativeService::dump(int fd, const Vector<String16>& /* args */) { |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 204 | auto out = std::fstream(StringPrintf("/proc/self/fd/%d", fd)); |
| 205 | const binder::Status dump_permission = checkPermission(kDump); |
| 206 | if (!dump_permission.isOk()) { |
| 207 | out << dump_permission.toString8() << endl; |
| 208 | return PERMISSION_DENIED; |
| 209 | } |
| 210 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 211 | ACQUIRE_LOCK; |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 212 | out << "vold is happy!" << endl; |
| 213 | out.flush(); |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 214 | return NO_ERROR; |
| 215 | } |
| 216 | |
Jeff Sharkey | 814e9d3 | 2017-09-13 11:49:44 -0600 | [diff] [blame] | 217 | binder::Status VoldNativeService::setListener( |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 218 | const android::sp<android::os::IVoldListener>& listener) { |
Jeff Sharkey | 814e9d3 | 2017-09-13 11:49:44 -0600 | [diff] [blame] | 219 | ENFORCE_UID(AID_SYSTEM); |
| 220 | ACQUIRE_LOCK; |
| 221 | |
| 222 | VolumeManager::Instance()->setListener(listener); |
| 223 | return ok(); |
| 224 | } |
| 225 | |
Jeff Sharkey | cbe69fc | 2017-09-15 16:50:28 -0600 | [diff] [blame] | 226 | binder::Status VoldNativeService::monitor() { |
| 227 | ENFORCE_UID(AID_SYSTEM); |
| 228 | |
| 229 | // Simply acquire/release each lock for watchdog |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 230 | { ACQUIRE_LOCK; } |
| 231 | { ACQUIRE_CRYPT_LOCK; } |
Jeff Sharkey | cbe69fc | 2017-09-15 16:50:28 -0600 | [diff] [blame] | 232 | |
| 233 | return ok(); |
| 234 | } |
| 235 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 236 | binder::Status VoldNativeService::reset() { |
| 237 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 238 | ACQUIRE_LOCK; |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 239 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 240 | return translate(VolumeManager::Instance()->reset()); |
| 241 | } |
| 242 | |
| 243 | binder::Status VoldNativeService::shutdown() { |
| 244 | ENFORCE_UID(AID_SYSTEM); |
| 245 | ACQUIRE_LOCK; |
| 246 | |
| 247 | return translate(VolumeManager::Instance()->shutdown()); |
| 248 | } |
| 249 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 250 | binder::Status VoldNativeService::onUserAdded(int32_t userId, int32_t userSerial) { |
| 251 | ENFORCE_UID(AID_SYSTEM); |
| 252 | ACQUIRE_LOCK; |
| 253 | |
| 254 | return translate(VolumeManager::Instance()->onUserAdded(userId, userSerial)); |
| 255 | } |
| 256 | |
| 257 | binder::Status VoldNativeService::onUserRemoved(int32_t userId) { |
| 258 | ENFORCE_UID(AID_SYSTEM); |
| 259 | ACQUIRE_LOCK; |
| 260 | |
| 261 | return translate(VolumeManager::Instance()->onUserRemoved(userId)); |
| 262 | } |
| 263 | |
| 264 | binder::Status VoldNativeService::onUserStarted(int32_t userId) { |
| 265 | ENFORCE_UID(AID_SYSTEM); |
| 266 | ACQUIRE_LOCK; |
| 267 | |
| 268 | return translate(VolumeManager::Instance()->onUserStarted(userId)); |
| 269 | } |
| 270 | |
| 271 | binder::Status VoldNativeService::onUserStopped(int32_t userId) { |
| 272 | ENFORCE_UID(AID_SYSTEM); |
| 273 | ACQUIRE_LOCK; |
| 274 | |
| 275 | return translate(VolumeManager::Instance()->onUserStopped(userId)); |
| 276 | } |
| 277 | |
Jeff Sharkey | 401b260 | 2017-12-14 22:15:20 -0700 | [diff] [blame] | 278 | binder::Status VoldNativeService::onSecureKeyguardStateChanged(bool isShowing) { |
| 279 | ENFORCE_UID(AID_SYSTEM); |
| 280 | ACQUIRE_LOCK; |
| 281 | |
| 282 | return translate(VolumeManager::Instance()->onSecureKeyguardStateChanged(isShowing)); |
| 283 | } |
| 284 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 285 | binder::Status VoldNativeService::partition(const std::string& diskId, int32_t partitionType, |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 286 | int32_t ratio) { |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 287 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 288 | CHECK_ARGUMENT_ID(diskId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 289 | ACQUIRE_LOCK; |
| 290 | |
| 291 | auto disk = VolumeManager::Instance()->findDisk(diskId); |
| 292 | if (disk == nullptr) { |
| 293 | return error("Failed to find disk " + diskId); |
| 294 | } |
| 295 | switch (partitionType) { |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 296 | case PARTITION_TYPE_PUBLIC: |
| 297 | return translate(disk->partitionPublic()); |
| 298 | case PARTITION_TYPE_PRIVATE: |
| 299 | return translate(disk->partitionPrivate()); |
| 300 | case PARTITION_TYPE_MIXED: |
| 301 | return translate(disk->partitionMixed(ratio)); |
| 302 | default: |
| 303 | return error("Unknown type " + std::to_string(partitionType)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 304 | } |
| 305 | } |
| 306 | |
Jeff Sharkey | 3ce1825 | 2017-10-24 11:08:45 -0600 | [diff] [blame] | 307 | binder::Status VoldNativeService::forgetPartition(const std::string& partGuid, |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 308 | const std::string& fsUuid) { |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 309 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 310 | CHECK_ARGUMENT_HEX(partGuid); |
Jeff Sharkey | 3ce1825 | 2017-10-24 11:08:45 -0600 | [diff] [blame] | 311 | CHECK_ARGUMENT_HEX(fsUuid); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 312 | ACQUIRE_LOCK; |
| 313 | |
Jeff Sharkey | 3ce1825 | 2017-10-24 11:08:45 -0600 | [diff] [blame] | 314 | return translate(VolumeManager::Instance()->forgetPartition(partGuid, fsUuid)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 315 | } |
| 316 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 317 | binder::Status VoldNativeService::mount(const std::string& volId, int32_t mountFlags, |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 318 | int32_t mountUserId) { |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 319 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 320 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 321 | ACQUIRE_LOCK; |
| 322 | |
| 323 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 324 | if (vol == nullptr) { |
| 325 | return error("Failed to find volume " + volId); |
| 326 | } |
| 327 | |
| 328 | vol->setMountFlags(mountFlags); |
| 329 | vol->setMountUserId(mountUserId); |
| 330 | |
| 331 | int res = vol->mount(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 332 | if ((mountFlags & MOUNT_FLAG_PRIMARY) != 0) { |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 333 | VolumeManager::Instance()->setPrimary(vol); |
| 334 | } |
| 335 | return translate(res); |
| 336 | } |
| 337 | |
| 338 | binder::Status VoldNativeService::unmount(const std::string& volId) { |
| 339 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 340 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 341 | ACQUIRE_LOCK; |
| 342 | |
| 343 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 344 | if (vol == nullptr) { |
| 345 | return error("Failed to find volume " + volId); |
| 346 | } |
| 347 | return translate(vol->unmount()); |
| 348 | } |
| 349 | |
| 350 | binder::Status VoldNativeService::format(const std::string& volId, const std::string& fsType) { |
| 351 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 352 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 353 | ACQUIRE_LOCK; |
| 354 | |
| 355 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 356 | if (vol == nullptr) { |
| 357 | return error("Failed to find volume " + volId); |
| 358 | } |
| 359 | return translate(vol->format(fsType)); |
| 360 | } |
| 361 | |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 362 | static binder::Status pathForVolId(const std::string& volId, std::string* path) { |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 363 | if (volId == "private" || volId == "null") { |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 364 | *path = "/data"; |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 365 | } else { |
| 366 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 367 | if (vol == nullptr) { |
| 368 | return error("Failed to find volume " + volId); |
| 369 | } |
| 370 | if (vol->getType() != VolumeBase::Type::kPrivate) { |
| 371 | return error("Volume " + volId + " not private"); |
| 372 | } |
| 373 | if (vol->getState() != VolumeBase::State::kMounted) { |
| 374 | return error("Volume " + volId + " not mounted"); |
| 375 | } |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 376 | *path = vol->getPath(); |
| 377 | if (path->empty()) { |
| 378 | return error("Volume " + volId + " missing path"); |
| 379 | } |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 380 | } |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 381 | return ok(); |
| 382 | } |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 383 | |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 384 | binder::Status VoldNativeService::benchmark( |
| 385 | const std::string& volId, const android::sp<android::os::IVoldTaskListener>& listener) { |
| 386 | ENFORCE_UID(AID_SYSTEM); |
| 387 | CHECK_ARGUMENT_ID(volId); |
| 388 | ACQUIRE_LOCK; |
| 389 | |
| 390 | std::string path; |
| 391 | auto status = pathForVolId(volId, &path); |
| 392 | if (!status.isOk()) return status; |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 393 | |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 394 | std::thread([=]() { android::vold::Benchmark(path, listener); }).detach(); |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 395 | return ok(); |
| 396 | } |
| 397 | |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 398 | binder::Status VoldNativeService::checkEncryption(const std::string& volId) { |
| 399 | ENFORCE_UID(AID_SYSTEM); |
| 400 | CHECK_ARGUMENT_ID(volId); |
| 401 | ACQUIRE_LOCK; |
| 402 | |
| 403 | std::string path; |
| 404 | auto status = pathForVolId(volId, &path); |
| 405 | if (!status.isOk()) return status; |
| 406 | return translate(android::vold::CheckEncryption(path)); |
| 407 | } |
| 408 | |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 409 | binder::Status VoldNativeService::moveStorage( |
| 410 | const std::string& fromVolId, const std::string& toVolId, |
| 411 | const android::sp<android::os::IVoldTaskListener>& listener) { |
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(fromVolId); |
| 414 | CHECK_ARGUMENT_ID(toVolId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 415 | ACQUIRE_LOCK; |
| 416 | |
| 417 | auto fromVol = VolumeManager::Instance()->findVolume(fromVolId); |
| 418 | auto toVol = VolumeManager::Instance()->findVolume(toVolId); |
| 419 | if (fromVol == nullptr) { |
| 420 | return error("Failed to find volume " + fromVolId); |
| 421 | } else if (toVol == nullptr) { |
| 422 | return error("Failed to find volume " + toVolId); |
| 423 | } |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 424 | |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 425 | std::thread([=]() { android::vold::MoveStorage(fromVol, toVol, listener); }).detach(); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 426 | return ok(); |
| 427 | } |
| 428 | |
| 429 | binder::Status VoldNativeService::remountUid(int32_t uid, int32_t remountMode) { |
| 430 | ENFORCE_UID(AID_SYSTEM); |
| 431 | ACQUIRE_LOCK; |
| 432 | |
| 433 | std::string tmp; |
| 434 | switch (remountMode) { |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 435 | case REMOUNT_MODE_NONE: |
| 436 | tmp = "none"; |
| 437 | break; |
| 438 | case REMOUNT_MODE_DEFAULT: |
| 439 | tmp = "default"; |
| 440 | break; |
| 441 | case REMOUNT_MODE_READ: |
| 442 | tmp = "read"; |
| 443 | break; |
| 444 | case REMOUNT_MODE_WRITE: |
| 445 | tmp = "write"; |
| 446 | break; |
| 447 | default: |
| 448 | return error("Unknown mode " + std::to_string(remountMode)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 449 | } |
| 450 | return translate(VolumeManager::Instance()->remountUid(uid, tmp)); |
| 451 | } |
| 452 | |
| 453 | binder::Status VoldNativeService::mkdirs(const std::string& path) { |
| 454 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 455 | CHECK_ARGUMENT_PATH(path); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 456 | ACQUIRE_LOCK; |
| 457 | |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 458 | return translate(VolumeManager::Instance()->mkdirs(path)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 459 | } |
| 460 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 461 | binder::Status VoldNativeService::createObb(const std::string& sourcePath, |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 462 | const std::string& sourceKey, int32_t ownerGid, |
| 463 | std::string* _aidl_return) { |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 464 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 465 | CHECK_ARGUMENT_PATH(sourcePath); |
| 466 | CHECK_ARGUMENT_HEX(sourceKey); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 467 | ACQUIRE_LOCK; |
| 468 | |
| 469 | return translate( |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 470 | VolumeManager::Instance()->createObb(sourcePath, sourceKey, ownerGid, _aidl_return)); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | binder::Status VoldNativeService::destroyObb(const std::string& volId) { |
| 474 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 475 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 476 | ACQUIRE_LOCK; |
| 477 | |
| 478 | return translate(VolumeManager::Instance()->destroyObb(volId)); |
| 479 | } |
| 480 | |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 481 | binder::Status VoldNativeService::fstrim( |
| 482 | int32_t fstrimFlags, const android::sp<android::os::IVoldTaskListener>& listener) { |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 483 | ENFORCE_UID(AID_SYSTEM); |
| 484 | ACQUIRE_LOCK; |
| 485 | |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 486 | std::thread([=]() { android::vold::Trim(listener); }).detach(); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 487 | return ok(); |
| 488 | } |
| 489 | |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 490 | binder::Status VoldNativeService::runIdleMaint( |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 491 | const android::sp<android::os::IVoldTaskListener>& listener) { |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 492 | ENFORCE_UID(AID_SYSTEM); |
| 493 | ACQUIRE_LOCK; |
| 494 | |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 495 | std::thread([=]() { android::vold::RunIdleMaint(listener); }).detach(); |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 496 | return ok(); |
| 497 | } |
| 498 | |
| 499 | binder::Status VoldNativeService::abortIdleMaint( |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 500 | const android::sp<android::os::IVoldTaskListener>& listener) { |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 501 | ENFORCE_UID(AID_SYSTEM); |
| 502 | ACQUIRE_LOCK; |
| 503 | |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 504 | std::thread([=]() { android::vold::AbortIdleMaint(listener); }).detach(); |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 505 | return ok(); |
| 506 | } |
| 507 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 508 | binder::Status VoldNativeService::mountAppFuse(int32_t uid, int32_t pid, int32_t mountId, |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 509 | android::base::unique_fd* _aidl_return) { |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 510 | ENFORCE_UID(AID_SYSTEM); |
| 511 | ACQUIRE_LOCK; |
| 512 | |
| 513 | return translate(VolumeManager::Instance()->mountAppFuse(uid, pid, mountId, _aidl_return)); |
| 514 | } |
| 515 | |
| 516 | binder::Status VoldNativeService::unmountAppFuse(int32_t uid, int32_t pid, int32_t mountId) { |
| 517 | ENFORCE_UID(AID_SYSTEM); |
| 518 | ACQUIRE_LOCK; |
| 519 | |
| 520 | return translate(VolumeManager::Instance()->unmountAppFuse(uid, pid, mountId)); |
| 521 | } |
| 522 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 523 | binder::Status VoldNativeService::fdeCheckPassword(const std::string& password) { |
| 524 | ENFORCE_UID(AID_SYSTEM); |
| 525 | ACQUIRE_CRYPT_LOCK; |
| 526 | |
| 527 | return translate(cryptfs_check_passwd(password.c_str())); |
| 528 | } |
| 529 | |
| 530 | binder::Status VoldNativeService::fdeRestart() { |
| 531 | ENFORCE_UID(AID_SYSTEM); |
| 532 | ACQUIRE_CRYPT_LOCK; |
| 533 | |
| 534 | // Spawn as thread so init can issue commands back to vold without |
| 535 | // causing deadlock, usually as a result of prep_data_fs. |
| 536 | std::thread(&cryptfs_restart).detach(); |
| 537 | return ok(); |
| 538 | } |
| 539 | |
| 540 | binder::Status VoldNativeService::fdeComplete(int32_t* _aidl_return) { |
| 541 | ENFORCE_UID(AID_SYSTEM); |
| 542 | ACQUIRE_CRYPT_LOCK; |
| 543 | |
| 544 | *_aidl_return = cryptfs_crypto_complete(); |
| 545 | return ok(); |
| 546 | } |
| 547 | |
| 548 | static int fdeEnableInternal(int32_t passwordType, const std::string& password, |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 549 | int32_t encryptionFlags) { |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 550 | bool noUi = (encryptionFlags & VoldNativeService::ENCRYPTION_FLAG_NO_UI) != 0; |
| 551 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 552 | for (int tries = 0; tries < 2; ++tries) { |
| 553 | int rc; |
| 554 | if (passwordType == VoldNativeService::PASSWORD_TYPE_DEFAULT) { |
Paul Lawrence | 7ee87cf | 2017-12-22 10:12:06 -0800 | [diff] [blame] | 555 | rc = cryptfs_enable_default(noUi); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 556 | } else { |
Paul Lawrence | 7ee87cf | 2017-12-22 10:12:06 -0800 | [diff] [blame] | 557 | rc = cryptfs_enable(passwordType, password.c_str(), noUi); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | if (rc == 0) { |
| 561 | return 0; |
| 562 | } else if (tries == 0) { |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 563 | KillProcessesWithOpenFiles(DATA_MNT_POINT, SIGKILL); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 564 | } |
| 565 | } |
| 566 | |
| 567 | return -1; |
| 568 | } |
| 569 | |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 570 | binder::Status VoldNativeService::fdeEnable(int32_t passwordType, const std::string& password, |
| 571 | int32_t encryptionFlags) { |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 572 | ENFORCE_UID(AID_SYSTEM); |
| 573 | ACQUIRE_CRYPT_LOCK; |
| 574 | |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 575 | LOG(DEBUG) << "fdeEnable(" << passwordType << ", *, " << encryptionFlags << ")"; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 576 | if (e4crypt_is_native()) { |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 577 | LOG(ERROR) << "e4crypt_is_native, fdeEnable invalid"; |
| 578 | return error("e4crypt_is_native, fdeEnable invalid"); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 579 | } |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 580 | LOG(DEBUG) << "!e4crypt_is_native, spawning fdeEnableInternal"; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 581 | |
| 582 | // Spawn as thread so init can issue commands back to vold without |
| 583 | // causing deadlock, usually as a result of prep_data_fs. |
| 584 | std::thread(&fdeEnableInternal, passwordType, password, encryptionFlags).detach(); |
| 585 | return ok(); |
| 586 | } |
| 587 | |
| 588 | binder::Status VoldNativeService::fdeChangePassword(int32_t passwordType, |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 589 | const std::string& password) { |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 590 | ENFORCE_UID(AID_SYSTEM); |
| 591 | ACQUIRE_CRYPT_LOCK; |
| 592 | |
| 593 | return translate(cryptfs_changepw(passwordType, password.c_str())); |
| 594 | } |
| 595 | |
| 596 | binder::Status VoldNativeService::fdeVerifyPassword(const std::string& password) { |
| 597 | ENFORCE_UID(AID_SYSTEM); |
| 598 | ACQUIRE_CRYPT_LOCK; |
| 599 | |
| 600 | return translate(cryptfs_verify_passwd(password.c_str())); |
| 601 | } |
| 602 | |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 603 | binder::Status VoldNativeService::fdeGetField(const std::string& key, std::string* _aidl_return) { |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 604 | ENFORCE_UID(AID_SYSTEM); |
| 605 | ACQUIRE_CRYPT_LOCK; |
| 606 | |
| 607 | char buf[PROPERTY_VALUE_MAX]; |
| 608 | if (cryptfs_getfield(key.c_str(), buf, sizeof(buf)) != CRYPTO_GETFIELD_OK) { |
| 609 | return error(StringPrintf("Failed to read field %s", key.c_str())); |
| 610 | } else { |
| 611 | *_aidl_return = buf; |
| 612 | return ok(); |
| 613 | } |
| 614 | } |
| 615 | |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 616 | binder::Status VoldNativeService::fdeSetField(const std::string& key, const std::string& value) { |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 617 | ENFORCE_UID(AID_SYSTEM); |
| 618 | ACQUIRE_CRYPT_LOCK; |
| 619 | |
| 620 | return translate(cryptfs_setfield(key.c_str(), value.c_str())); |
| 621 | } |
| 622 | |
| 623 | binder::Status VoldNativeService::fdeGetPasswordType(int32_t* _aidl_return) { |
| 624 | ENFORCE_UID(AID_SYSTEM); |
| 625 | ACQUIRE_CRYPT_LOCK; |
| 626 | |
| 627 | *_aidl_return = cryptfs_get_password_type(); |
| 628 | return ok(); |
| 629 | } |
| 630 | |
| 631 | binder::Status VoldNativeService::fdeGetPassword(std::string* _aidl_return) { |
| 632 | ENFORCE_UID(AID_SYSTEM); |
| 633 | ACQUIRE_CRYPT_LOCK; |
| 634 | |
| 635 | const char* res = cryptfs_get_password(); |
| 636 | if (res != nullptr) { |
| 637 | *_aidl_return = res; |
| 638 | } |
| 639 | return ok(); |
| 640 | } |
| 641 | |
| 642 | binder::Status VoldNativeService::fdeClearPassword() { |
| 643 | ENFORCE_UID(AID_SYSTEM); |
| 644 | ACQUIRE_CRYPT_LOCK; |
| 645 | |
| 646 | cryptfs_clear_password(); |
| 647 | return ok(); |
| 648 | } |
| 649 | |
| 650 | binder::Status VoldNativeService::fbeEnable() { |
| 651 | ENFORCE_UID(AID_SYSTEM); |
| 652 | ACQUIRE_CRYPT_LOCK; |
| 653 | |
| 654 | return translateBool(e4crypt_initialize_global_de()); |
| 655 | } |
| 656 | |
| 657 | binder::Status VoldNativeService::mountDefaultEncrypted() { |
| 658 | ENFORCE_UID(AID_SYSTEM); |
| 659 | ACQUIRE_CRYPT_LOCK; |
| 660 | |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 661 | if (!e4crypt_is_native()) { |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 662 | // Spawn as thread so init can issue commands back to vold without |
| 663 | // causing deadlock, usually as a result of prep_data_fs. |
| 664 | std::thread(&cryptfs_mount_default_encrypted).detach(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 665 | } |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 666 | return ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | binder::Status VoldNativeService::initUser0() { |
| 670 | ENFORCE_UID(AID_SYSTEM); |
| 671 | ACQUIRE_CRYPT_LOCK; |
| 672 | |
| 673 | return translateBool(e4crypt_init_user0()); |
| 674 | } |
| 675 | |
| 676 | binder::Status VoldNativeService::isConvertibleToFbe(bool* _aidl_return) { |
| 677 | ENFORCE_UID(AID_SYSTEM); |
| 678 | ACQUIRE_CRYPT_LOCK; |
| 679 | |
| 680 | *_aidl_return = cryptfs_isConvertibleToFBE() != 0; |
| 681 | return ok(); |
| 682 | } |
| 683 | |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 684 | binder::Status VoldNativeService::mountFstab(const std::string& mountPoint) { |
| 685 | ENFORCE_UID(AID_SYSTEM); |
| 686 | ACQUIRE_LOCK; |
| 687 | |
| 688 | return translateBool(e4crypt_mount_metadata_encrypted(mountPoint, false)); |
| 689 | } |
| 690 | |
| 691 | binder::Status VoldNativeService::encryptFstab(const std::string& mountPoint) { |
| 692 | ENFORCE_UID(AID_SYSTEM); |
| 693 | ACQUIRE_LOCK; |
| 694 | |
| 695 | return translateBool(e4crypt_mount_metadata_encrypted(mountPoint, true)); |
| 696 | } |
| 697 | |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 698 | binder::Status VoldNativeService::createUserKey(int32_t userId, int32_t userSerial, bool ephemeral) { |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 699 | ENFORCE_UID(AID_SYSTEM); |
| 700 | ACQUIRE_CRYPT_LOCK; |
| 701 | |
| 702 | return translateBool(e4crypt_vold_create_user_key(userId, userSerial, ephemeral)); |
| 703 | } |
| 704 | |
| 705 | binder::Status VoldNativeService::destroyUserKey(int32_t userId) { |
| 706 | ENFORCE_UID(AID_SYSTEM); |
| 707 | ACQUIRE_CRYPT_LOCK; |
| 708 | |
| 709 | return translateBool(e4crypt_destroy_user_key(userId)); |
| 710 | } |
| 711 | |
| 712 | binder::Status VoldNativeService::addUserKeyAuth(int32_t userId, int32_t userSerial, |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 713 | const std::string& token, |
| 714 | const std::string& secret) { |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 715 | ENFORCE_UID(AID_SYSTEM); |
| 716 | ACQUIRE_CRYPT_LOCK; |
| 717 | |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 718 | return translateBool(e4crypt_add_user_key_auth(userId, userSerial, token, secret)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | binder::Status VoldNativeService::fixateNewestUserKeyAuth(int32_t userId) { |
| 722 | ENFORCE_UID(AID_SYSTEM); |
| 723 | ACQUIRE_CRYPT_LOCK; |
| 724 | |
| 725 | return translateBool(e4crypt_fixate_newest_user_key_auth(userId)); |
| 726 | } |
| 727 | |
| 728 | binder::Status VoldNativeService::unlockUserKey(int32_t userId, int32_t userSerial, |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 729 | const std::string& token, |
| 730 | const std::string& secret) { |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 731 | ENFORCE_UID(AID_SYSTEM); |
| 732 | ACQUIRE_CRYPT_LOCK; |
| 733 | |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 734 | return translateBool(e4crypt_unlock_user_key(userId, userSerial, token, secret)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | binder::Status VoldNativeService::lockUserKey(int32_t userId) { |
| 738 | ENFORCE_UID(AID_SYSTEM); |
| 739 | ACQUIRE_CRYPT_LOCK; |
| 740 | |
| 741 | return translateBool(e4crypt_lock_user_key(userId)); |
| 742 | } |
| 743 | |
| 744 | binder::Status VoldNativeService::prepareUserStorage(const std::unique_ptr<std::string>& uuid, |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 745 | int32_t userId, int32_t userSerial, |
| 746 | int32_t flags) { |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 747 | ENFORCE_UID(AID_SYSTEM); |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 748 | std::string empty_string = ""; |
| 749 | auto uuid_ = uuid ? *uuid : empty_string; |
Paul Crowley | 06f762d | 2017-10-16 10:59:51 -0700 | [diff] [blame] | 750 | CHECK_ARGUMENT_HEX(uuid_); |
| 751 | |
| 752 | ACQUIRE_CRYPT_LOCK; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 753 | return translateBool(e4crypt_prepare_user_storage(uuid_, userId, userSerial, flags)); |
| 754 | } |
| 755 | |
| 756 | binder::Status VoldNativeService::destroyUserStorage(const std::unique_ptr<std::string>& uuid, |
Paul Crowley | 8915d62 | 2018-09-18 15:14:18 -0700 | [diff] [blame^] | 757 | int32_t userId, int32_t flags) { |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 758 | ENFORCE_UID(AID_SYSTEM); |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 759 | std::string empty_string = ""; |
| 760 | auto uuid_ = uuid ? *uuid : empty_string; |
Paul Crowley | 06f762d | 2017-10-16 10:59:51 -0700 | [diff] [blame] | 761 | CHECK_ARGUMENT_HEX(uuid_); |
| 762 | |
| 763 | ACQUIRE_CRYPT_LOCK; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 764 | return translateBool(e4crypt_destroy_user_storage(uuid_, userId, flags)); |
| 765 | } |
| 766 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 767 | } // namespace vold |
| 768 | } // namespace android |