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