Merge "Only kill apps with storage app data isolation enabled"

This commit is contained in:
Alan Stokes 2021-05-05 14:16:00 +00:00 committed by Gerrit Code Review
commit b2678b6654
5 changed files with 14 additions and 11 deletions

View file

@ -84,7 +84,7 @@ static bool checkSymlink(const std::string& path, const std::string& prefix) {
} }
// TODO: Refactor the code with KillProcessesWithOpenFiles(). // TODO: Refactor the code with KillProcessesWithOpenFiles().
int KillProcessesWithMounts(const std::string& prefix, int signal) { int KillProcessesWithTmpfsMounts(const std::string& prefix, int signal) {
std::unordered_set<pid_t> pids; std::unordered_set<pid_t> pids;
auto proc_d = std::unique_ptr<DIR, int (*)(DIR*)>(opendir("/proc"), closedir); auto proc_d = std::unique_ptr<DIR, int (*)(DIR*)>(opendir("/proc"), closedir);
@ -112,7 +112,8 @@ int KillProcessesWithMounts(const std::string& prefix, int signal) {
// Check if obb directory is mounted, and get all packages of mounted app data directory. // Check if obb directory is mounted, and get all packages of mounted app data directory.
mntent* mentry; mntent* mentry;
while ((mentry = getmntent(fp.get())) != nullptr) { while ((mentry = getmntent(fp.get())) != nullptr) {
if (android::base::StartsWith(mentry->mnt_dir, prefix)) { if (mentry->mnt_fsname != nullptr && strncmp(mentry->mnt_fsname, "tmpfs", 5) == 0
&& android::base::StartsWith(mentry->mnt_dir, prefix)) {
pids.insert(pid); pids.insert(pid);
break; break;
} }

View file

@ -21,7 +21,7 @@ namespace android {
namespace vold { namespace vold {
int KillProcessesWithOpenFiles(const std::string& path, int signal, bool killFuseDaemon = true); int KillProcessesWithOpenFiles(const std::string& path, int signal, bool killFuseDaemon = true);
int KillProcessesWithMounts(const std::string& path, int signal); int KillProcessesWithTmpfsMounts(const std::string& path, int signal);
} // namespace vold } // namespace vold
} // namespace android } // namespace android

View file

@ -504,25 +504,25 @@ status_t ForceUnmount(const std::string& path) {
return -errno; return -errno;
} }
status_t KillProcessesWithMountPrefix(const std::string& path) { status_t KillProcessesWithTmpfsMountPrefix(const std::string& path) {
if (KillProcessesWithMounts(path, SIGINT) == 0) { if (KillProcessesWithTmpfsMounts(path, SIGINT) == 0) {
return OK; return OK;
} }
if (sSleepOnUnmount) sleep(5); if (sSleepOnUnmount) sleep(5);
if (KillProcessesWithMounts(path, SIGTERM) == 0) { if (KillProcessesWithTmpfsMounts(path, SIGTERM) == 0) {
return OK; return OK;
} }
if (sSleepOnUnmount) sleep(5); if (sSleepOnUnmount) sleep(5);
if (KillProcessesWithMounts(path, SIGKILL) == 0) { if (KillProcessesWithTmpfsMounts(path, SIGKILL) == 0) {
return OK; return OK;
} }
if (sSleepOnUnmount) sleep(5); if (sSleepOnUnmount) sleep(5);
// Send SIGKILL a second time to determine if we've // Send SIGKILL a second time to determine if we've
// actually killed everyone mount // actually killed everyone mount
if (KillProcessesWithMounts(path, SIGKILL) == 0) { if (KillProcessesWithTmpfsMounts(path, SIGKILL) == 0) {
return OK; return OK;
} }
PLOG(ERROR) << "Failed to kill processes using " << path; PLOG(ERROR) << "Failed to kill processes using " << path;

View file

@ -78,8 +78,8 @@ status_t ForceUnmount(const std::string& path);
/* Kills any processes using given path */ /* Kills any processes using given path */
status_t KillProcessesUsingPath(const std::string& path); status_t KillProcessesUsingPath(const std::string& path);
/* Kills any processes using given mount prifix */ /* Kills any processes using given tmpfs mount prifix */
status_t KillProcessesWithMountPrefix(const std::string& path); status_t KillProcessesWithTmpfsMountPrefix(const std::string& path);
/* Creates bind mount from source to target */ /* Creates bind mount from source to target */
status_t BindMount(const std::string& source, const std::string& target); status_t BindMount(const std::string& source, const std::string& target);

View file

@ -191,7 +191,9 @@ status_t EmulatedVolume::unmountFuseBindMounts() {
// umount the whole Android/ dir. // umount the whole Android/ dir.
if (mAppDataIsolationEnabled) { if (mAppDataIsolationEnabled) {
std::string appObbDir(StringPrintf("%s/%d/Android/obb", getPath().c_str(), userId)); std::string appObbDir(StringPrintf("%s/%d/Android/obb", getPath().c_str(), userId));
KillProcessesWithMountPrefix(appObbDir); // Here we assume obb/data dirs is mounted as tmpfs, then it must be caused by
// app data isolation.
KillProcessesWithTmpfsMountPrefix(appObbDir);
} else { } else {
std::string androidDataTarget( std::string androidDataTarget(
StringPrintf("/mnt/user/%d/%s/%d/Android/data", userId, label.c_str(), userId)); StringPrintf("/mnt/user/%d/%s/%d/Android/data", userId, label.c_str(), userId));