KernelSU: SUS_SU: Initiate path with 0 and no memset is needed
1. kernel & KernelSU: More optimization for SUS_SU mode 2 (Experimental) 2. Always flag zygote spawned isolated service as non-root user app process and no su allowed process 3. Change susfs_fake_qstr_name, shorter length 4. KernelSU: SUS_SU: Initiate path with 0 and no memset is needed Co-authored-by: simonpunk <simonpunk2016@gmail.com>
This commit is contained in:
@@ -1224,17 +1224,29 @@ int ksu_handle_setuid(struct cred *new, const struct cred *old)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_KSU_SUSFS_SUS_MOUNT
|
#ifdef CONFIG_KSU_SUSFS
|
||||||
// check if current process is zygote
|
// check if current process is zygote
|
||||||
bool is_zygote_child = susfs_is_sid_equal(old->security, susfs_zygote_sid);
|
bool is_zygote_child = susfs_is_sid_equal(old->security, susfs_zygote_sid);
|
||||||
|
#endif // #ifdef CONFIG_KSU_SUSFS
|
||||||
if (likely(is_zygote_child)) {
|
if (likely(is_zygote_child)) {
|
||||||
// if spawned process is non user app process
|
// if spawned process is non user app process
|
||||||
if (unlikely(new_uid.val < 10000 && new_uid.val >= 1000)) {
|
if (unlikely(new_uid.val < 10000 && new_uid.val >= 1000)) {
|
||||||
|
#ifdef CONFIG_KSU_SUSFS_SUS_SU
|
||||||
|
// set flag if zygote spawned system process is allowed for root access
|
||||||
|
if (!ksu_is_allow_uid(new_uid.val)) {
|
||||||
|
task_lock(current);
|
||||||
|
susfs_set_current_proc_su_not_allowed();
|
||||||
|
task_unlock(current);
|
||||||
|
}
|
||||||
|
#endif // #ifdef CONFIG_KSU_SUSFS_SUS_SU
|
||||||
|
#ifdef CONFIG_KSU_SUSFS_SUS_MOUNT
|
||||||
// umount for the system process if path DATA_ADB_UMOUNT_FOR_ZYGOTE_SYSTEM_PROCESS exists
|
// umount for the system process if path DATA_ADB_UMOUNT_FOR_ZYGOTE_SYSTEM_PROCESS exists
|
||||||
if (susfs_is_umount_for_zygote_system_process_enabled) {
|
if (susfs_is_umount_for_zygote_system_process_enabled) {
|
||||||
goto out_ksu_try_umount;
|
goto out_ksu_try_umount;
|
||||||
}
|
}
|
||||||
|
#endif // #ifdef CONFIG_KSU_SUSFS_SUS_MOUNT
|
||||||
}
|
}
|
||||||
|
#ifdef CONFIG_KSU_SUSFS
|
||||||
// - here we check if uid is a isolated service spawned by zygote directly
|
// - here we check if uid is a isolated service spawned by zygote directly
|
||||||
// - Apps that do not use "useAppZyogte" to start a isolated service will be directly
|
// - Apps that do not use "useAppZyogte" to start a isolated service will be directly
|
||||||
// spawned by zygote which KSU will ignore it by default, the only fix for now is to
|
// spawned by zygote which KSU will ignore it by default, the only fix for now is to
|
||||||
@@ -1242,14 +1254,21 @@ int ksu_handle_setuid(struct cred *new, const struct cred *old)
|
|||||||
// - Therefore make sure your root app doesn't use isolated service for root access
|
// - Therefore make sure your root app doesn't use isolated service for root access
|
||||||
// - Kudos to ThePedroo, the author and maintainer of Rezygisk for finding and reporting
|
// - Kudos to ThePedroo, the author and maintainer of Rezygisk for finding and reporting
|
||||||
// the detection, really big helps here!
|
// the detection, really big helps here!
|
||||||
else if (new_uid.val >= 90000 && new_uid.val < 1000000 && susfs_is_umount_for_zygote_iso_service_enabled) {
|
else if (new_uid.val >= 90000 && new_uid.val < 1000000) {
|
||||||
task_lock(current);
|
task_lock(current);
|
||||||
susfs_set_current_non_root_user_app_proc();
|
susfs_set_current_non_root_user_app_proc();
|
||||||
|
#ifdef CONFIG_KSU_SUSFS_SUS_SU
|
||||||
|
susfs_set_current_proc_su_not_allowed();
|
||||||
|
#endif
|
||||||
task_unlock(current);
|
task_unlock(current);
|
||||||
|
#ifdef CONFIG_KSU_SUSFS_SUS_MOUNT
|
||||||
|
if (susfs_is_umount_for_zygote_iso_service_enabled) {
|
||||||
goto out_susfs_try_umount_all;
|
goto out_susfs_try_umount_all;
|
||||||
}
|
}
|
||||||
|
#endif // #ifdef CONFIG_KSU_SUSFS_SUS_MOUNT
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif // #ifdef CONFIG_KSU_SUSFS
|
||||||
|
|
||||||
if (!is_appuid(new_uid) || is_unsupported_uid(new_uid.val)) {
|
if (!is_appuid(new_uid) || is_unsupported_uid(new_uid.val)) {
|
||||||
// pr_info("handle setuid ignore non application or isolated uid: %d\n", new_uid.val);
|
// pr_info("handle setuid ignore non application or isolated uid: %d\n", new_uid.val);
|
||||||
@@ -1264,9 +1283,12 @@ int ksu_handle_setuid(struct cred *new, const struct cred *old)
|
|||||||
else {
|
else {
|
||||||
task_lock(current);
|
task_lock(current);
|
||||||
susfs_set_current_non_root_user_app_proc();
|
susfs_set_current_non_root_user_app_proc();
|
||||||
|
#ifdef CONFIG_KSU_SUSFS_SUS_SU
|
||||||
|
susfs_set_current_proc_su_not_allowed();
|
||||||
|
#endif // #ifdef CONFIG_KSU_SUSFS_SUS_SU
|
||||||
task_unlock(current);
|
task_unlock(current);
|
||||||
}
|
}
|
||||||
#endif
|
#endif // #ifdef CONFIG_KSU_SUSFS
|
||||||
|
|
||||||
#ifdef CONFIG_KSU_SUSFS_SUS_MOUNT
|
#ifdef CONFIG_KSU_SUSFS_SUS_MOUNT
|
||||||
out_ksu_try_umount:
|
out_ksu_try_umount:
|
||||||
@@ -1278,7 +1300,7 @@ out_ksu_try_umount:
|
|||||||
pr_info("uid: %d should not umount!\n", current_uid().val);
|
pr_info("uid: %d should not umount!\n", current_uid().val);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#ifndef CONFIG_KSU_SUSFS_SUS_MOUNT
|
#ifndef CONFIG_KSU_SUSFS
|
||||||
// check old process's selinux context, if it is not zygote, ignore it!
|
// 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
|
// 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!
|
// when we umount for such process, that is a disaster!
|
||||||
|
|||||||
@@ -65,12 +65,18 @@ int ksu_handle_faccessat(int *dfd, const char __user **filename_user, int *mode,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef CONFIG_KSU_SUSFS_SUS_SU
|
||||||
if (!ksu_is_allow_uid(current_uid().val)) {
|
if (!ksu_is_allow_uid(current_uid().val)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_KSU_SUSFS_SUS_SU
|
||||||
|
char path[sizeof(su)] = {0};
|
||||||
|
#else
|
||||||
char path[sizeof(su) + 1];
|
char path[sizeof(su) + 1];
|
||||||
memset(path, 0, sizeof(path));
|
memset(path, 0, sizeof(path));
|
||||||
|
#endif
|
||||||
ksu_strncpy_from_user_nofault(path, *filename_user, sizeof(path));
|
ksu_strncpy_from_user_nofault(path, *filename_user, sizeof(path));
|
||||||
|
|
||||||
if (unlikely(!memcmp(path, su, sizeof(su)))) {
|
if (unlikely(!memcmp(path, su, sizeof(su)))) {
|
||||||
@@ -89,10 +95,6 @@ struct filename* susfs_ksu_handle_stat(int *dfd, const char __user **filename_us
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ksu_is_allow_uid(current_uid().val)) {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (likely(memcmp(name->name, su, sizeof(su)))) {
|
if (likely(memcmp(name->name, su, sizeof(su)))) {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@@ -113,16 +115,22 @@ int ksu_handle_stat(int *dfd, const char __user **filename_user, int *flags)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef CONFIG_KSU_SUSFS_SUS_SU
|
||||||
if (!ksu_is_allow_uid(current_uid().val)) {
|
if (!ksu_is_allow_uid(current_uid().val)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (unlikely(!filename_user)) {
|
if (unlikely(!filename_user)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_KSU_SUSFS_SUS_SU
|
||||||
|
char path[sizeof(su)] = {0};
|
||||||
|
#else
|
||||||
char path[sizeof(su) + 1];
|
char path[sizeof(su) + 1];
|
||||||
memset(path, 0, sizeof(path));
|
memset(path, 0, sizeof(path));
|
||||||
|
#endif
|
||||||
// Remove this later!! we use syscall hook, so this will never happen!!!!!
|
// Remove this later!! we use syscall hook, so this will never happen!!!!!
|
||||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 0) && 0
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 0) && 0
|
||||||
// it becomes a `struct filename *` after 5.18
|
// it becomes a `struct filename *` after 5.18
|
||||||
@@ -172,8 +180,10 @@ int ksu_handle_execveat_sucompat(int *fd, struct filename **filename_ptr,
|
|||||||
if (likely(memcmp(filename->name, su, sizeof(su))))
|
if (likely(memcmp(filename->name, su, sizeof(su))))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
#ifndef CONFIG_KSU_SUSFS_SUS_SU
|
||||||
if (!ksu_is_allow_uid(current_uid().val))
|
if (!ksu_is_allow_uid(current_uid().val))
|
||||||
return 0;
|
return 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
pr_info("do_execveat_common su found\n");
|
pr_info("do_execveat_common su found\n");
|
||||||
memcpy((void *)filename->name, ksud_path, sizeof(ksud_path));
|
memcpy((void *)filename->name, ksud_path, sizeof(ksud_path));
|
||||||
@@ -187,8 +197,12 @@ int ksu_handle_execve_sucompat(int *fd, const char __user **filename_user,
|
|||||||
void *__never_use_argv, void *__never_use_envp,
|
void *__never_use_argv, void *__never_use_envp,
|
||||||
int *__never_use_flags)
|
int *__never_use_flags)
|
||||||
{
|
{
|
||||||
// const char su[] = SU_PATH;
|
//const char su[] = SU_PATH;
|
||||||
|
#ifdef CONFIG_KSU_SUSFS_SUS_SU
|
||||||
|
char path[sizeof(su)] = {0};
|
||||||
|
#else
|
||||||
char path[sizeof(su) + 1];
|
char path[sizeof(su) + 1];
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef CONFIG_KSU_KPROBES_HOOK
|
#ifndef CONFIG_KSU_KPROBES_HOOK
|
||||||
if (!ksu_sucompat_hook_state) {
|
if (!ksu_sucompat_hook_state) {
|
||||||
@@ -215,7 +229,6 @@ int ksu_handle_execve_sucompat(int *fd, const char __user **filename_user,
|
|||||||
long len = strncpy_from_user(path, *filename_user, sizeof(path));
|
long len = strncpy_from_user(path, *filename_user, sizeof(path));
|
||||||
if (len <= 0 || len > sizeof(path))
|
if (len <= 0 || len > sizeof(path))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// strncpy_from_user_nofault does this too
|
// strncpy_from_user_nofault does this too
|
||||||
path[sizeof(path) - 1] = '\0';
|
path[sizeof(path) - 1] = '\0';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user