Skip to content

Commit 9887400

Browse files
committed
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]> -10/7/25: fix mismerge (add missing do_umount label) -This is temp., to allow history from the proceeding changes to remain in-tact.
1 parent 7bcb31c commit 9887400

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

kernel/core_hook.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ static inline bool is_allow_su()
149149
return ksu_is_allow_uid(current_uid().val);
150150
}
151151

152-
static inline bool is_unsupported_uid(uid_t uid)
152+
static inline bool is_unsupported_app_uid(uid_t uid)
153153
{
154154
#define LAST_APPLICATION_UID 19999
155155
uid_t appid = uid % 100000;
@@ -1067,14 +1067,13 @@ LSM_HANDLER_TYPE ksu_handle_prctl(int option, unsigned long arg2, unsigned long
10671067
return 0;
10681068
}
10691069

1070-
static bool is_appuid(kuid_t uid)
1070+
static bool is_non_appuid(kuid_t uid)
10711071
{
10721072
#define PER_USER_RANGE 100000
10731073
#define FIRST_APPLICATION_UID 10000
1074-
#define LAST_APPLICATION_UID 19999
10751074

10761075
uid_t appid = uid.val % PER_USER_RANGE;
1077-
return appid >= FIRST_APPLICATION_UID && appid <= LAST_APPLICATION_UID;
1076+
return appid < FIRST_APPLICATION_UID;
10781077
}
10791078

10801079
static bool should_umount(struct path *path)
@@ -1231,13 +1230,26 @@ LSM_HANDLER_TYPE ksu_handle_setuid(struct cred *new, const struct cred *old)
12311230
}
12321231
#endif // #ifdef CONFIG_KSU_SUSFS
12331232

1234-
if (!is_appuid(new_uid) || is_unsupported_uid(new_uid.val)) {
1235-
// pr_info("handle setuid ignore non application or isolated uid: %d\n", new_uid.val);
1233+
if (is_non_appuid(new_uid)) {
1234+
#ifdef CONFIG_KSU_DEBUG
1235+
pr_info("handle setuid ignore non application uid: %d\n", new_uid.val);
1236+
#endif
12361237
return 0;
12371238
}
12381239

1240+
1241+
// isolated process may be directly forked from zygote, always unmount
1242+
if (is_unsupported_app_uid(new_uid.val)) {
1243+
#ifdef CONFIG_KSU_DEBUG
1244+
pr_info("handle umount for unsupported application uid: %d\n", new_uid.val);
1245+
#endif
1246+
goto do_umount;
1247+
}
1248+
12391249
if (ksu_is_allow_uid(new_uid.val)) {
1240-
// pr_info("handle setuid ignore allowed application: %d\n", new_uid.val);
1250+
#ifdef CONFIG_KSU_DEBUG
1251+
pr_info("handle setuid ignore allowed application: %d\n", new_uid.val);
1252+
#endif
12411253
return 0;
12421254
}
12431255
#ifdef CONFIG_KSU_SUSFS
@@ -1265,13 +1277,11 @@ LSM_HANDLER_TYPE ksu_handle_setuid(struct cred *new, const struct cred *old)
12651277
#endif
12661278
}
12671279

1268-
#ifndef CONFIG_KSU_SUSFS
1280+
do_umount:
12691281
// check old process's selinux context, if it is not zygote, ignore it!
12701282
// because some su apps may setuid to untrusted_app but they are in global mount namespace
12711283
// when we umount for such process, that is a disaster!
1272-
bool is_zygote_child = is_zygote(old->security);
1273-
#endif
1274-
if (!is_zygote_child) {
1284+
if (!is_zygote(old->security)) {
12751285
pr_info("handle umount ignore non zygote child: %d\n",
12761286
current->pid);
12771287
return 0;

0 commit comments

Comments
 (0)