Skip to content

Commit 5dcc2eb

Browse files
aviraxpbackslashxx
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 a35aec4 commit 5dcc2eb

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

65-
static inline bool is_unsupported_uid(uid_t uid)
65+
static inline bool is_unsupported_app_uid(uid_t uid)
6666
{
6767
#define LAST_APPLICATION_UID 19999
6868
uid_t appid = uid % 100000;
@@ -468,14 +468,13 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3,
468468
return 0;
469469
}
470470

471-
static bool is_appuid(kuid_t uid)
471+
static bool is_non_appuid(kuid_t uid)
472472
{
473473
#define PER_USER_RANGE 100000
474474
#define FIRST_APPLICATION_UID 10000
475-
#define LAST_APPLICATION_UID 19999
476475

477476
uid_t appid = uid.val % PER_USER_RANGE;
478-
return appid >= FIRST_APPLICATION_UID && appid <= LAST_APPLICATION_UID;
477+
return appid < FIRST_APPLICATION_UID;
479478
}
480479

481480
static bool should_umount(struct path *path)
@@ -547,13 +546,25 @@ int ksu_handle_setuid(struct cred *new, const struct cred *old)
547546
return 0;
548547
}
549548

550-
if (!is_appuid(new_uid) || is_unsupported_uid(new_uid.val)) {
551-
// pr_info("handle setuid ignore non application or isolated uid: %d\n", new_uid.val);
549+
if (is_non_appuid(new_uid)) {
550+
#ifdef CONFIG_KSU_DEBUG
551+
pr_info("handle setuid ignore non application uid: %d\n", new_uid.val);
552+
#endif
552553
return 0;
553554
}
554555

556+
// isolated process may be directly forked from zygote, always unmount
557+
if (is_unsupported_app_uid(new_uid.val)) {
558+
#ifdef CONFIG_KSU_DEBUG
559+
pr_info("handle umount for unsupported application uid: %d\n", new_uid.val);
560+
#endif
561+
goto do_umount;
562+
}
563+
555564
if (ksu_is_allow_uid(new_uid.val)) {
556-
// pr_info("handle setuid ignore allowed application: %d\n", new_uid.val);
565+
#ifdef CONFIG_KSU_DEBUG
566+
pr_info("handle setuid ignore allowed application: %d\n", new_uid.val);
567+
#endif
557568
return 0;
558569
}
559570

@@ -565,11 +576,11 @@ int ksu_handle_setuid(struct cred *new, const struct cred *old)
565576
#endif
566577
}
567578

579+
do_umount:
568580
// check old process's selinux context, if it is not zygote, ignore it!
569581
// because some su apps may setuid to untrusted_app but they are in global mount namespace
570582
// when we umount for such process, that is a disaster!
571-
bool is_zygote_child = is_zygote(old->security);
572-
if (!is_zygote_child) {
583+
if (!is_zygote(old->security)) {
573584
pr_info("handle umount ignore non zygote child: %d\n",
574585
current->pid);
575586
return 0;

0 commit comments

Comments
 (0)