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" |
Paul Crowley | 73be12d | 2020-02-03 12:22:03 -0800 | [diff] [blame] | 20 | |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 21 | #include "Benchmark.h" |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 22 | #include "CheckEncryption.h" |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 23 | #include "Checkpoint.h" |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 24 | #include "FsCrypt.h" |
Paul Crowley | 73be12d | 2020-02-03 12:22:03 -0800 | [diff] [blame] | 25 | #include "IdleMaint.h" |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 26 | #include "MetadataCrypt.h" |
Paul Crowley | 73be12d | 2020-02-03 12:22:03 -0800 | [diff] [blame] | 27 | #include "MoveStorage.h" |
| 28 | #include "Process.h" |
| 29 | #include "VoldUtil.h" |
| 30 | #include "VolumeManager.h" |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 31 | #include "cryptfs.h" |
Paul Crowley | 73be12d | 2020-02-03 12:22:03 -0800 | [diff] [blame] | 32 | |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 33 | #include "incfs_ndk.h" |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 34 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 35 | #include <fstream> |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 36 | #include <thread> |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 37 | |
| 38 | #include <android-base/logging.h> |
| 39 | #include <android-base/stringprintf.h> |
| 40 | #include <android-base/strings.h> |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 41 | #include <fs_mgr.h> |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 42 | #include <fscrypt/fscrypt.h> |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 43 | #include <private/android_filesystem_config.h> |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 44 | #include <utils/Trace.h> |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 45 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 46 | using android::base::StringPrintf; |
| 47 | using std::endl; |
| 48 | |
| 49 | namespace android { |
| 50 | namespace vold { |
| 51 | |
| 52 | namespace { |
| 53 | |
| 54 | constexpr const char* kDump = "android.permission.DUMP"; |
| 55 | |
| 56 | static binder::Status ok() { |
| 57 | return binder::Status::ok(); |
| 58 | } |
| 59 | |
| 60 | static binder::Status exception(uint32_t code, const std::string& msg) { |
| 61 | return binder::Status::fromExceptionCode(code, String8(msg.c_str())); |
| 62 | } |
| 63 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 64 | static binder::Status error(const std::string& msg) { |
| 65 | PLOG(ERROR) << msg; |
| 66 | return binder::Status::fromServiceSpecificError(errno, String8(msg.c_str())); |
| 67 | } |
| 68 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 69 | static binder::Status translate(int status) { |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 70 | if (status == 0) { |
| 71 | return binder::Status::ok(); |
| 72 | } else { |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 73 | return binder::Status::fromServiceSpecificError(status); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 74 | } |
| 75 | } |
| 76 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 77 | static binder::Status translateBool(bool status) { |
| 78 | if (status) { |
| 79 | return binder::Status::ok(); |
| 80 | } else { |
| 81 | return binder::Status::fromServiceSpecificError(status); |
| 82 | } |
| 83 | } |
| 84 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 85 | binder::Status checkPermission(const char* permission) { |
| 86 | pid_t pid; |
| 87 | uid_t uid; |
| 88 | |
| 89 | if (checkCallingPermission(String16(permission), reinterpret_cast<int32_t*>(&pid), |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 90 | reinterpret_cast<int32_t*>(&uid))) { |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 91 | return ok(); |
| 92 | } else { |
| 93 | return exception(binder::Status::EX_SECURITY, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 94 | StringPrintf("UID %d / PID %d lacks permission %s", uid, pid, permission)); |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 98 | binder::Status checkUidOrRoot(uid_t expectedUid) { |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 99 | uid_t uid = IPCThreadState::self()->getCallingUid(); |
| 100 | if (uid == expectedUid || uid == AID_ROOT) { |
| 101 | return ok(); |
| 102 | } else { |
| 103 | return exception(binder::Status::EX_SECURITY, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 104 | StringPrintf("UID %d is not expected UID %d", uid, expectedUid)); |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 105 | } |
| 106 | } |
| 107 | |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 108 | binder::Status checkArgumentId(const std::string& id) { |
| 109 | if (id.empty()) { |
| 110 | return exception(binder::Status::EX_ILLEGAL_ARGUMENT, "Missing ID"); |
| 111 | } |
| 112 | for (const char& c : id) { |
Zim | a438b24 | 2019-09-25 14:37:38 +0100 | [diff] [blame] | 113 | if (!std::isalnum(c) && c != ':' && c != ',' && c != ';') { |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 114 | return exception(binder::Status::EX_ILLEGAL_ARGUMENT, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 115 | StringPrintf("ID %s is malformed", id.c_str())); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 116 | } |
| 117 | } |
| 118 | return ok(); |
| 119 | } |
| 120 | |
| 121 | binder::Status checkArgumentPath(const std::string& path) { |
| 122 | if (path.empty()) { |
| 123 | return exception(binder::Status::EX_ILLEGAL_ARGUMENT, "Missing path"); |
| 124 | } |
| 125 | if (path[0] != '/') { |
| 126 | return exception(binder::Status::EX_ILLEGAL_ARGUMENT, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 127 | StringPrintf("Path %s is relative", path.c_str())); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 128 | } |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 129 | if ((path + '/').find("/../") != std::string::npos) { |
| 130 | return exception(binder::Status::EX_ILLEGAL_ARGUMENT, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 131 | StringPrintf("Path %s is shady", path.c_str())); |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 132 | } |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 133 | for (const char& c : path) { |
| 134 | if (c == '\0' || c == '\n') { |
| 135 | return exception(binder::Status::EX_ILLEGAL_ARGUMENT, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 136 | StringPrintf("Path %s is malformed", path.c_str())); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | return ok(); |
| 140 | } |
| 141 | |
| 142 | binder::Status checkArgumentHex(const std::string& hex) { |
| 143 | // Empty hex strings are allowed |
| 144 | for (const char& c : hex) { |
| 145 | if (!std::isxdigit(c) && c != ':' && c != '-') { |
| 146 | return exception(binder::Status::EX_ILLEGAL_ARGUMENT, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 147 | StringPrintf("Hex %s is malformed", hex.c_str())); |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | return ok(); |
| 151 | } |
| 152 | |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 153 | #define ENFORCE_SYSTEM_OR_ROOT \ |
| 154 | { \ |
| 155 | binder::Status status = checkUidOrRoot(AID_SYSTEM); \ |
| 156 | if (!status.isOk()) { \ |
| 157 | return status; \ |
| 158 | } \ |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 159 | } |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 160 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 161 | #define CHECK_ARGUMENT_ID(id) \ |
| 162 | { \ |
| 163 | binder::Status status = checkArgumentId((id)); \ |
| 164 | if (!status.isOk()) { \ |
| 165 | return status; \ |
| 166 | } \ |
| 167 | } |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 168 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 169 | #define CHECK_ARGUMENT_PATH(path) \ |
| 170 | { \ |
| 171 | binder::Status status = checkArgumentPath((path)); \ |
| 172 | if (!status.isOk()) { \ |
| 173 | return status; \ |
| 174 | } \ |
| 175 | } |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 176 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 177 | #define CHECK_ARGUMENT_HEX(hex) \ |
| 178 | { \ |
| 179 | binder::Status status = checkArgumentHex((hex)); \ |
| 180 | if (!status.isOk()) { \ |
| 181 | return status; \ |
| 182 | } \ |
| 183 | } |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 184 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 185 | #define ACQUIRE_LOCK \ |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 186 | std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getLock()); \ |
| 187 | ATRACE_CALL(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 188 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 189 | #define ACQUIRE_CRYPT_LOCK \ |
Jeff Sharkey | 67b8c49 | 2017-09-21 17:08:43 -0600 | [diff] [blame] | 190 | std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getCryptLock()); \ |
| 191 | ATRACE_CALL(); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 192 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 193 | } // namespace |
| 194 | |
| 195 | status_t VoldNativeService::start() { |
| 196 | IPCThreadState::self()->disableBackgroundScheduling(true); |
| 197 | status_t ret = BinderService<VoldNativeService>::publish(); |
| 198 | if (ret != android::OK) { |
| 199 | return ret; |
| 200 | } |
| 201 | sp<ProcessState> ps(ProcessState::self()); |
| 202 | ps->startThreadPool(); |
| 203 | ps->giveThreadPoolName(); |
| 204 | return android::OK; |
| 205 | } |
| 206 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 207 | status_t VoldNativeService::dump(int fd, const Vector<String16>& /* args */) { |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 208 | auto out = std::fstream(StringPrintf("/proc/self/fd/%d", fd)); |
| 209 | const binder::Status dump_permission = checkPermission(kDump); |
| 210 | if (!dump_permission.isOk()) { |
| 211 | out << dump_permission.toString8() << endl; |
| 212 | return PERMISSION_DENIED; |
| 213 | } |
| 214 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 215 | ACQUIRE_LOCK; |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 216 | out << "vold is happy!" << endl; |
| 217 | out.flush(); |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 218 | return NO_ERROR; |
| 219 | } |
| 220 | |
Jeff Sharkey | 814e9d3 | 2017-09-13 11:49:44 -0600 | [diff] [blame] | 221 | binder::Status VoldNativeService::setListener( |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 222 | const android::sp<android::os::IVoldListener>& listener) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 223 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 814e9d3 | 2017-09-13 11:49:44 -0600 | [diff] [blame] | 224 | ACQUIRE_LOCK; |
| 225 | |
| 226 | VolumeManager::Instance()->setListener(listener); |
| 227 | return ok(); |
| 228 | } |
| 229 | |
Jeff Sharkey | cbe69fc | 2017-09-15 16:50:28 -0600 | [diff] [blame] | 230 | binder::Status VoldNativeService::monitor() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 231 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | cbe69fc | 2017-09-15 16:50:28 -0600 | [diff] [blame] | 232 | |
| 233 | // Simply acquire/release each lock for watchdog |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 234 | { ACQUIRE_LOCK; } |
| 235 | { ACQUIRE_CRYPT_LOCK; } |
Jeff Sharkey | cbe69fc | 2017-09-15 16:50:28 -0600 | [diff] [blame] | 236 | |
| 237 | return ok(); |
| 238 | } |
| 239 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 240 | binder::Status VoldNativeService::reset() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 241 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 242 | ACQUIRE_LOCK; |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 243 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 244 | return translate(VolumeManager::Instance()->reset()); |
| 245 | } |
| 246 | |
| 247 | binder::Status VoldNativeService::shutdown() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 248 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 249 | ACQUIRE_LOCK; |
| 250 | |
| 251 | return translate(VolumeManager::Instance()->shutdown()); |
| 252 | } |
| 253 | |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 254 | binder::Status VoldNativeService::onUserAdded(int32_t userId, int32_t userSerial) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 255 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 256 | ACQUIRE_LOCK; |
| 257 | |
| 258 | return translate(VolumeManager::Instance()->onUserAdded(userId, userSerial)); |
| 259 | } |
| 260 | |
| 261 | binder::Status VoldNativeService::onUserRemoved(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 262 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 263 | ACQUIRE_LOCK; |
| 264 | |
| 265 | return translate(VolumeManager::Instance()->onUserRemoved(userId)); |
| 266 | } |
| 267 | |
Sudheer Shanka | 5fceb48 | 2019-04-29 10:46:35 -0700 | [diff] [blame] | 268 | binder::Status VoldNativeService::onUserStarted(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 269 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 270 | ACQUIRE_LOCK; |
| 271 | |
Sudheer Shanka | 5fceb48 | 2019-04-29 10:46:35 -0700 | [diff] [blame] | 272 | return translate(VolumeManager::Instance()->onUserStarted(userId)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | binder::Status VoldNativeService::onUserStopped(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 276 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 277 | ACQUIRE_LOCK; |
| 278 | |
| 279 | return translate(VolumeManager::Instance()->onUserStopped(userId)); |
| 280 | } |
| 281 | |
Sudheer Shanka | d484aa9 | 2018-07-31 10:07:34 -0700 | [diff] [blame] | 282 | binder::Status VoldNativeService::addAppIds(const std::vector<std::string>& packageNames, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 283 | const std::vector<int32_t>& appIds) { |
Sudheer Shanka | 5fceb48 | 2019-04-29 10:46:35 -0700 | [diff] [blame] | 284 | return ok(); |
Sudheer Shanka | d484aa9 | 2018-07-31 10:07:34 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Sudheer Shanka | d484aa9 | 2018-07-31 10:07:34 -0700 | [diff] [blame] | 287 | binder::Status VoldNativeService::addSandboxIds(const std::vector<int32_t>& appIds, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 288 | const std::vector<std::string>& sandboxIds) { |
Sudheer Shanka | 5fceb48 | 2019-04-29 10:46:35 -0700 | [diff] [blame] | 289 | return ok(); |
Sudheer Shanka | d484aa9 | 2018-07-31 10:07:34 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Jeff Sharkey | 401b260 | 2017-12-14 22:15:20 -0700 | [diff] [blame] | 292 | binder::Status VoldNativeService::onSecureKeyguardStateChanged(bool isShowing) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 293 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 401b260 | 2017-12-14 22:15:20 -0700 | [diff] [blame] | 294 | ACQUIRE_LOCK; |
| 295 | |
| 296 | return translate(VolumeManager::Instance()->onSecureKeyguardStateChanged(isShowing)); |
| 297 | } |
| 298 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 299 | binder::Status VoldNativeService::partition(const std::string& diskId, int32_t partitionType, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 300 | int32_t ratio) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 301 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 302 | CHECK_ARGUMENT_ID(diskId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 303 | ACQUIRE_LOCK; |
| 304 | |
| 305 | auto disk = VolumeManager::Instance()->findDisk(diskId); |
| 306 | if (disk == nullptr) { |
| 307 | return error("Failed to find disk " + diskId); |
| 308 | } |
| 309 | switch (partitionType) { |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 310 | case PARTITION_TYPE_PUBLIC: |
| 311 | return translate(disk->partitionPublic()); |
| 312 | case PARTITION_TYPE_PRIVATE: |
| 313 | return translate(disk->partitionPrivate()); |
| 314 | case PARTITION_TYPE_MIXED: |
| 315 | return translate(disk->partitionMixed(ratio)); |
| 316 | default: |
| 317 | return error("Unknown type " + std::to_string(partitionType)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | |
Jeff Sharkey | 3ce1825 | 2017-10-24 11:08:45 -0600 | [diff] [blame] | 321 | binder::Status VoldNativeService::forgetPartition(const std::string& partGuid, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 322 | const std::string& fsUuid) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 323 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 324 | CHECK_ARGUMENT_HEX(partGuid); |
Jeff Sharkey | 3ce1825 | 2017-10-24 11:08:45 -0600 | [diff] [blame] | 325 | CHECK_ARGUMENT_HEX(fsUuid); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 326 | ACQUIRE_LOCK; |
| 327 | |
Jeff Sharkey | 3ce1825 | 2017-10-24 11:08:45 -0600 | [diff] [blame] | 328 | return translate(VolumeManager::Instance()->forgetPartition(partGuid, fsUuid)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 329 | } |
| 330 | |
Zim | 5048b4b | 2019-11-19 09:16:03 +0000 | [diff] [blame] | 331 | binder::Status VoldNativeService::mount( |
| 332 | const std::string& volId, int32_t mountFlags, int32_t mountUserId, |
| 333 | const android::sp<android::os::IVoldMountCallback>& callback) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 334 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 335 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 336 | ACQUIRE_LOCK; |
| 337 | |
| 338 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 339 | if (vol == nullptr) { |
| 340 | return error("Failed to find volume " + volId); |
| 341 | } |
| 342 | |
| 343 | vol->setMountFlags(mountFlags); |
| 344 | vol->setMountUserId(mountUserId); |
| 345 | |
Zim | 5048b4b | 2019-11-19 09:16:03 +0000 | [diff] [blame] | 346 | vol->setMountCallback(callback); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 347 | int res = vol->mount(); |
Zim | 5048b4b | 2019-11-19 09:16:03 +0000 | [diff] [blame] | 348 | vol->setMountCallback(nullptr); |
| 349 | |
Sudheer Shanka | 40ab674 | 2018-09-18 13:07:45 -0700 | [diff] [blame] | 350 | if (res != OK) { |
| 351 | return translate(res); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 352 | } |
Zim | 3623a21 | 2019-07-19 16:46:53 +0100 | [diff] [blame] | 353 | |
Sudheer Shanka | 40ab674 | 2018-09-18 13:07:45 -0700 | [diff] [blame] | 354 | if ((mountFlags & MOUNT_FLAG_PRIMARY) != 0) { |
| 355 | res = VolumeManager::Instance()->setPrimary(vol); |
| 356 | if (res != OK) { |
| 357 | return translate(res); |
| 358 | } |
| 359 | } |
| 360 | return translate(OK); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | binder::Status VoldNativeService::unmount(const std::string& volId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 364 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 365 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 366 | ACQUIRE_LOCK; |
| 367 | |
| 368 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 369 | if (vol == nullptr) { |
| 370 | return error("Failed to find volume " + volId); |
| 371 | } |
| 372 | return translate(vol->unmount()); |
| 373 | } |
| 374 | |
| 375 | binder::Status VoldNativeService::format(const std::string& volId, const std::string& fsType) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 376 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 377 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 378 | ACQUIRE_LOCK; |
| 379 | |
| 380 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 381 | if (vol == nullptr) { |
| 382 | return error("Failed to find volume " + volId); |
| 383 | } |
| 384 | return translate(vol->format(fsType)); |
| 385 | } |
| 386 | |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 387 | static binder::Status pathForVolId(const std::string& volId, std::string* path) { |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 388 | if (volId == "private" || volId == "null") { |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 389 | *path = "/data"; |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 390 | } else { |
| 391 | auto vol = VolumeManager::Instance()->findVolume(volId); |
| 392 | if (vol == nullptr) { |
| 393 | return error("Failed to find volume " + volId); |
| 394 | } |
| 395 | if (vol->getType() != VolumeBase::Type::kPrivate) { |
| 396 | return error("Volume " + volId + " not private"); |
| 397 | } |
| 398 | if (vol->getState() != VolumeBase::State::kMounted) { |
| 399 | return error("Volume " + volId + " not mounted"); |
| 400 | } |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 401 | *path = vol->getPath(); |
| 402 | if (path->empty()) { |
| 403 | return error("Volume " + volId + " missing path"); |
| 404 | } |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 405 | } |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 406 | return ok(); |
| 407 | } |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 408 | |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 409 | binder::Status VoldNativeService::benchmark( |
| 410 | const std::string& volId, const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 411 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 412 | CHECK_ARGUMENT_ID(volId); |
| 413 | ACQUIRE_LOCK; |
| 414 | |
| 415 | std::string path; |
| 416 | auto status = pathForVolId(volId, &path); |
| 417 | if (!status.isOk()) return status; |
Jeff Sharkey | 52f7a91 | 2017-09-15 12:57:44 -0600 | [diff] [blame] | 418 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 419 | std::thread([=]() { android::vold::Benchmark(path, listener); }).detach(); |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 420 | return ok(); |
| 421 | } |
| 422 | |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 423 | binder::Status VoldNativeService::checkEncryption(const std::string& volId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 424 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 2048a28 | 2017-06-15 09:59:43 -0600 | [diff] [blame] | 425 | CHECK_ARGUMENT_ID(volId); |
| 426 | ACQUIRE_LOCK; |
| 427 | |
| 428 | std::string path; |
| 429 | auto status = pathForVolId(volId, &path); |
| 430 | if (!status.isOk()) return status; |
| 431 | return translate(android::vold::CheckEncryption(path)); |
| 432 | } |
| 433 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 434 | binder::Status VoldNativeService::moveStorage( |
| 435 | const std::string& fromVolId, const std::string& toVolId, |
| 436 | const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 437 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 438 | CHECK_ARGUMENT_ID(fromVolId); |
| 439 | CHECK_ARGUMENT_ID(toVolId); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 440 | ACQUIRE_LOCK; |
| 441 | |
| 442 | auto fromVol = VolumeManager::Instance()->findVolume(fromVolId); |
| 443 | auto toVol = VolumeManager::Instance()->findVolume(toVolId); |
| 444 | if (fromVol == nullptr) { |
| 445 | return error("Failed to find volume " + fromVolId); |
| 446 | } else if (toVol == nullptr) { |
| 447 | return error("Failed to find volume " + toVolId); |
| 448 | } |
Jeff Sharkey | 01a0e7f | 2017-10-17 16:06:32 -0600 | [diff] [blame] | 449 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 450 | std::thread([=]() { android::vold::MoveStorage(fromVol, toVol, listener); }).detach(); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 451 | return ok(); |
| 452 | } |
| 453 | |
| 454 | binder::Status VoldNativeService::remountUid(int32_t uid, int32_t remountMode) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 455 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 456 | ACQUIRE_LOCK; |
| 457 | |
Sudheer Shanka | 817b911 | 2018-12-13 17:40:28 -0800 | [diff] [blame] | 458 | return translate(VolumeManager::Instance()->remountUid(uid, remountMode)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 459 | } |
| 460 | |
Ricky Wai | 6b12257 | 2020-02-28 16:30:47 +0000 | [diff] [blame] | 461 | binder::Status VoldNativeService::remountAppStorageDirs(int uid, int pid, |
| 462 | const std::vector<std::string>& packageNames) { |
| 463 | ENFORCE_SYSTEM_OR_ROOT; |
| 464 | ACQUIRE_LOCK; |
| 465 | |
| 466 | return translate(VolumeManager::Instance()->remountAppStorageDirs(uid, pid, packageNames)); |
| 467 | } |
| 468 | |
Martijn Coenen | 8a68a07 | 2020-02-12 15:29:02 +0100 | [diff] [blame] | 469 | binder::Status VoldNativeService::setupAppDir(const std::string& path, int32_t appUid) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 470 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 471 | CHECK_ARGUMENT_PATH(path); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 472 | ACQUIRE_LOCK; |
| 473 | |
Martijn Coenen | 8a68a07 | 2020-02-12 15:29:02 +0100 | [diff] [blame] | 474 | return translate(VolumeManager::Instance()->setupAppDir(path, appUid)); |
Jeff Sharkey | 9462bdd | 2017-09-07 15:27:28 -0600 | [diff] [blame] | 475 | } |
| 476 | |
Martijn Coenen | 816f4d9 | 2020-02-18 15:06:37 +0100 | [diff] [blame] | 477 | binder::Status VoldNativeService::fixupAppDir(const std::string& path, int32_t appUid) { |
| 478 | ENFORCE_SYSTEM_OR_ROOT; |
| 479 | CHECK_ARGUMENT_PATH(path); |
| 480 | ACQUIRE_LOCK; |
| 481 | |
| 482 | return translate(VolumeManager::Instance()->fixupAppDir(path, appUid)); |
| 483 | } |
| 484 | |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 485 | binder::Status VoldNativeService::createObb(const std::string& sourcePath, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 486 | const std::string& sourceKey, int32_t ownerGid, |
| 487 | std::string* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 488 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 489 | CHECK_ARGUMENT_PATH(sourcePath); |
| 490 | CHECK_ARGUMENT_HEX(sourceKey); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 491 | ACQUIRE_LOCK; |
| 492 | |
| 493 | return translate( |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 494 | VolumeManager::Instance()->createObb(sourcePath, sourceKey, ownerGid, _aidl_return)); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | binder::Status VoldNativeService::destroyObb(const std::string& volId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 498 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | ec4fda2 | 2017-09-12 13:19:24 -0600 | [diff] [blame] | 499 | CHECK_ARGUMENT_ID(volId); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 500 | ACQUIRE_LOCK; |
| 501 | |
| 502 | return translate(VolumeManager::Instance()->destroyObb(volId)); |
| 503 | } |
| 504 | |
Risan | 82e90de | 2020-02-04 16:07:21 +0900 | [diff] [blame] | 505 | binder::Status VoldNativeService::createStubVolume(const std::string& sourcePath, |
| 506 | const std::string& mountPath, |
| 507 | const std::string& fsType, |
| 508 | const std::string& fsUuid, |
| 509 | const std::string& fsLabel, int32_t flags, |
| 510 | std::string* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 511 | ENFORCE_SYSTEM_OR_ROOT; |
Risan | 8c9f332 | 2018-10-29 08:52:56 +0900 | [diff] [blame] | 512 | CHECK_ARGUMENT_PATH(sourcePath); |
| 513 | CHECK_ARGUMENT_PATH(mountPath); |
| 514 | CHECK_ARGUMENT_HEX(fsUuid); |
| 515 | // Label limitation seems to be different between fs (including allowed characters), so checking |
| 516 | // is quite meaningless. |
| 517 | ACQUIRE_LOCK; |
| 518 | |
Risan | 82e90de | 2020-02-04 16:07:21 +0900 | [diff] [blame] | 519 | return translate(VolumeManager::Instance()->createStubVolume( |
| 520 | sourcePath, mountPath, fsType, fsUuid, fsLabel, flags, _aidl_return)); |
Risan | 8c9f332 | 2018-10-29 08:52:56 +0900 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | binder::Status VoldNativeService::destroyStubVolume(const std::string& volId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 524 | ENFORCE_SYSTEM_OR_ROOT; |
Risan | 8c9f332 | 2018-10-29 08:52:56 +0900 | [diff] [blame] | 525 | CHECK_ARGUMENT_ID(volId); |
| 526 | ACQUIRE_LOCK; |
| 527 | |
| 528 | return translate(VolumeManager::Instance()->destroyStubVolume(volId)); |
| 529 | } |
| 530 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 531 | binder::Status VoldNativeService::fstrim( |
| 532 | int32_t fstrimFlags, const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 533 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 534 | ACQUIRE_LOCK; |
| 535 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 536 | std::thread([=]() { android::vold::Trim(listener); }).detach(); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 537 | return ok(); |
| 538 | } |
| 539 | |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 540 | binder::Status VoldNativeService::runIdleMaint( |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 541 | const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 542 | ENFORCE_SYSTEM_OR_ROOT; |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 543 | ACQUIRE_LOCK; |
| 544 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 545 | std::thread([=]() { android::vold::RunIdleMaint(listener); }).detach(); |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 546 | return ok(); |
| 547 | } |
| 548 | |
| 549 | binder::Status VoldNativeService::abortIdleMaint( |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 550 | const android::sp<android::os::IVoldTaskListener>& listener) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 551 | ENFORCE_SYSTEM_OR_ROOT; |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 552 | ACQUIRE_LOCK; |
| 553 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 554 | std::thread([=]() { android::vold::AbortIdleMaint(listener); }).detach(); |
Jin Qian | a370c14 | 2017-10-17 15:41:45 -0700 | [diff] [blame] | 555 | return ok(); |
| 556 | } |
| 557 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 558 | binder::Status VoldNativeService::mountAppFuse(int32_t uid, int32_t mountId, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 559 | android::base::unique_fd* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 560 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 561 | ACQUIRE_LOCK; |
| 562 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 563 | return translate(VolumeManager::Instance()->mountAppFuse(uid, mountId, _aidl_return)); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 564 | } |
| 565 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 566 | binder::Status VoldNativeService::unmountAppFuse(int32_t uid, int32_t mountId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 567 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 568 | ACQUIRE_LOCK; |
| 569 | |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 570 | return translate(VolumeManager::Instance()->unmountAppFuse(uid, mountId)); |
| 571 | } |
| 572 | |
| 573 | binder::Status VoldNativeService::openAppFuseFile(int32_t uid, int32_t mountId, int32_t fileId, |
| 574 | int32_t flags, |
| 575 | android::base::unique_fd* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 576 | ENFORCE_SYSTEM_OR_ROOT; |
Risan | 8f6198d | 2018-10-26 20:56:45 -0600 | [diff] [blame] | 577 | ACQUIRE_LOCK; |
| 578 | |
| 579 | int fd = VolumeManager::Instance()->openAppFuseFile(uid, mountId, fileId, flags); |
| 580 | if (fd == -1) { |
| 581 | return error("Failed to open AppFuse file for uid: " + std::to_string(uid) + |
| 582 | " mountId: " + std::to_string(mountId) + " fileId: " + std::to_string(fileId) + |
| 583 | " flags: " + std::to_string(flags)); |
| 584 | } |
| 585 | |
| 586 | *_aidl_return = android::base::unique_fd(fd); |
| 587 | return ok(); |
Jeff Sharkey | 11c2d38 | 2017-09-11 10:32:01 -0600 | [diff] [blame] | 588 | } |
| 589 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 590 | binder::Status VoldNativeService::fdeCheckPassword(const std::string& password) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 591 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 592 | ACQUIRE_CRYPT_LOCK; |
| 593 | |
| 594 | return translate(cryptfs_check_passwd(password.c_str())); |
| 595 | } |
| 596 | |
| 597 | binder::Status VoldNativeService::fdeRestart() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 598 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 599 | ACQUIRE_CRYPT_LOCK; |
| 600 | |
| 601 | // Spawn as thread so init can issue commands back to vold without |
| 602 | // causing deadlock, usually as a result of prep_data_fs. |
| 603 | std::thread(&cryptfs_restart).detach(); |
| 604 | return ok(); |
| 605 | } |
| 606 | |
| 607 | binder::Status VoldNativeService::fdeComplete(int32_t* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 608 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 609 | ACQUIRE_CRYPT_LOCK; |
| 610 | |
| 611 | *_aidl_return = cryptfs_crypto_complete(); |
| 612 | return ok(); |
| 613 | } |
| 614 | |
| 615 | static int fdeEnableInternal(int32_t passwordType, const std::string& password, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 616 | int32_t encryptionFlags) { |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 617 | bool noUi = (encryptionFlags & VoldNativeService::ENCRYPTION_FLAG_NO_UI) != 0; |
| 618 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 619 | for (int tries = 0; tries < 2; ++tries) { |
| 620 | int rc; |
| 621 | if (passwordType == VoldNativeService::PASSWORD_TYPE_DEFAULT) { |
Paul Lawrence | 7ee87cf | 2017-12-22 10:12:06 -0800 | [diff] [blame] | 622 | rc = cryptfs_enable_default(noUi); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 623 | } else { |
Paul Lawrence | 7ee87cf | 2017-12-22 10:12:06 -0800 | [diff] [blame] | 624 | rc = cryptfs_enable(passwordType, password.c_str(), noUi); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | if (rc == 0) { |
| 628 | return 0; |
| 629 | } else if (tries == 0) { |
Jeff Sharkey | 3472e52 | 2017-10-06 18:02:53 -0600 | [diff] [blame] | 630 | KillProcessesWithOpenFiles(DATA_MNT_POINT, SIGKILL); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 631 | } |
| 632 | } |
| 633 | |
| 634 | return -1; |
| 635 | } |
| 636 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 637 | binder::Status VoldNativeService::fdeEnable(int32_t passwordType, const std::string& password, |
| 638 | int32_t encryptionFlags) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 639 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 640 | ACQUIRE_CRYPT_LOCK; |
| 641 | |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 642 | LOG(DEBUG) << "fdeEnable(" << passwordType << ", *, " << encryptionFlags << ")"; |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 643 | if (fscrypt_is_native()) { |
| 644 | LOG(ERROR) << "fscrypt_is_native, fdeEnable invalid"; |
| 645 | return error("fscrypt_is_native, fdeEnable invalid"); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 646 | } |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 647 | LOG(DEBUG) << "!fscrypt_is_native, spawning fdeEnableInternal"; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 648 | |
| 649 | // Spawn as thread so init can issue commands back to vold without |
| 650 | // causing deadlock, usually as a result of prep_data_fs. |
| 651 | std::thread(&fdeEnableInternal, passwordType, password, encryptionFlags).detach(); |
| 652 | return ok(); |
| 653 | } |
| 654 | |
| 655 | binder::Status VoldNativeService::fdeChangePassword(int32_t passwordType, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 656 | const std::string& password) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 657 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 658 | ACQUIRE_CRYPT_LOCK; |
| 659 | |
| 660 | return translate(cryptfs_changepw(passwordType, password.c_str())); |
| 661 | } |
| 662 | |
| 663 | binder::Status VoldNativeService::fdeVerifyPassword(const std::string& password) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 664 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 665 | ACQUIRE_CRYPT_LOCK; |
| 666 | |
| 667 | return translate(cryptfs_verify_passwd(password.c_str())); |
| 668 | } |
| 669 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 670 | binder::Status VoldNativeService::fdeGetField(const std::string& key, std::string* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 671 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 672 | ACQUIRE_CRYPT_LOCK; |
| 673 | |
| 674 | char buf[PROPERTY_VALUE_MAX]; |
| 675 | if (cryptfs_getfield(key.c_str(), buf, sizeof(buf)) != CRYPTO_GETFIELD_OK) { |
| 676 | return error(StringPrintf("Failed to read field %s", key.c_str())); |
| 677 | } else { |
| 678 | *_aidl_return = buf; |
| 679 | return ok(); |
| 680 | } |
| 681 | } |
| 682 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 683 | binder::Status VoldNativeService::fdeSetField(const std::string& key, const std::string& value) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 684 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 685 | ACQUIRE_CRYPT_LOCK; |
| 686 | |
| 687 | return translate(cryptfs_setfield(key.c_str(), value.c_str())); |
| 688 | } |
| 689 | |
| 690 | binder::Status VoldNativeService::fdeGetPasswordType(int32_t* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 691 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 692 | ACQUIRE_CRYPT_LOCK; |
| 693 | |
| 694 | *_aidl_return = cryptfs_get_password_type(); |
| 695 | return ok(); |
| 696 | } |
| 697 | |
| 698 | binder::Status VoldNativeService::fdeGetPassword(std::string* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 699 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 700 | ACQUIRE_CRYPT_LOCK; |
| 701 | |
| 702 | const char* res = cryptfs_get_password(); |
| 703 | if (res != nullptr) { |
| 704 | *_aidl_return = res; |
| 705 | } |
| 706 | return ok(); |
| 707 | } |
| 708 | |
| 709 | binder::Status VoldNativeService::fdeClearPassword() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 710 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 711 | ACQUIRE_CRYPT_LOCK; |
| 712 | |
| 713 | cryptfs_clear_password(); |
| 714 | return ok(); |
| 715 | } |
| 716 | |
| 717 | binder::Status VoldNativeService::fbeEnable() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 718 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 719 | ACQUIRE_CRYPT_LOCK; |
| 720 | |
Paul Crowley | c8a3ef3 | 2019-09-11 15:00:08 -0700 | [diff] [blame] | 721 | return translateBool(fscrypt_initialize_systemwide_keys()); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | binder::Status VoldNativeService::mountDefaultEncrypted() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 725 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 726 | ACQUIRE_CRYPT_LOCK; |
| 727 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 728 | if (!fscrypt_is_native()) { |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 729 | // Spawn as thread so init can issue commands back to vold without |
| 730 | // causing deadlock, usually as a result of prep_data_fs. |
| 731 | std::thread(&cryptfs_mount_default_encrypted).detach(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 732 | } |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 733 | return ok(); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | binder::Status VoldNativeService::initUser0() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 737 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 738 | ACQUIRE_CRYPT_LOCK; |
| 739 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 740 | return translateBool(fscrypt_init_user0()); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | binder::Status VoldNativeService::isConvertibleToFbe(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 744 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 745 | ACQUIRE_CRYPT_LOCK; |
| 746 | |
| 747 | *_aidl_return = cryptfs_isConvertibleToFBE() != 0; |
| 748 | return ok(); |
| 749 | } |
| 750 | |
Paul Lawrence | 236e5e8 | 2019-06-25 14:44:33 -0700 | [diff] [blame] | 751 | binder::Status VoldNativeService::mountFstab(const std::string& blkDevice, |
| 752 | const std::string& mountPoint) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 753 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 754 | ACQUIRE_LOCK; |
| 755 | |
Paul Lawrence | 236e5e8 | 2019-06-25 14:44:33 -0700 | [diff] [blame] | 756 | return translateBool(fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, false)); |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 757 | } |
| 758 | |
Paul Lawrence | 236e5e8 | 2019-06-25 14:44:33 -0700 | [diff] [blame] | 759 | binder::Status VoldNativeService::encryptFstab(const std::string& blkDevice, |
| 760 | const std::string& mountPoint) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 761 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 762 | ACQUIRE_LOCK; |
| 763 | |
Paul Lawrence | 236e5e8 | 2019-06-25 14:44:33 -0700 | [diff] [blame] | 764 | return translateBool(fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, true)); |
Paul Crowley | 0fd2626 | 2018-01-30 09:48:19 -0800 | [diff] [blame] | 765 | } |
| 766 | |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 767 | binder::Status VoldNativeService::createUserKey(int32_t userId, int32_t userSerial, bool ephemeral) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 768 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 769 | ACQUIRE_CRYPT_LOCK; |
| 770 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 771 | return translateBool(fscrypt_vold_create_user_key(userId, userSerial, ephemeral)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | binder::Status VoldNativeService::destroyUserKey(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 775 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 776 | ACQUIRE_CRYPT_LOCK; |
| 777 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 778 | return translateBool(fscrypt_destroy_user_key(userId)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | binder::Status VoldNativeService::addUserKeyAuth(int32_t userId, int32_t userSerial, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 782 | const std::string& token, |
| 783 | const std::string& secret) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 784 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 785 | ACQUIRE_CRYPT_LOCK; |
| 786 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 787 | return translateBool(fscrypt_add_user_key_auth(userId, userSerial, token, secret)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 788 | } |
| 789 | |
Barani Muthukumaran | 9ad51ad | 2019-10-31 22:59:34 -0700 | [diff] [blame] | 790 | binder::Status VoldNativeService::clearUserKeyAuth(int32_t userId, int32_t userSerial, |
| 791 | const std::string& token, |
| 792 | const std::string& secret) { |
| 793 | ENFORCE_SYSTEM_OR_ROOT; |
| 794 | ACQUIRE_CRYPT_LOCK; |
| 795 | |
| 796 | return translateBool(fscrypt_clear_user_key_auth(userId, userSerial, token, secret)); |
| 797 | } |
| 798 | |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 799 | binder::Status VoldNativeService::fixateNewestUserKeyAuth(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 800 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 801 | ACQUIRE_CRYPT_LOCK; |
| 802 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 803 | return translateBool(fscrypt_fixate_newest_user_key_auth(userId)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | binder::Status VoldNativeService::unlockUserKey(int32_t userId, int32_t userSerial, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 807 | const std::string& token, |
| 808 | const std::string& secret) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 809 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 810 | ACQUIRE_CRYPT_LOCK; |
| 811 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 812 | return translateBool(fscrypt_unlock_user_key(userId, userSerial, token, secret)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | binder::Status VoldNativeService::lockUserKey(int32_t userId) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 816 | ENFORCE_SYSTEM_OR_ROOT; |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 817 | ACQUIRE_CRYPT_LOCK; |
| 818 | |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 819 | return translateBool(fscrypt_lock_user_key(userId)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | binder::Status VoldNativeService::prepareUserStorage(const std::unique_ptr<std::string>& uuid, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 823 | int32_t userId, int32_t userSerial, |
| 824 | int32_t flags) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 825 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 826 | std::string empty_string = ""; |
| 827 | auto uuid_ = uuid ? *uuid : empty_string; |
Paul Crowley | 06f762d | 2017-10-16 10:59:51 -0700 | [diff] [blame] | 828 | CHECK_ARGUMENT_HEX(uuid_); |
| 829 | |
| 830 | ACQUIRE_CRYPT_LOCK; |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 831 | return translateBool(fscrypt_prepare_user_storage(uuid_, userId, userSerial, flags)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | binder::Status VoldNativeService::destroyUserStorage(const std::unique_ptr<std::string>& uuid, |
Paul Crowley | edf7a4e | 2018-09-18 15:14:18 -0700 | [diff] [blame] | 835 | int32_t userId, int32_t flags) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 836 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Crowley | 3b71fc5 | 2017-10-09 10:55:21 -0700 | [diff] [blame] | 837 | std::string empty_string = ""; |
| 838 | auto uuid_ = uuid ? *uuid : empty_string; |
Paul Crowley | 06f762d | 2017-10-16 10:59:51 -0700 | [diff] [blame] | 839 | CHECK_ARGUMENT_HEX(uuid_); |
| 840 | |
| 841 | ACQUIRE_CRYPT_LOCK; |
Eric Biggers | a701c45 | 2018-10-23 13:06:55 -0700 | [diff] [blame] | 842 | return translateBool(fscrypt_destroy_user_storage(uuid_, userId, flags)); |
Jeff Sharkey | 83b559c | 2017-09-12 16:30:52 -0600 | [diff] [blame] | 843 | } |
| 844 | |
Sudheer Shanka | fa6a174 | 2018-10-04 16:26:22 -0700 | [diff] [blame] | 845 | binder::Status VoldNativeService::prepareSandboxForApp(const std::string& packageName, |
| 846 | int32_t appId, const std::string& sandboxId, |
| 847 | int32_t userId) { |
Sudheer Shanka | 5fceb48 | 2019-04-29 10:46:35 -0700 | [diff] [blame] | 848 | return ok(); |
Sudheer Shanka | fa6a174 | 2018-10-04 16:26:22 -0700 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | binder::Status VoldNativeService::destroySandboxForApp(const std::string& packageName, |
Sudheer Shanka | 69bc40f | 2018-10-25 11:06:55 -0700 | [diff] [blame] | 852 | const std::string& sandboxId, |
Sudheer Shanka | fa6a174 | 2018-10-04 16:26:22 -0700 | [diff] [blame] | 853 | int32_t userId) { |
Sudheer Shanka | 5fceb48 | 2019-04-29 10:46:35 -0700 | [diff] [blame] | 854 | return ok(); |
Sudheer Shanka | c756209 | 2018-08-24 10:20:56 -0700 | [diff] [blame] | 855 | } |
| 856 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 857 | binder::Status VoldNativeService::startCheckpoint(int32_t retry) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 858 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 859 | ACQUIRE_LOCK; |
| 860 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 861 | return cp_startCheckpoint(retry); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 862 | } |
| 863 | |
Daniel Rosenberg | d399249 | 2018-10-02 17:40:44 -0700 | [diff] [blame] | 864 | binder::Status VoldNativeService::needsRollback(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 865 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | d399249 | 2018-10-02 17:40:44 -0700 | [diff] [blame] | 866 | ACQUIRE_LOCK; |
| 867 | |
| 868 | *_aidl_return = cp_needsRollback(); |
| 869 | return ok(); |
| 870 | } |
| 871 | |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 872 | binder::Status VoldNativeService::needsCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 873 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 874 | ACQUIRE_LOCK; |
| 875 | |
| 876 | *_aidl_return = cp_needsCheckpoint(); |
| 877 | return ok(); |
| 878 | } |
| 879 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 880 | binder::Status VoldNativeService::commitChanges() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 881 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 882 | ACQUIRE_LOCK; |
| 883 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 884 | return cp_commitChanges(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 885 | } |
| 886 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 887 | binder::Status VoldNativeService::prepareCheckpoint() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 888 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 889 | ACQUIRE_LOCK; |
| 890 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 891 | return cp_prepareCheckpoint(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 892 | } |
| 893 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 894 | binder::Status VoldNativeService::restoreCheckpoint(const std::string& mountPoint) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 895 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Lawrence | 1abb2fe | 2018-09-21 10:49:57 -0700 | [diff] [blame] | 896 | CHECK_ARGUMENT_PATH(mountPoint); |
| 897 | ACQUIRE_LOCK; |
| 898 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 899 | return cp_restoreCheckpoint(mountPoint); |
Paul Lawrence | 1abb2fe | 2018-09-21 10:49:57 -0700 | [diff] [blame] | 900 | } |
| 901 | |
Daniel Rosenberg | dda5981 | 2019-03-06 17:45:17 -0800 | [diff] [blame] | 902 | binder::Status VoldNativeService::restoreCheckpointPart(const std::string& mountPoint, int count) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 903 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | dda5981 | 2019-03-06 17:45:17 -0800 | [diff] [blame] | 904 | CHECK_ARGUMENT_PATH(mountPoint); |
| 905 | ACQUIRE_LOCK; |
| 906 | |
| 907 | return cp_restoreCheckpoint(mountPoint, count); |
| 908 | } |
| 909 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 910 | binder::Status VoldNativeService::markBootAttempt() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 911 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 912 | ACQUIRE_LOCK; |
| 913 | |
Daniel Rosenberg | e334aab | 2018-10-10 18:52:04 -0700 | [diff] [blame] | 914 | return cp_markBootAttempt(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 915 | } |
| 916 | |
Daniel Rosenberg | a59e439 | 2019-03-20 17:02:47 -0700 | [diff] [blame] | 917 | binder::Status VoldNativeService::abortChanges(const std::string& message, bool retry) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 918 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 919 | ACQUIRE_LOCK; |
| 920 | |
Daniel Rosenberg | a59e439 | 2019-03-20 17:02:47 -0700 | [diff] [blame] | 921 | cp_abortChanges(message, retry); |
| 922 | return ok(); |
Daniel Rosenberg | 4f68471 | 2018-08-28 01:58:49 -0700 | [diff] [blame] | 923 | } |
| 924 | |
Daniel Rosenberg | 9b667fb | 2019-01-22 17:27:25 -0800 | [diff] [blame] | 925 | binder::Status VoldNativeService::supportsCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 926 | ENFORCE_SYSTEM_OR_ROOT; |
Daniel Rosenberg | 9b667fb | 2019-01-22 17:27:25 -0800 | [diff] [blame] | 927 | ACQUIRE_LOCK; |
| 928 | |
| 929 | return cp_supportsCheckpoint(*_aidl_return); |
| 930 | } |
| 931 | |
Paul Lawrence | c5c79c5 | 2019-03-18 13:36:40 -0700 | [diff] [blame] | 932 | binder::Status VoldNativeService::supportsBlockCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 933 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Lawrence | c5c79c5 | 2019-03-18 13:36:40 -0700 | [diff] [blame] | 934 | ACQUIRE_LOCK; |
| 935 | |
| 936 | return cp_supportsBlockCheckpoint(*_aidl_return); |
| 937 | } |
| 938 | |
| 939 | binder::Status VoldNativeService::supportsFileCheckpoint(bool* _aidl_return) { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 940 | ENFORCE_SYSTEM_OR_ROOT; |
Paul Lawrence | c5c79c5 | 2019-03-18 13:36:40 -0700 | [diff] [blame] | 941 | ACQUIRE_LOCK; |
| 942 | |
| 943 | return cp_supportsFileCheckpoint(*_aidl_return); |
| 944 | } |
| 945 | |
Nikita Ioffe | a5798fc | 2019-10-11 16:38:21 +0100 | [diff] [blame] | 946 | binder::Status VoldNativeService::resetCheckpoint() { |
Nikita Ioffe | 5d85bf3 | 2019-10-23 17:19:13 +0100 | [diff] [blame] | 947 | ENFORCE_SYSTEM_OR_ROOT; |
Nikita Ioffe | a5798fc | 2019-10-11 16:38:21 +0100 | [diff] [blame] | 948 | ACQUIRE_LOCK; |
| 949 | |
| 950 | cp_resetCheckpoint(); |
| 951 | return ok(); |
| 952 | } |
| 953 | |
Yurii Zubrytskyi | 3497cb5 | 2020-01-10 11:54:06 -0800 | [diff] [blame] | 954 | binder::Status VoldNativeService::incFsEnabled(bool* _aidl_return) { |
| 955 | *_aidl_return = IncFs_IsEnabled(); |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 956 | return ok(); |
| 957 | } |
| 958 | |
| 959 | binder::Status VoldNativeService::mountIncFs( |
Yurii Zubrytskyi | 3497cb5 | 2020-01-10 11:54:06 -0800 | [diff] [blame] | 960 | const std::string& backingPath, const std::string& targetDir, int32_t flags, |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 961 | ::android::os::incremental::IncrementalFileSystemControlParcel* _aidl_return) { |
Yurii Zubrytskyi | 3497cb5 | 2020-01-10 11:54:06 -0800 | [diff] [blame] | 962 | auto result = IncFs_Mount(backingPath.c_str(), targetDir.c_str(), |
| 963 | {.flags = IncFsMountFlags(flags), |
| 964 | .defaultReadTimeoutMs = INCFS_DEFAULT_READ_TIMEOUT_MS, |
| 965 | .readLogBufferPages = 4}); |
| 966 | if (result.cmd < 0) { |
| 967 | return translate(result.cmd); |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 968 | } |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 969 | using unique_fd = ::android::base::unique_fd; |
Yurii Zubrytskyi | 3497cb5 | 2020-01-10 11:54:06 -0800 | [diff] [blame] | 970 | _aidl_return->cmd.reset(unique_fd(result.cmd)); |
| 971 | _aidl_return->pendingReads.reset(unique_fd(result.pendingReads)); |
| 972 | if (result.logs >= 0) { |
| 973 | _aidl_return->log.reset(unique_fd(result.logs)); |
Songchun Fan | ab55cec | 2019-12-02 10:50:12 -0800 | [diff] [blame] | 974 | } |
| 975 | return ok(); |
| 976 | } |
| 977 | |
| 978 | binder::Status VoldNativeService::unmountIncFs(const std::string& dir) { |
| 979 | return translate(IncFs_Unmount(dir.c_str())); |
| 980 | } |
| 981 | |
| 982 | binder::Status VoldNativeService::bindMount(const std::string& sourceDir, |
| 983 | const std::string& targetDir) { |
| 984 | return translate(IncFs_BindMount(sourceDir.c_str(), targetDir.c_str())); |
| 985 | } |
| 986 | |
Jeff Sharkey | 068c6be | 2017-09-06 13:47:40 -0600 | [diff] [blame] | 987 | } // namespace vold |
| 988 | } // namespace android |