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