Skip to content

Commit a58b535

Browse files
author
Ricky Wai
committed
Only kill apps with storage app data isolation enabled
Originally it kills all the apps with obb and data mounted. Due to recent changes, all apps will have obb and data dirs mounted in default root namespace. Hence all apps will be killed by by KillProcessesWithMounts(). To fix this, we also check if the dir is mounted as tmpfs, as the default namespace one is bind mounted to lowerfs, which app data isolation is mounted as tmpfs, so we only kill the process that have obb dir mounted as tmpfs. Bug: 148049767 Test: Able to boot without warnings / errors Ignore-AOSP-First: Merge it along with other CLs, will cherry-pick to AOSP afterwards. Change-Id: I45d9a63ed47cbc27aebb63357a43f51ad62275db
1 parent 73eda07 commit a58b535

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

Process.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static bool checkSymlink(const std::string& path, const std::string& prefix) {
8484
}
8585

8686
// TODO: Refactor the code with KillProcessesWithOpenFiles().
87-
int KillProcessesWithMounts(const std::string& prefix, int signal) {
87+
int KillProcessesWithTmpfsMounts(const std::string& prefix, int signal) {
8888
std::unordered_set<pid_t> pids;
8989

9090
auto proc_d = std::unique_ptr<DIR, int (*)(DIR*)>(opendir("/proc"), closedir);
@@ -112,7 +112,8 @@ int KillProcessesWithMounts(const std::string& prefix, int signal) {
112112
// Check if obb directory is mounted, and get all packages of mounted app data directory.
113113
mntent* mentry;
114114
while ((mentry = getmntent(fp.get())) != nullptr) {
115-
if (android::base::StartsWith(mentry->mnt_dir, prefix)) {
115+
if (mentry->mnt_fsname != nullptr && strncmp(mentry->mnt_fsname, "tmpfs", 5) == 0
116+
&& android::base::StartsWith(mentry->mnt_dir, prefix)) {
116117
pids.insert(pid);
117118
break;
118119
}

Process.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace android {
2121
namespace vold {
2222

2323
int KillProcessesWithOpenFiles(const std::string& path, int signal, bool killFuseDaemon = true);
24-
int KillProcessesWithMounts(const std::string& path, int signal);
24+
int KillProcessesWithTmpfsMounts(const std::string& path, int signal);
2525

2626
} // namespace vold
2727
} // namespace android

Utils.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -499,25 +499,25 @@ status_t ForceUnmount(const std::string& path) {
499499
return -errno;
500500
}
501501

502-
status_t KillProcessesWithMountPrefix(const std::string& path) {
503-
if (KillProcessesWithMounts(path, SIGINT) == 0) {
502+
status_t KillProcessesWithTmpfsMountPrefix(const std::string& path) {
503+
if (KillProcessesWithTmpfsMounts(path, SIGINT) == 0) {
504504
return OK;
505505
}
506506
if (sSleepOnUnmount) sleep(5);
507507

508-
if (KillProcessesWithMounts(path, SIGTERM) == 0) {
508+
if (KillProcessesWithTmpfsMounts(path, SIGTERM) == 0) {
509509
return OK;
510510
}
511511
if (sSleepOnUnmount) sleep(5);
512512

513-
if (KillProcessesWithMounts(path, SIGKILL) == 0) {
513+
if (KillProcessesWithTmpfsMounts(path, SIGKILL) == 0) {
514514
return OK;
515515
}
516516
if (sSleepOnUnmount) sleep(5);
517517

518518
// Send SIGKILL a second time to determine if we've
519519
// actually killed everyone mount
520-
if (KillProcessesWithMounts(path, SIGKILL) == 0) {
520+
if (KillProcessesWithTmpfsMounts(path, SIGKILL) == 0) {
521521
return OK;
522522
}
523523
PLOG(ERROR) << "Failed to kill processes using " << path;

Utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ status_t ForceUnmount(const std::string& path);
7878
/* Kills any processes using given path */
7979
status_t KillProcessesUsingPath(const std::string& path);
8080

81-
/* Kills any processes using given mount prifix */
82-
status_t KillProcessesWithMountPrefix(const std::string& path);
81+
/* Kills any processes using given tmpfs mount prifix */
82+
status_t KillProcessesWithTmpfsMountPrefix(const std::string& path);
8383

8484
/* Creates bind mount from source to target */
8585
status_t BindMount(const std::string& source, const std::string& target);

model/EmulatedVolume.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ status_t EmulatedVolume::unmountFuseBindMounts() {
191191
// umount the whole Android/ dir.
192192
if (mAppDataIsolationEnabled) {
193193
std::string appObbDir(StringPrintf("%s/%d/Android/obb", getPath().c_str(), userId));
194-
KillProcessesWithMountPrefix(appObbDir);
194+
// Here we assume obb/data dirs is mounted as tmpfs, then it must be caused by
195+
// app data isolation.
196+
KillProcessesWithTmpfsMountPrefix(appObbDir);
195197
} else {
196198
std::string androidDataTarget(
197199
StringPrintf("/mnt/user/%d/%s/%d/Android/data", userId, label.c_str(), userId));

0 commit comments

Comments
 (0)