Skip to content

Commit 8b002e7

Browse files
aviraxpanzarfarooq
authored andcommitted
Reapply: "Handle unmount for isolated process correctly (tiann#2696)"
Isolated processes can be directly forked from zygote, but current code doesn't handle it well. Fix it by unmounting unconditionally if isolated process is forked from zygote.
1 parent 2c76d5f commit 8b002e7

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

kernel/core_hook.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static inline bool is_allow_su()
146146
return ksu_is_allow_uid(current_uid().val);
147147
}
148148

149-
static inline bool is_unsupported_uid(uid_t uid)
149+
static inline bool is_unsupported_app_uid(uid_t uid)
150150
{
151151
#define LAST_APPLICATION_UID 19999
152152
uid_t appid = uid % 100000;
@@ -823,14 +823,13 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3,
823823
return 0;
824824
}
825825

826-
static bool is_appuid(kuid_t uid)
826+
static bool is_non_appuid(kuid_t uid)
827827
{
828828
#define PER_USER_RANGE 100000
829829
#define FIRST_APPLICATION_UID 10000
830-
#define LAST_APPLICATION_UID 19999
831830

832831
uid_t appid = uid.val % PER_USER_RANGE;
833-
return appid >= FIRST_APPLICATION_UID && appid <= LAST_APPLICATION_UID;
832+
return appid < FIRST_APPLICATION_UID;
834833
}
835834

836835
static bool should_umount(struct path *path)
@@ -1019,13 +1018,25 @@ int ksu_handle_setuid(struct cred *new, const struct cred *old)
10191018
return 0;
10201019
}
10211020

1022-
if (!is_appuid(new_uid) || is_unsupported_uid(new_uid.val)) {
1023-
// pr_info("handle setuid ignore non application or isolated uid: %d\n", new_uid.val);
1021+
if (is_non_appuid(new_uid)) {
1022+
#ifdef CONFIG_KSU_DEBUG
1023+
pr_info("handle setuid ignore non application uid: %d\n", new_uid.val);
1024+
#endif
10241025
return 0;
10251026
}
10261027

1028+
// isolated process may be directly forked from zygote, always unmount
1029+
if (is_unsupported_app_uid(new_uid.val)) {
1030+
#ifdef CONFIG_KSU_DEBUG
1031+
pr_info("handle umount for unsupported application uid: %d\n", new_uid.val);
1032+
#endif
1033+
goto do_umount;
1034+
}
1035+
10271036
if (ksu_is_allow_uid(new_uid.val)) {
1028-
// pr_info("handle setuid ignore allowed application: %d\n", new_uid.val);
1037+
#ifdef CONFIG_KSU_DEBUG
1038+
pr_info("handle setuid ignore allowed application: %d\n", new_uid.val);
1039+
#endif
10291040
return 0;
10301041
}
10311042

@@ -1037,11 +1048,11 @@ int ksu_handle_setuid(struct cred *new, const struct cred *old)
10371048
#endif
10381049
}
10391050

1051+
do_umount:
10401052
// check old process's selinux context, if it is not zygote, ignore it!
10411053
// because some su apps may setuid to untrusted_app but they are in global mount namespace
10421054
// when we umount for such process, that is a disaster!
1043-
bool is_zygote_child = is_zygote(old->security);
1044-
if (!is_zygote_child) {
1055+
if (!is_zygote(old->security)) {
10451056
pr_info("handle umount ignore non zygote child: %d\n",
10461057
current->pid);
10471058
return 0;

0 commit comments

Comments
 (0)