2017-09-06 21:47:40 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2017-09-22 01:08:43 +02:00
|
|
|
#define ATRACE_TAG ATRACE_TAG_PACKAGE_MANAGER
|
|
|
|
|
2017-09-06 21:47:40 +02:00
|
|
|
#include "VoldNativeService.h"
|
2020-02-03 21:22:03 +01:00
|
|
|
|
2017-10-18 00:06:32 +02:00
|
|
|
#include "Benchmark.h"
|
2017-06-15 17:59:43 +02:00
|
|
|
#include "CheckEncryption.h"
|
2020-02-03 21:22:03 +01:00
|
|
|
#include "Checkpoint.h"
|
|
|
|
#include "FsCrypt.h"
|
2017-06-15 17:59:43 +02:00
|
|
|
#include "IdleMaint.h"
|
2020-02-03 21:22:03 +01:00
|
|
|
#include "MetadataCrypt.h"
|
2017-10-18 00:06:32 +02:00
|
|
|
#include "MoveStorage.h"
|
2017-09-13 00:30:52 +02:00
|
|
|
#include "Process.h"
|
2020-02-03 21:22:03 +01:00
|
|
|
#include "VoldUtil.h"
|
2017-06-15 17:59:43 +02:00
|
|
|
#include "VolumeManager.h"
|
2018-09-19 00:14:18 +02:00
|
|
|
#include "cryptfs.h"
|
2020-02-03 21:22:03 +01:00
|
|
|
|
2019-12-02 19:50:12 +01:00
|
|
|
#include "incfs_ndk.h"
|
2017-09-13 00:30:52 +02:00
|
|
|
|
2017-09-06 21:47:40 +02:00
|
|
|
#include <fstream>
|
2017-10-18 00:06:32 +02:00
|
|
|
#include <thread>
|
2017-09-06 21:47:40 +02:00
|
|
|
|
|
|
|
#include <android-base/logging.h>
|
|
|
|
#include <android-base/stringprintf.h>
|
|
|
|
#include <android-base/strings.h>
|
2017-09-11 18:32:01 +02:00
|
|
|
#include <fs_mgr.h>
|
2018-10-23 22:06:55 +02:00
|
|
|
#include <fscrypt/fscrypt.h>
|
2017-09-06 21:47:40 +02:00
|
|
|
#include <private/android_filesystem_config.h>
|
2017-09-22 01:08:43 +02:00
|
|
|
#include <utils/Trace.h>
|
2017-09-06 21:47:40 +02:00
|
|
|
|
|
|
|
using android::base::StringPrintf;
|
|
|
|
using std::endl;
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
namespace vold {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr const char* kDump = "android.permission.DUMP";
|
|
|
|
|
|
|
|
static binder::Status ok() {
|
|
|
|
return binder::Status::ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
static binder::Status exception(uint32_t code, const std::string& msg) {
|
|
|
|
return binder::Status::fromExceptionCode(code, String8(msg.c_str()));
|
|
|
|
}
|
|
|
|
|
2017-09-07 23:27:28 +02:00
|
|
|
static binder::Status error(const std::string& msg) {
|
|
|
|
PLOG(ERROR) << msg;
|
|
|
|
return binder::Status::fromServiceSpecificError(errno, String8(msg.c_str()));
|
|
|
|
}
|
|
|
|
|
2017-09-13 00:30:52 +02:00
|
|
|
static binder::Status translate(int status) {
|
2017-09-07 23:27:28 +02:00
|
|
|
if (status == 0) {
|
|
|
|
return binder::Status::ok();
|
|
|
|
} else {
|
2017-09-11 18:32:01 +02:00
|
|
|
return binder::Status::fromServiceSpecificError(status);
|
2017-09-07 23:27:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-13 00:30:52 +02:00
|
|
|
static binder::Status translateBool(bool status) {
|
|
|
|
if (status) {
|
|
|
|
return binder::Status::ok();
|
|
|
|
} else {
|
|
|
|
return binder::Status::fromServiceSpecificError(status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-06 21:47:40 +02:00
|
|
|
binder::Status checkPermission(const char* permission) {
|
|
|
|
pid_t pid;
|
|
|
|
uid_t uid;
|
|
|
|
|
|
|
|
if (checkCallingPermission(String16(permission), reinterpret_cast<int32_t*>(&pid),
|
2018-09-19 00:14:18 +02:00
|
|
|
reinterpret_cast<int32_t*>(&uid))) {
|
2017-09-06 21:47:40 +02:00
|
|
|
return ok();
|
|
|
|
} else {
|
|
|
|
return exception(binder::Status::EX_SECURITY,
|
2018-09-19 00:14:18 +02:00
|
|
|
StringPrintf("UID %d / PID %d lacks permission %s", uid, pid, permission));
|
2017-09-06 21:47:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-23 18:19:13 +02:00
|
|
|
binder::Status checkUidOrRoot(uid_t expectedUid) {
|
2017-09-06 21:47:40 +02:00
|
|
|
uid_t uid = IPCThreadState::self()->getCallingUid();
|
|
|
|
if (uid == expectedUid || uid == AID_ROOT) {
|
|
|
|
return ok();
|
|
|
|
} else {
|
|
|
|
return exception(binder::Status::EX_SECURITY,
|
2018-09-19 00:14:18 +02:00
|
|
|
StringPrintf("UID %d is not expected UID %d", uid, expectedUid));
|
2017-09-06 21:47:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-12 21:19:24 +02:00
|
|
|
binder::Status checkArgumentId(const std::string& id) {
|
|
|
|
if (id.empty()) {
|
|
|
|
return exception(binder::Status::EX_ILLEGAL_ARGUMENT, "Missing ID");
|
|
|
|
}
|
|
|
|
for (const char& c : id) {
|
2019-09-25 15:37:38 +02:00
|
|
|
if (!std::isalnum(c) && c != ':' && c != ',' && c != ';') {
|
2017-09-12 21:19:24 +02:00
|
|
|
return exception(binder::Status::EX_ILLEGAL_ARGUMENT,
|
2018-09-19 00:14:18 +02:00
|
|
|
StringPrintf("ID %s is malformed", id.c_str()));
|
2017-09-12 21:19:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status checkArgumentPath(const std::string& path) {
|
|
|
|
if (path.empty()) {
|
|
|
|
return exception(binder::Status::EX_ILLEGAL_ARGUMENT, "Missing path");
|
|
|
|
}
|
|
|
|
if (path[0] != '/') {
|
|
|
|
return exception(binder::Status::EX_ILLEGAL_ARGUMENT,
|
2018-09-19 00:14:18 +02:00
|
|
|
StringPrintf("Path %s is relative", path.c_str()));
|
2017-09-12 21:19:24 +02:00
|
|
|
}
|
2017-10-18 00:06:32 +02:00
|
|
|
if ((path + '/').find("/../") != std::string::npos) {
|
|
|
|
return exception(binder::Status::EX_ILLEGAL_ARGUMENT,
|
2018-09-19 00:14:18 +02:00
|
|
|
StringPrintf("Path %s is shady", path.c_str()));
|
2017-10-18 00:06:32 +02:00
|
|
|
}
|
2017-09-12 21:19:24 +02:00
|
|
|
for (const char& c : path) {
|
|
|
|
if (c == '\0' || c == '\n') {
|
|
|
|
return exception(binder::Status::EX_ILLEGAL_ARGUMENT,
|
2018-09-19 00:14:18 +02:00
|
|
|
StringPrintf("Path %s is malformed", path.c_str()));
|
2017-09-12 21:19:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status checkArgumentHex(const std::string& hex) {
|
|
|
|
// Empty hex strings are allowed
|
|
|
|
for (const char& c : hex) {
|
|
|
|
if (!std::isxdigit(c) && c != ':' && c != '-') {
|
|
|
|
return exception(binder::Status::EX_ILLEGAL_ARGUMENT,
|
2018-09-19 00:14:18 +02:00
|
|
|
StringPrintf("Hex %s is malformed", hex.c_str()));
|
2017-09-12 21:19:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ok();
|
|
|
|
}
|
|
|
|
|
2019-10-23 18:19:13 +02:00
|
|
|
#define ENFORCE_SYSTEM_OR_ROOT \
|
|
|
|
{ \
|
|
|
|
binder::Status status = checkUidOrRoot(AID_SYSTEM); \
|
|
|
|
if (!status.isOk()) { \
|
|
|
|
return status; \
|
|
|
|
} \
|
2018-09-19 00:14:18 +02:00
|
|
|
}
|
2017-09-06 21:47:40 +02:00
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
#define CHECK_ARGUMENT_ID(id) \
|
|
|
|
{ \
|
|
|
|
binder::Status status = checkArgumentId((id)); \
|
|
|
|
if (!status.isOk()) { \
|
|
|
|
return status; \
|
|
|
|
} \
|
|
|
|
}
|
2017-09-12 21:19:24 +02:00
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
#define CHECK_ARGUMENT_PATH(path) \
|
|
|
|
{ \
|
|
|
|
binder::Status status = checkArgumentPath((path)); \
|
|
|
|
if (!status.isOk()) { \
|
|
|
|
return status; \
|
|
|
|
} \
|
|
|
|
}
|
2017-09-12 21:19:24 +02:00
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
#define CHECK_ARGUMENT_HEX(hex) \
|
|
|
|
{ \
|
|
|
|
binder::Status status = checkArgumentHex((hex)); \
|
|
|
|
if (!status.isOk()) { \
|
|
|
|
return status; \
|
|
|
|
} \
|
|
|
|
}
|
2017-09-12 21:19:24 +02:00
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
#define ACQUIRE_LOCK \
|
2017-09-22 01:08:43 +02:00
|
|
|
std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getLock()); \
|
|
|
|
ATRACE_CALL();
|
2017-09-13 00:30:52 +02:00
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
#define ACQUIRE_CRYPT_LOCK \
|
2017-09-22 01:08:43 +02:00
|
|
|
std::lock_guard<std::mutex> lock(VolumeManager::Instance()->getCryptLock()); \
|
|
|
|
ATRACE_CALL();
|
2017-09-07 23:27:28 +02:00
|
|
|
|
2017-09-06 21:47:40 +02:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
status_t VoldNativeService::start() {
|
|
|
|
IPCThreadState::self()->disableBackgroundScheduling(true);
|
|
|
|
status_t ret = BinderService<VoldNativeService>::publish();
|
|
|
|
if (ret != android::OK) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
sp<ProcessState> ps(ProcessState::self());
|
|
|
|
ps->startThreadPool();
|
|
|
|
ps->giveThreadPoolName();
|
|
|
|
return android::OK;
|
|
|
|
}
|
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
status_t VoldNativeService::dump(int fd, const Vector<String16>& /* args */) {
|
2017-09-06 21:47:40 +02:00
|
|
|
auto out = std::fstream(StringPrintf("/proc/self/fd/%d", fd));
|
|
|
|
const binder::Status dump_permission = checkPermission(kDump);
|
|
|
|
if (!dump_permission.isOk()) {
|
|
|
|
out << dump_permission.toString8() << endl;
|
|
|
|
return PERMISSION_DENIED;
|
|
|
|
}
|
|
|
|
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
2017-09-06 21:47:40 +02:00
|
|
|
out << "vold is happy!" << endl;
|
|
|
|
out.flush();
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2017-09-13 19:49:44 +02:00
|
|
|
binder::Status VoldNativeService::setListener(
|
2018-09-19 00:14:18 +02:00
|
|
|
const android::sp<android::os::IVoldListener>& listener) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 19:49:44 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
VolumeManager::Instance()->setListener(listener);
|
|
|
|
return ok();
|
|
|
|
}
|
|
|
|
|
2017-09-16 00:50:28 +02:00
|
|
|
binder::Status VoldNativeService::monitor() {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-16 00:50:28 +02:00
|
|
|
|
|
|
|
// Simply acquire/release each lock for watchdog
|
2018-09-19 00:14:18 +02:00
|
|
|
{ ACQUIRE_LOCK; }
|
|
|
|
{ ACQUIRE_CRYPT_LOCK; }
|
2017-09-16 00:50:28 +02:00
|
|
|
|
|
|
|
return ok();
|
|
|
|
}
|
|
|
|
|
2017-09-06 21:47:40 +02:00
|
|
|
binder::Status VoldNativeService::reset() {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return translate(VolumeManager::Instance()->reset());
|
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::shutdown() {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return translate(VolumeManager::Instance()->shutdown());
|
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::onUserAdded(int32_t userId, int32_t userSerial) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return translate(VolumeManager::Instance()->onUserAdded(userId, userSerial));
|
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::onUserRemoved(int32_t userId) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return translate(VolumeManager::Instance()->onUserRemoved(userId));
|
|
|
|
}
|
|
|
|
|
2019-04-29 19:46:35 +02:00
|
|
|
binder::Status VoldNativeService::onUserStarted(int32_t userId) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2019-04-29 19:46:35 +02:00
|
|
|
return translate(VolumeManager::Instance()->onUserStarted(userId));
|
2017-09-07 23:27:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::onUserStopped(int32_t userId) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return translate(VolumeManager::Instance()->onUserStopped(userId));
|
|
|
|
}
|
|
|
|
|
2018-07-31 19:07:34 +02:00
|
|
|
binder::Status VoldNativeService::addAppIds(const std::vector<std::string>& packageNames,
|
2018-09-19 00:14:18 +02:00
|
|
|
const std::vector<int32_t>& appIds) {
|
2019-04-29 19:46:35 +02:00
|
|
|
return ok();
|
2018-07-31 19:07:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::addSandboxIds(const std::vector<int32_t>& appIds,
|
2018-09-19 00:14:18 +02:00
|
|
|
const std::vector<std::string>& sandboxIds) {
|
2019-04-29 19:46:35 +02:00
|
|
|
return ok();
|
2018-07-31 19:07:34 +02:00
|
|
|
}
|
|
|
|
|
2017-12-15 06:15:20 +01:00
|
|
|
binder::Status VoldNativeService::onSecureKeyguardStateChanged(bool isShowing) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-12-15 06:15:20 +01:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return translate(VolumeManager::Instance()->onSecureKeyguardStateChanged(isShowing));
|
|
|
|
}
|
|
|
|
|
2017-09-11 18:32:01 +02:00
|
|
|
binder::Status VoldNativeService::partition(const std::string& diskId, int32_t partitionType,
|
2018-09-19 00:14:18 +02:00
|
|
|
int32_t ratio) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-12 21:19:24 +02:00
|
|
|
CHECK_ARGUMENT_ID(diskId);
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
auto disk = VolumeManager::Instance()->findDisk(diskId);
|
|
|
|
if (disk == nullptr) {
|
|
|
|
return error("Failed to find disk " + diskId);
|
|
|
|
}
|
|
|
|
switch (partitionType) {
|
2018-09-19 00:14:18 +02:00
|
|
|
case PARTITION_TYPE_PUBLIC:
|
|
|
|
return translate(disk->partitionPublic());
|
|
|
|
case PARTITION_TYPE_PRIVATE:
|
|
|
|
return translate(disk->partitionPrivate());
|
|
|
|
case PARTITION_TYPE_MIXED:
|
|
|
|
return translate(disk->partitionMixed(ratio));
|
|
|
|
default:
|
|
|
|
return error("Unknown type " + std::to_string(partitionType));
|
2017-09-07 23:27:28 +02:00
|
|
|
}
|
|
|
|
}
|
2017-09-06 21:47:40 +02:00
|
|
|
|
2017-10-24 19:08:45 +02:00
|
|
|
binder::Status VoldNativeService::forgetPartition(const std::string& partGuid,
|
2018-09-19 00:14:18 +02:00
|
|
|
const std::string& fsUuid) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-12 21:19:24 +02:00
|
|
|
CHECK_ARGUMENT_HEX(partGuid);
|
2017-10-24 19:08:45 +02:00
|
|
|
CHECK_ARGUMENT_HEX(fsUuid);
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2017-10-24 19:08:45 +02:00
|
|
|
return translate(VolumeManager::Instance()->forgetPartition(partGuid, fsUuid));
|
2017-09-07 23:27:28 +02:00
|
|
|
}
|
|
|
|
|
2019-11-19 10:16:03 +01:00
|
|
|
binder::Status VoldNativeService::mount(
|
|
|
|
const std::string& volId, int32_t mountFlags, int32_t mountUserId,
|
|
|
|
const android::sp<android::os::IVoldMountCallback>& callback) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-12 21:19:24 +02:00
|
|
|
CHECK_ARGUMENT_ID(volId);
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
auto vol = VolumeManager::Instance()->findVolume(volId);
|
|
|
|
if (vol == nullptr) {
|
|
|
|
return error("Failed to find volume " + volId);
|
|
|
|
}
|
|
|
|
|
|
|
|
vol->setMountFlags(mountFlags);
|
|
|
|
vol->setMountUserId(mountUserId);
|
|
|
|
|
2019-11-19 10:16:03 +01:00
|
|
|
vol->setMountCallback(callback);
|
2017-09-07 23:27:28 +02:00
|
|
|
int res = vol->mount();
|
2019-11-19 10:16:03 +01:00
|
|
|
vol->setMountCallback(nullptr);
|
|
|
|
|
2018-09-18 22:07:45 +02:00
|
|
|
if (res != OK) {
|
|
|
|
return translate(res);
|
|
|
|
}
|
2019-07-19 17:46:53 +02:00
|
|
|
|
2017-09-13 00:30:52 +02:00
|
|
|
if ((mountFlags & MOUNT_FLAG_PRIMARY) != 0) {
|
2018-09-18 22:07:45 +02:00
|
|
|
res = VolumeManager::Instance()->setPrimary(vol);
|
|
|
|
if (res != OK) {
|
|
|
|
return translate(res);
|
|
|
|
}
|
2017-09-07 23:27:28 +02:00
|
|
|
}
|
2018-09-18 22:07:45 +02:00
|
|
|
return translate(OK);
|
2017-09-07 23:27:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::unmount(const std::string& volId) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-12 21:19:24 +02:00
|
|
|
CHECK_ARGUMENT_ID(volId);
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
auto vol = VolumeManager::Instance()->findVolume(volId);
|
|
|
|
if (vol == nullptr) {
|
|
|
|
return error("Failed to find volume " + volId);
|
|
|
|
}
|
|
|
|
return translate(vol->unmount());
|
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::format(const std::string& volId, const std::string& fsType) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-12 21:19:24 +02:00
|
|
|
CHECK_ARGUMENT_ID(volId);
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
auto vol = VolumeManager::Instance()->findVolume(volId);
|
|
|
|
if (vol == nullptr) {
|
|
|
|
return error("Failed to find volume " + volId);
|
|
|
|
}
|
|
|
|
return translate(vol->format(fsType));
|
|
|
|
}
|
|
|
|
|
2017-06-15 17:59:43 +02:00
|
|
|
static binder::Status pathForVolId(const std::string& volId, std::string* path) {
|
2017-09-15 20:57:44 +02:00
|
|
|
if (volId == "private" || volId == "null") {
|
2017-06-15 17:59:43 +02:00
|
|
|
*path = "/data";
|
2017-09-15 20:57:44 +02:00
|
|
|
} else {
|
|
|
|
auto vol = VolumeManager::Instance()->findVolume(volId);
|
|
|
|
if (vol == nullptr) {
|
|
|
|
return error("Failed to find volume " + volId);
|
|
|
|
}
|
|
|
|
if (vol->getType() != VolumeBase::Type::kPrivate) {
|
|
|
|
return error("Volume " + volId + " not private");
|
|
|
|
}
|
|
|
|
if (vol->getState() != VolumeBase::State::kMounted) {
|
|
|
|
return error("Volume " + volId + " not mounted");
|
|
|
|
}
|
2017-06-15 17:59:43 +02:00
|
|
|
*path = vol->getPath();
|
|
|
|
if (path->empty()) {
|
|
|
|
return error("Volume " + volId + " missing path");
|
|
|
|
}
|
2017-09-15 20:57:44 +02:00
|
|
|
}
|
2017-06-15 17:59:43 +02:00
|
|
|
return ok();
|
|
|
|
}
|
2017-09-15 20:57:44 +02:00
|
|
|
|
2017-06-15 17:59:43 +02:00
|
|
|
binder::Status VoldNativeService::benchmark(
|
|
|
|
const std::string& volId, const android::sp<android::os::IVoldTaskListener>& listener) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-06-15 17:59:43 +02:00
|
|
|
CHECK_ARGUMENT_ID(volId);
|
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
std::string path;
|
|
|
|
auto status = pathForVolId(volId, &path);
|
|
|
|
if (!status.isOk()) return status;
|
2017-09-15 20:57:44 +02:00
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
std::thread([=]() { android::vold::Benchmark(path, listener); }).detach();
|
2017-09-07 23:27:28 +02:00
|
|
|
return ok();
|
|
|
|
}
|
|
|
|
|
2017-06-15 17:59:43 +02:00
|
|
|
binder::Status VoldNativeService::checkEncryption(const std::string& volId) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-06-15 17:59:43 +02:00
|
|
|
CHECK_ARGUMENT_ID(volId);
|
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
std::string path;
|
|
|
|
auto status = pathForVolId(volId, &path);
|
|
|
|
if (!status.isOk()) return status;
|
|
|
|
return translate(android::vold::CheckEncryption(path));
|
|
|
|
}
|
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
binder::Status VoldNativeService::moveStorage(
|
|
|
|
const std::string& fromVolId, const std::string& toVolId,
|
|
|
|
const android::sp<android::os::IVoldTaskListener>& listener) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-12 21:19:24 +02:00
|
|
|
CHECK_ARGUMENT_ID(fromVolId);
|
|
|
|
CHECK_ARGUMENT_ID(toVolId);
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
auto fromVol = VolumeManager::Instance()->findVolume(fromVolId);
|
|
|
|
auto toVol = VolumeManager::Instance()->findVolume(toVolId);
|
|
|
|
if (fromVol == nullptr) {
|
|
|
|
return error("Failed to find volume " + fromVolId);
|
|
|
|
} else if (toVol == nullptr) {
|
|
|
|
return error("Failed to find volume " + toVolId);
|
|
|
|
}
|
2017-10-18 00:06:32 +02:00
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
std::thread([=]() { android::vold::MoveStorage(fromVol, toVol, listener); }).detach();
|
2017-09-06 21:47:40 +02:00
|
|
|
return ok();
|
|
|
|
}
|
|
|
|
|
2017-09-07 23:27:28 +02:00
|
|
|
binder::Status VoldNativeService::remountUid(int32_t uid, int32_t remountMode) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2018-12-14 02:40:28 +01:00
|
|
|
return translate(VolumeManager::Instance()->remountUid(uid, remountMode));
|
2017-09-07 23:27:28 +02:00
|
|
|
}
|
|
|
|
|
2020-02-28 17:30:47 +01:00
|
|
|
binder::Status VoldNativeService::remountAppStorageDirs(int uid, int pid,
|
|
|
|
const std::vector<std::string>& packageNames) {
|
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return translate(VolumeManager::Instance()->remountAppStorageDirs(uid, pid, packageNames));
|
|
|
|
}
|
|
|
|
|
2020-02-12 15:29:02 +01:00
|
|
|
binder::Status VoldNativeService::setupAppDir(const std::string& path, int32_t appUid) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-12 21:19:24 +02:00
|
|
|
CHECK_ARGUMENT_PATH(path);
|
2017-09-07 23:27:28 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2020-02-12 15:29:02 +01:00
|
|
|
return translate(VolumeManager::Instance()->setupAppDir(path, appUid));
|
2017-09-07 23:27:28 +02:00
|
|
|
}
|
|
|
|
|
2020-02-18 15:06:37 +01:00
|
|
|
binder::Status VoldNativeService::fixupAppDir(const std::string& path, int32_t appUid) {
|
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
|
|
|
CHECK_ARGUMENT_PATH(path);
|
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return translate(VolumeManager::Instance()->fixupAppDir(path, appUid));
|
|
|
|
}
|
|
|
|
|
2017-09-11 18:32:01 +02:00
|
|
|
binder::Status VoldNativeService::createObb(const std::string& sourcePath,
|
2018-09-19 00:14:18 +02:00
|
|
|
const std::string& sourceKey, int32_t ownerGid,
|
|
|
|
std::string* _aidl_return) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-12 21:19:24 +02:00
|
|
|
CHECK_ARGUMENT_PATH(sourcePath);
|
|
|
|
CHECK_ARGUMENT_HEX(sourceKey);
|
2017-09-11 18:32:01 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return translate(
|
2018-09-19 00:14:18 +02:00
|
|
|
VolumeManager::Instance()->createObb(sourcePath, sourceKey, ownerGid, _aidl_return));
|
2017-09-11 18:32:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::destroyObb(const std::string& volId) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-12 21:19:24 +02:00
|
|
|
CHECK_ARGUMENT_ID(volId);
|
2017-09-11 18:32:01 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return translate(VolumeManager::Instance()->destroyObb(volId));
|
|
|
|
}
|
|
|
|
|
2020-02-04 08:07:21 +01:00
|
|
|
binder::Status VoldNativeService::createStubVolume(const std::string& sourcePath,
|
|
|
|
const std::string& mountPath,
|
|
|
|
const std::string& fsType,
|
|
|
|
const std::string& fsUuid,
|
|
|
|
const std::string& fsLabel, int32_t flags,
|
|
|
|
std::string* _aidl_return) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2018-10-29 00:52:56 +01:00
|
|
|
CHECK_ARGUMENT_PATH(sourcePath);
|
|
|
|
CHECK_ARGUMENT_PATH(mountPath);
|
|
|
|
CHECK_ARGUMENT_HEX(fsUuid);
|
|
|
|
// Label limitation seems to be different between fs (including allowed characters), so checking
|
|
|
|
// is quite meaningless.
|
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2020-02-04 08:07:21 +01:00
|
|
|
return translate(VolumeManager::Instance()->createStubVolume(
|
|
|
|
sourcePath, mountPath, fsType, fsUuid, fsLabel, flags, _aidl_return));
|
2018-10-29 00:52:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::destroyStubVolume(const std::string& volId) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2018-10-29 00:52:56 +01:00
|
|
|
CHECK_ARGUMENT_ID(volId);
|
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return translate(VolumeManager::Instance()->destroyStubVolume(volId));
|
|
|
|
}
|
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
binder::Status VoldNativeService::fstrim(
|
|
|
|
int32_t fstrimFlags, const android::sp<android::os::IVoldTaskListener>& listener) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-11 18:32:01 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
std::thread([=]() { android::vold::Trim(listener); }).detach();
|
2017-09-11 18:32:01 +02:00
|
|
|
return ok();
|
|
|
|
}
|
|
|
|
|
2017-10-18 00:41:45 +02:00
|
|
|
binder::Status VoldNativeService::runIdleMaint(
|
2018-09-19 00:14:18 +02:00
|
|
|
const android::sp<android::os::IVoldTaskListener>& listener) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-10-18 00:41:45 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
std::thread([=]() { android::vold::RunIdleMaint(listener); }).detach();
|
2017-10-18 00:41:45 +02:00
|
|
|
return ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::abortIdleMaint(
|
2018-09-19 00:14:18 +02:00
|
|
|
const android::sp<android::os::IVoldTaskListener>& listener) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-10-18 00:41:45 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
std::thread([=]() { android::vold::AbortIdleMaint(listener); }).detach();
|
2017-10-18 00:41:45 +02:00
|
|
|
return ok();
|
|
|
|
}
|
|
|
|
|
2018-10-27 04:56:45 +02:00
|
|
|
binder::Status VoldNativeService::mountAppFuse(int32_t uid, int32_t mountId,
|
2018-09-19 00:14:18 +02:00
|
|
|
android::base::unique_fd* _aidl_return) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-11 18:32:01 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2018-10-27 04:56:45 +02:00
|
|
|
return translate(VolumeManager::Instance()->mountAppFuse(uid, mountId, _aidl_return));
|
2017-09-11 18:32:01 +02:00
|
|
|
}
|
|
|
|
|
2018-10-27 04:56:45 +02:00
|
|
|
binder::Status VoldNativeService::unmountAppFuse(int32_t uid, int32_t mountId) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-11 18:32:01 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2018-10-27 04:56:45 +02:00
|
|
|
return translate(VolumeManager::Instance()->unmountAppFuse(uid, mountId));
|
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::openAppFuseFile(int32_t uid, int32_t mountId, int32_t fileId,
|
|
|
|
int32_t flags,
|
|
|
|
android::base::unique_fd* _aidl_return) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2018-10-27 04:56:45 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
int fd = VolumeManager::Instance()->openAppFuseFile(uid, mountId, fileId, flags);
|
|
|
|
if (fd == -1) {
|
|
|
|
return error("Failed to open AppFuse file for uid: " + std::to_string(uid) +
|
|
|
|
" mountId: " + std::to_string(mountId) + " fileId: " + std::to_string(fileId) +
|
|
|
|
" flags: " + std::to_string(flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
*_aidl_return = android::base::unique_fd(fd);
|
|
|
|
return ok();
|
2017-09-11 18:32:01 +02:00
|
|
|
}
|
|
|
|
|
2017-09-13 00:30:52 +02:00
|
|
|
binder::Status VoldNativeService::fdeCheckPassword(const std::string& password) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
|
|
|
return translate(cryptfs_check_passwd(password.c_str()));
|
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::fdeRestart() {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
|
|
|
// Spawn as thread so init can issue commands back to vold without
|
|
|
|
// causing deadlock, usually as a result of prep_data_fs.
|
|
|
|
std::thread(&cryptfs_restart).detach();
|
|
|
|
return ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::fdeComplete(int32_t* _aidl_return) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
|
|
|
*_aidl_return = cryptfs_crypto_complete();
|
|
|
|
return ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fdeEnableInternal(int32_t passwordType, const std::string& password,
|
2018-09-19 00:14:18 +02:00
|
|
|
int32_t encryptionFlags) {
|
2017-09-13 00:30:52 +02:00
|
|
|
bool noUi = (encryptionFlags & VoldNativeService::ENCRYPTION_FLAG_NO_UI) != 0;
|
|
|
|
|
|
|
|
for (int tries = 0; tries < 2; ++tries) {
|
|
|
|
int rc;
|
|
|
|
if (passwordType == VoldNativeService::PASSWORD_TYPE_DEFAULT) {
|
2017-12-22 19:12:06 +01:00
|
|
|
rc = cryptfs_enable_default(noUi);
|
2017-09-13 00:30:52 +02:00
|
|
|
} else {
|
2017-12-22 19:12:06 +01:00
|
|
|
rc = cryptfs_enable(passwordType, password.c_str(), noUi);
|
2017-09-13 00:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rc == 0) {
|
|
|
|
return 0;
|
|
|
|
} else if (tries == 0) {
|
2017-10-07 02:02:53 +02:00
|
|
|
KillProcessesWithOpenFiles(DATA_MNT_POINT, SIGKILL);
|
2017-09-13 00:30:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
binder::Status VoldNativeService::fdeEnable(int32_t passwordType, const std::string& password,
|
|
|
|
int32_t encryptionFlags) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
2018-01-30 18:48:19 +01:00
|
|
|
LOG(DEBUG) << "fdeEnable(" << passwordType << ", *, " << encryptionFlags << ")";
|
2018-10-23 22:06:55 +02:00
|
|
|
if (fscrypt_is_native()) {
|
|
|
|
LOG(ERROR) << "fscrypt_is_native, fdeEnable invalid";
|
|
|
|
return error("fscrypt_is_native, fdeEnable invalid");
|
2017-09-13 00:30:52 +02:00
|
|
|
}
|
2018-10-23 22:06:55 +02:00
|
|
|
LOG(DEBUG) << "!fscrypt_is_native, spawning fdeEnableInternal";
|
2017-09-13 00:30:52 +02:00
|
|
|
|
|
|
|
// Spawn as thread so init can issue commands back to vold without
|
|
|
|
// causing deadlock, usually as a result of prep_data_fs.
|
|
|
|
std::thread(&fdeEnableInternal, passwordType, password, encryptionFlags).detach();
|
|
|
|
return ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::fdeChangePassword(int32_t passwordType,
|
2018-09-19 00:14:18 +02:00
|
|
|
const std::string& password) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
|
|
|
return translate(cryptfs_changepw(passwordType, password.c_str()));
|
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::fdeVerifyPassword(const std::string& password) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
|
|
|
return translate(cryptfs_verify_passwd(password.c_str()));
|
|
|
|
}
|
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
binder::Status VoldNativeService::fdeGetField(const std::string& key, std::string* _aidl_return) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
|
|
|
char buf[PROPERTY_VALUE_MAX];
|
|
|
|
if (cryptfs_getfield(key.c_str(), buf, sizeof(buf)) != CRYPTO_GETFIELD_OK) {
|
|
|
|
return error(StringPrintf("Failed to read field %s", key.c_str()));
|
|
|
|
} else {
|
|
|
|
*_aidl_return = buf;
|
|
|
|
return ok();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
binder::Status VoldNativeService::fdeSetField(const std::string& key, const std::string& value) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
|
|
|
return translate(cryptfs_setfield(key.c_str(), value.c_str()));
|
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::fdeGetPasswordType(int32_t* _aidl_return) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
|
|
|
*_aidl_return = cryptfs_get_password_type();
|
|
|
|
return ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::fdeGetPassword(std::string* _aidl_return) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
|
|
|
const char* res = cryptfs_get_password();
|
|
|
|
if (res != nullptr) {
|
|
|
|
*_aidl_return = res;
|
|
|
|
}
|
|
|
|
return ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::fdeClearPassword() {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
|
|
|
cryptfs_clear_password();
|
|
|
|
return ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::fbeEnable() {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
2019-09-12 00:00:08 +02:00
|
|
|
return translateBool(fscrypt_initialize_systemwide_keys());
|
2017-09-13 00:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::mountDefaultEncrypted() {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
2018-10-23 22:06:55 +02:00
|
|
|
if (!fscrypt_is_native()) {
|
2017-09-13 00:30:52 +02:00
|
|
|
// Spawn as thread so init can issue commands back to vold without
|
|
|
|
// causing deadlock, usually as a result of prep_data_fs.
|
|
|
|
std::thread(&cryptfs_mount_default_encrypted).detach();
|
|
|
|
}
|
2018-01-30 18:48:19 +01:00
|
|
|
return ok();
|
2017-09-13 00:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::initUser0() {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
2018-10-23 22:06:55 +02:00
|
|
|
return translateBool(fscrypt_init_user0());
|
2017-09-13 00:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::isConvertibleToFbe(bool* _aidl_return) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
|
|
|
*_aidl_return = cryptfs_isConvertibleToFBE() != 0;
|
|
|
|
return ok();
|
|
|
|
}
|
|
|
|
|
2019-06-25 23:44:33 +02:00
|
|
|
binder::Status VoldNativeService::mountFstab(const std::string& blkDevice,
|
|
|
|
const std::string& mountPoint) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2018-01-30 18:48:19 +01:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2019-06-25 23:44:33 +02:00
|
|
|
return translateBool(fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, false));
|
2018-01-30 18:48:19 +01:00
|
|
|
}
|
|
|
|
|
2019-06-25 23:44:33 +02:00
|
|
|
binder::Status VoldNativeService::encryptFstab(const std::string& blkDevice,
|
|
|
|
const std::string& mountPoint) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2018-01-30 18:48:19 +01:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2019-06-25 23:44:33 +02:00
|
|
|
return translateBool(fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, true));
|
2018-01-30 18:48:19 +01:00
|
|
|
}
|
|
|
|
|
2018-09-19 00:14:18 +02:00
|
|
|
binder::Status VoldNativeService::createUserKey(int32_t userId, int32_t userSerial, bool ephemeral) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
2018-10-23 22:06:55 +02:00
|
|
|
return translateBool(fscrypt_vold_create_user_key(userId, userSerial, ephemeral));
|
2017-09-13 00:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::destroyUserKey(int32_t userId) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
2018-10-23 22:06:55 +02:00
|
|
|
return translateBool(fscrypt_destroy_user_key(userId));
|
2017-09-13 00:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::addUserKeyAuth(int32_t userId, int32_t userSerial,
|
2018-09-19 00:14:18 +02:00
|
|
|
const std::string& token,
|
|
|
|
const std::string& secret) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
2018-10-23 22:06:55 +02:00
|
|
|
return translateBool(fscrypt_add_user_key_auth(userId, userSerial, token, secret));
|
2017-09-13 00:30:52 +02:00
|
|
|
}
|
|
|
|
|
2019-11-01 06:59:34 +01:00
|
|
|
binder::Status VoldNativeService::clearUserKeyAuth(int32_t userId, int32_t userSerial,
|
|
|
|
const std::string& token,
|
|
|
|
const std::string& secret) {
|
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
|
|
|
return translateBool(fscrypt_clear_user_key_auth(userId, userSerial, token, secret));
|
|
|
|
}
|
|
|
|
|
2017-09-13 00:30:52 +02:00
|
|
|
binder::Status VoldNativeService::fixateNewestUserKeyAuth(int32_t userId) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
2018-10-23 22:06:55 +02:00
|
|
|
return translateBool(fscrypt_fixate_newest_user_key_auth(userId));
|
2017-09-13 00:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::unlockUserKey(int32_t userId, int32_t userSerial,
|
2018-09-19 00:14:18 +02:00
|
|
|
const std::string& token,
|
|
|
|
const std::string& secret) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
2018-10-23 22:06:55 +02:00
|
|
|
return translateBool(fscrypt_unlock_user_key(userId, userSerial, token, secret));
|
2017-09-13 00:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::lockUserKey(int32_t userId) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-09-13 00:30:52 +02:00
|
|
|
ACQUIRE_CRYPT_LOCK;
|
|
|
|
|
2018-10-23 22:06:55 +02:00
|
|
|
return translateBool(fscrypt_lock_user_key(userId));
|
2017-09-13 00:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::prepareUserStorage(const std::unique_ptr<std::string>& uuid,
|
2018-09-19 00:14:18 +02:00
|
|
|
int32_t userId, int32_t userSerial,
|
|
|
|
int32_t flags) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-10-09 19:55:21 +02:00
|
|
|
std::string empty_string = "";
|
|
|
|
auto uuid_ = uuid ? *uuid : empty_string;
|
2017-10-16 19:59:51 +02:00
|
|
|
CHECK_ARGUMENT_HEX(uuid_);
|
|
|
|
|
|
|
|
ACQUIRE_CRYPT_LOCK;
|
2018-10-23 22:06:55 +02:00
|
|
|
return translateBool(fscrypt_prepare_user_storage(uuid_, userId, userSerial, flags));
|
2017-09-13 00:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::destroyUserStorage(const std::unique_ptr<std::string>& uuid,
|
2018-09-19 00:14:18 +02:00
|
|
|
int32_t userId, int32_t flags) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2017-10-09 19:55:21 +02:00
|
|
|
std::string empty_string = "";
|
|
|
|
auto uuid_ = uuid ? *uuid : empty_string;
|
2017-10-16 19:59:51 +02:00
|
|
|
CHECK_ARGUMENT_HEX(uuid_);
|
|
|
|
|
|
|
|
ACQUIRE_CRYPT_LOCK;
|
2018-10-23 22:06:55 +02:00
|
|
|
return translateBool(fscrypt_destroy_user_storage(uuid_, userId, flags));
|
2017-09-13 00:30:52 +02:00
|
|
|
}
|
|
|
|
|
2018-10-05 01:26:22 +02:00
|
|
|
binder::Status VoldNativeService::prepareSandboxForApp(const std::string& packageName,
|
|
|
|
int32_t appId, const std::string& sandboxId,
|
|
|
|
int32_t userId) {
|
2019-04-29 19:46:35 +02:00
|
|
|
return ok();
|
2018-10-05 01:26:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::destroySandboxForApp(const std::string& packageName,
|
2018-10-25 20:06:55 +02:00
|
|
|
const std::string& sandboxId,
|
2018-10-05 01:26:22 +02:00
|
|
|
int32_t userId) {
|
2019-04-29 19:46:35 +02:00
|
|
|
return ok();
|
2018-08-24 19:20:56 +02:00
|
|
|
}
|
|
|
|
|
2018-10-11 03:52:04 +02:00
|
|
|
binder::Status VoldNativeService::startCheckpoint(int32_t retry) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2018-08-28 10:58:49 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2018-10-11 03:52:04 +02:00
|
|
|
return cp_startCheckpoint(retry);
|
2018-08-28 10:58:49 +02:00
|
|
|
}
|
|
|
|
|
2018-10-03 02:40:44 +02:00
|
|
|
binder::Status VoldNativeService::needsRollback(bool* _aidl_return) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2018-10-03 02:40:44 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
*_aidl_return = cp_needsRollback();
|
|
|
|
return ok();
|
|
|
|
}
|
|
|
|
|
2018-08-28 10:58:49 +02:00
|
|
|
binder::Status VoldNativeService::needsCheckpoint(bool* _aidl_return) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2018-08-28 10:58:49 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
*_aidl_return = cp_needsCheckpoint();
|
|
|
|
return ok();
|
|
|
|
}
|
|
|
|
|
2018-10-11 03:52:04 +02:00
|
|
|
binder::Status VoldNativeService::commitChanges() {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2018-08-28 10:58:49 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2018-10-11 03:52:04 +02:00
|
|
|
return cp_commitChanges();
|
2018-08-28 10:58:49 +02:00
|
|
|
}
|
|
|
|
|
2018-10-11 03:52:04 +02:00
|
|
|
binder::Status VoldNativeService::prepareCheckpoint() {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2018-08-28 10:58:49 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2018-10-11 03:52:04 +02:00
|
|
|
return cp_prepareCheckpoint();
|
2018-08-28 10:58:49 +02:00
|
|
|
}
|
|
|
|
|
2018-10-11 03:52:04 +02:00
|
|
|
binder::Status VoldNativeService::restoreCheckpoint(const std::string& mountPoint) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2018-09-21 19:49:57 +02:00
|
|
|
CHECK_ARGUMENT_PATH(mountPoint);
|
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2018-10-11 03:52:04 +02:00
|
|
|
return cp_restoreCheckpoint(mountPoint);
|
2018-09-21 19:49:57 +02:00
|
|
|
}
|
|
|
|
|
2019-03-07 02:45:17 +01:00
|
|
|
binder::Status VoldNativeService::restoreCheckpointPart(const std::string& mountPoint, int count) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2019-03-07 02:45:17 +01:00
|
|
|
CHECK_ARGUMENT_PATH(mountPoint);
|
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return cp_restoreCheckpoint(mountPoint, count);
|
|
|
|
}
|
|
|
|
|
2018-10-11 03:52:04 +02:00
|
|
|
binder::Status VoldNativeService::markBootAttempt() {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2018-08-28 10:58:49 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2018-10-11 03:52:04 +02:00
|
|
|
return cp_markBootAttempt();
|
2018-08-28 10:58:49 +02:00
|
|
|
}
|
|
|
|
|
2019-03-21 01:02:47 +01:00
|
|
|
binder::Status VoldNativeService::abortChanges(const std::string& message, bool retry) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2018-08-28 10:58:49 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
2019-03-21 01:02:47 +01:00
|
|
|
cp_abortChanges(message, retry);
|
|
|
|
return ok();
|
2018-08-28 10:58:49 +02:00
|
|
|
}
|
|
|
|
|
2019-01-23 02:27:25 +01:00
|
|
|
binder::Status VoldNativeService::supportsCheckpoint(bool* _aidl_return) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2019-01-23 02:27:25 +01:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return cp_supportsCheckpoint(*_aidl_return);
|
|
|
|
}
|
|
|
|
|
2019-03-18 21:36:40 +01:00
|
|
|
binder::Status VoldNativeService::supportsBlockCheckpoint(bool* _aidl_return) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2019-03-18 21:36:40 +01:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return cp_supportsBlockCheckpoint(*_aidl_return);
|
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::supportsFileCheckpoint(bool* _aidl_return) {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2019-03-18 21:36:40 +01:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
return cp_supportsFileCheckpoint(*_aidl_return);
|
|
|
|
}
|
|
|
|
|
2019-10-11 17:38:21 +02:00
|
|
|
binder::Status VoldNativeService::resetCheckpoint() {
|
2019-10-23 18:19:13 +02:00
|
|
|
ENFORCE_SYSTEM_OR_ROOT;
|
2019-10-11 17:38:21 +02:00
|
|
|
ACQUIRE_LOCK;
|
|
|
|
|
|
|
|
cp_resetCheckpoint();
|
|
|
|
return ok();
|
|
|
|
}
|
|
|
|
|
2020-01-10 20:54:06 +01:00
|
|
|
binder::Status VoldNativeService::incFsEnabled(bool* _aidl_return) {
|
|
|
|
*_aidl_return = IncFs_IsEnabled();
|
2019-12-02 19:50:12 +01:00
|
|
|
return ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::mountIncFs(
|
2020-01-10 20:54:06 +01:00
|
|
|
const std::string& backingPath, const std::string& targetDir, int32_t flags,
|
2019-12-02 19:50:12 +01:00
|
|
|
::android::os::incremental::IncrementalFileSystemControlParcel* _aidl_return) {
|
2020-01-10 20:54:06 +01:00
|
|
|
auto result = IncFs_Mount(backingPath.c_str(), targetDir.c_str(),
|
|
|
|
{.flags = IncFsMountFlags(flags),
|
|
|
|
.defaultReadTimeoutMs = INCFS_DEFAULT_READ_TIMEOUT_MS,
|
|
|
|
.readLogBufferPages = 4});
|
|
|
|
if (result.cmd < 0) {
|
|
|
|
return translate(result.cmd);
|
|
|
|
}
|
2019-12-02 19:50:12 +01:00
|
|
|
using unique_fd = ::android::base::unique_fd;
|
2020-01-10 20:54:06 +01:00
|
|
|
_aidl_return->cmd.reset(unique_fd(result.cmd));
|
|
|
|
_aidl_return->pendingReads.reset(unique_fd(result.pendingReads));
|
|
|
|
if (result.logs >= 0) {
|
|
|
|
_aidl_return->log.reset(unique_fd(result.logs));
|
2019-12-02 19:50:12 +01:00
|
|
|
}
|
|
|
|
return ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::unmountIncFs(const std::string& dir) {
|
|
|
|
return translate(IncFs_Unmount(dir.c_str()));
|
|
|
|
}
|
|
|
|
|
|
|
|
binder::Status VoldNativeService::bindMount(const std::string& sourceDir,
|
|
|
|
const std::string& targetDir) {
|
|
|
|
return translate(IncFs_BindMount(sourceDir.c_str(), targetDir.c_str()));
|
|
|
|
}
|
|
|
|
|
2017-09-06 21:47:40 +02:00
|
|
|
} // namespace vold
|
|
|
|
} // namespace android
|