Merge "Protect /mnt/scratch from stale umount on userdebug"

gugelfrei
Treehugger Robot 6 years ago committed by Gerrit Code Review
commit b39e6f2887

@ -139,6 +139,9 @@ cc_library_static {
"libarcobbvolume", "libarcobbvolume",
], ],
}, },
debuggable: {
cppflags: ["-D__ANDROID_DEBUGGABLE__"],
},
}, },
shared_libs: [ shared_libs: [
"android.hardware.health.storage@1.0", "android.hardware.health.storage@1.0",

@ -64,6 +64,7 @@
#include "model/EmulatedVolume.h" #include "model/EmulatedVolume.h"
#include "model/ObbVolume.h" #include "model/ObbVolume.h"
using android::base::StartsWith;
using android::base::StringPrintf; using android::base::StringPrintf;
using android::base::unique_fd; using android::base::unique_fd;
@ -589,10 +590,12 @@ int VolumeManager::unmountAll() {
mntent* mentry; mntent* mentry;
while ((mentry = getmntent(fp)) != NULL) { while ((mentry = getmntent(fp)) != NULL) {
auto test = std::string(mentry->mnt_dir); auto test = std::string(mentry->mnt_dir);
if ((android::base::StartsWith(test, "/mnt/") && if ((StartsWith(test, "/mnt/") &&
!android::base::StartsWith(test, "/mnt/vendor") && #ifdef __ANDROID_DEBUGGABLE__
!android::base::StartsWith(test, "/mnt/product")) || !StartsWith(test, "/mnt/scratch") &&
android::base::StartsWith(test, "/storage/")) { #endif
!StartsWith(test, "/mnt/vendor") && !StartsWith(test, "/mnt/product")) ||
StartsWith(test, "/storage/")) {
toUnmount.push_front(test); toUnmount.push_front(test);
} }
} }
@ -608,7 +611,7 @@ int VolumeManager::unmountAll() {
int VolumeManager::mkdirs(const std::string& path) { int VolumeManager::mkdirs(const std::string& path) {
// Only offer to create directories for paths managed by vold // Only offer to create directories for paths managed by vold
if (android::base::StartsWith(path, "/storage/")) { if (StartsWith(path, "/storage/")) {
// fs_mkdirs() does symlink checking and relative path enforcement // fs_mkdirs() does symlink checking and relative path enforcement
return fs_mkdirs(path.c_str(), 0700); return fs_mkdirs(path.c_str(), 0700);
} else { } else {
@ -630,7 +633,7 @@ static android::status_t getMountPath(uid_t uid, const std::string& name, std::s
return -EINVAL; return -EINVAL;
} }
} }
*path = android::base::StringPrintf("/mnt/appfuse/%d_%s", uid, name.c_str()); *path = StringPrintf("/mnt/appfuse/%d_%s", uid, name.c_str());
return android::OK; return android::OK;
} }
@ -638,7 +641,7 @@ static android::status_t mountInNamespace(uid_t uid, int device_fd, const std::s
// Remove existing mount. // Remove existing mount.
android::vold::ForceUnmount(path); android::vold::ForceUnmount(path);
const auto opts = android::base::StringPrintf( const auto opts = StringPrintf(
"fd=%i," "fd=%i,"
"rootmode=40000," "rootmode=40000,"
"default_permissions," "default_permissions,"
@ -673,7 +676,7 @@ static android::status_t runCommandInNamespace(const std::string& command, uid_t
} }
// Obtains process file descriptor. // Obtains process file descriptor.
const std::string pid_str = android::base::StringPrintf("%d", pid); const std::string pid_str = StringPrintf("%d", pid);
const unique_fd pid_fd(openat(dir.get(), pid_str.c_str(), O_RDONLY | O_DIRECTORY | O_CLOEXEC)); const unique_fd pid_fd(openat(dir.get(), pid_str.c_str(), O_RDONLY | O_DIRECTORY | O_CLOEXEC));
if (pid_fd.get() == -1) { if (pid_fd.get() == -1) {
PLOG(ERROR) << "Failed to open /proc/" << pid; PLOG(ERROR) << "Failed to open /proc/" << pid;
@ -782,8 +785,7 @@ int VolumeManager::destroyObb(const std::string& volId) {
return android::OK; return android::OK;
} }
int VolumeManager::mountAppFuse(uid_t uid, pid_t pid, int mountId, int VolumeManager::mountAppFuse(uid_t uid, pid_t pid, int mountId, unique_fd* device_fd) {
android::base::unique_fd* device_fd) {
std::string name = std::to_string(mountId); std::string name = std::to_string(mountId);
// Check mount point name. // Check mount point name.

Loading…
Cancel
Save