Skip to content

Commit 1a77f5d

Browse files
pershootaviraxp
authored andcommitted
Unmount isolated process which forks from zygote unconditionally (tiann/KernelSU#2747) (KernelSU-Next#776)
Rethink about this patch, isolated process which directly forks from zygote is just like normal app, so there is no reason apps won't crash but Isolated process will. Also zygote reopens fd before actually fork, so it should be fine. This reverts commit tiann/KernelSU@2a1741d. Co-authored-by: Wang Han <[email protected]> Signed-off-by: Sorayukii <[email protected]>
1 parent 69be375 commit 1a77f5d

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
@@ -63,7 +63,7 @@ static inline bool is_allow_su()
6363
return ksu_is_allow_uid(current_uid().val);
6464
}
6565

66-
static inline bool is_unsupported_uid(uid_t uid)
66+
static inline bool is_unsupported_app_uid(uid_t uid)
6767
{
6868
#define LAST_APPLICATION_UID 19999
6969
uid_t appid = uid % 100000;
@@ -600,14 +600,13 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3,
600600
return 0;
601601
}
602602

603-
static bool is_appuid(kuid_t uid)
603+
static bool is_non_appuid(kuid_t uid)
604604
{
605605
#define PER_USER_RANGE 100000
606606
#define FIRST_APPLICATION_UID 10000
607-
#define LAST_APPLICATION_UID 19999
608607

609608
uid_t appid = uid.val % PER_USER_RANGE;
610-
return appid >= FIRST_APPLICATION_UID && appid <= LAST_APPLICATION_UID;
609+
return appid < FIRST_APPLICATION_UID;
611610
}
612611

613612
static bool should_umount(struct path *path)
@@ -684,13 +683,25 @@ int ksu_handle_setuid(struct cred *new, const struct cred *old)
684683
return 0;
685684
}
686685

687-
if (!is_appuid(new_uid) || is_unsupported_uid(new_uid.val)) {
688-
// pr_info("handle setuid ignore non application or isolated uid: %d\n", new_uid.val);
686+
if (is_non_appuid(new_uid)) {
687+
#ifdef CONFIG_KSU_DEBUG
688+
pr_info("handle setuid ignore non application uid: %d\n", new_uid.val);
689+
#endif
689690
return 0;
690691
}
691692

693+
// isolated process may be directly forked from zygote, always unmount
694+
if (is_unsupported_app_uid(new_uid.val)) {
695+
#ifdef CONFIG_KSU_DEBUG
696+
pr_info("handle umount for unsupported application uid: %d\n", new_uid.val);
697+
#endif
698+
goto do_umount;
699+
}
700+
692701
if (ksu_is_allow_uid(new_uid.val)) {
693-
// pr_info("handle setuid ignore allowed application: %d\n", new_uid.val);
702+
#ifdef CONFIG_KSU_DEBUG
703+
pr_info("handle setuid ignore allowed application: %d\n", new_uid.val);
704+
#endif
694705
return 0;
695706
}
696707

@@ -702,11 +713,11 @@ int ksu_handle_setuid(struct cred *new, const struct cred *old)
702713
#endif
703714
}
704715

716+
do_umount:
705717
// check old process's selinux context, if it is not zygote, ignore it!
706718
// because some su apps may setuid to untrusted_app but they are in global mount namespace
707719
// when we umount for such process, that is a disaster!
708-
bool is_zygote_child = is_zygote(old->security);
709-
if (!is_zygote_child) {
720+
if (!is_zygote(old->security)) {
710721
pr_info("handle umount ignore non zygote child: %d\n",
711722
current->pid);
712723
return 0;

0 commit comments

Comments
 (0)