Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions kernel/allowlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#define PER_USER_RANGE 100000
#define FIRST_APPLICATION_UID 10000
#define LAST_APPLICATION_UID 19999
#define FIRST_ISOLATED_UID 99000
#define LAST_ISOLATED_UID 99999

void ksu_allowlist_init(void);

Expand Down Expand Up @@ -40,4 +42,10 @@ static inline bool is_appuid(uid_t uid)
uid_t appid = uid % PER_USER_RANGE;
return appid >= FIRST_APPLICATION_UID && appid <= LAST_APPLICATION_UID;
}

static inline bool is_isolated_process(uid_t uid)
{
uid_t appid = uid % PER_USER_RANGE;
return appid >= FIRST_ISOLATED_UID && appid <= LAST_ISOLATED_UID;
}
#endif
14 changes: 10 additions & 4 deletions kernel/kernel_umount.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ int ksu_handle_umount(uid_t old_uid, uid_t new_uid)
{
struct umount_tw *tw;

// this hook is used for umounting overlayfs for some uid, if there isn't any module mounted, just ignore it!
// if there isn't any module mounted, just ignore it!
if (!ksu_module_mounted) {
return 0;
}
Expand All @@ -110,18 +110,24 @@ int ksu_handle_umount(uid_t old_uid, uid_t new_uid)
return 0;
}

// FIXME: isolated process which directly forks from zygote is not handled
if (!is_appuid(new_uid)) {
// There are 5 scenarios:
// 1. Normal app: zygote -> appuid
// 2. Isolated process forked from zygote: zygote -> isolated_process
// 3. App zygote forked from zygote: zygote -> appuid
// 4. Isolated process froked from app zygote: appuid -> isolated_process (already handled by 3)
// 5. Isolated process froked from webview zygote (no need to handle, app cannot run custom code)
if (!is_appuid(new_uid) && !is_isolated_process(new_uid)) {
return 0;
}

if (!ksu_uid_should_umount(new_uid)) {
if (!ksu_uid_should_umount(new_uid) && !is_isolated_process(new_uid)) {
return 0;
}

// check old process's selinux context, if it is not zygote, ignore it!
// because some su apps may setuid to untrusted_app but they are in global mount namespace
// when we umount for such process, that is a disaster!
// also handle case 4 and 5
bool is_zygote_child = is_zygote(get_current_cred());
if (!is_zygote_child) {
pr_info("handle umount ignore non zygote child: %d\n", current->pid);
Expand Down