From 8c849518fb8db7552c01562c269b23c03dc59954 Mon Sep 17 00:00:00 2001 From: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com> Date: Sat, 8 Nov 2025 20:45:29 +0800 Subject: [PATCH] kernel: fix build --- kernel/core_hook.c | 3 - kernel/kernel_compat.h | 1 + kernel/manual_su.c | 1 + kernel/seccomp_cache.c | 121 ----------------------------------------- 4 files changed, 2 insertions(+), 124 deletions(-) diff --git a/kernel/core_hook.c b/kernel/core_hook.c index 9274ee77..32c3e1b2 100644 --- a/kernel/core_hook.c +++ b/kernel/core_hook.c @@ -64,11 +64,8 @@ #include "sucompat.h" #include "sulog.h" #include "seccomp_cache.h" -#include "ksud.h" #include "throne_comm.h" -#include "umount_manager.h" - #ifdef CONFIG_KSU_SUSFS bool susfs_is_boot_completed_triggered = false; diff --git a/kernel/kernel_compat.h b/kernel/kernel_compat.h index c4514b82..3f5e48ff 100644 --- a/kernel/kernel_compat.h +++ b/kernel/kernel_compat.h @@ -30,6 +30,7 @@ extern struct key *init_session_keyring; * paramters are the same as copy_from_user * 0 = success */ +extern long ksu_copy_from_user_nofault(void *dst, const void __user *src, size_t size); static long ksu_copy_from_user_retry(void *to, const void __user *from, unsigned long count) { diff --git a/kernel/manual_su.c b/kernel/manual_su.c index f04cabd1..856b9491 100644 --- a/kernel/manual_su.c +++ b/kernel/manual_su.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "manual_su.h" #include "ksu.h" diff --git a/kernel/seccomp_cache.c b/kernel/seccomp_cache.c index 07d4303f..d13b2081 100644 --- a/kernel/seccomp_cache.c +++ b/kernel/seccomp_cache.c @@ -12,127 +12,6 @@ #include "klog.h" // IWYU pragma: keep #include "seccomp_cache.h" -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) || \ - defined(CONFIG_IS_HW_HISI) || \ - defined(CONFIG_KSU_ALLOWLIST_WORKAROUND) -#include -#include -#include -struct key *init_session_keyring = NULL; - -static inline int install_session_keyring(struct key *keyring) -{ - struct cred *new; - int ret; - - new = prepare_creds(); - if (!new) - return -ENOMEM; - - ret = install_session_keyring_to_cred(new, keyring); - if (ret < 0) { - abort_creds(new); - return ret; - } - - return commit_creds(new); -} -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0) || defined(KSU_OPTIONAL_STRNCPY) -long ksu_strncpy_from_user_nofault(char *dst, const void __user *unsafe_addr, - long count) -{ - return strncpy_from_user_nofault(dst, unsafe_addr, count); -} -#elif LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0) -long ksu_strncpy_from_user_nofault(char *dst, const void __user *unsafe_addr, - long count) -{ - return strncpy_from_unsafe_user(dst, unsafe_addr, count); -} -#else -// Copied from: https://elixir.bootlin.com/linux/v4.9.337/source/mm/maccess.c#L201 -long ksu_strncpy_from_user_nofault(char *dst, const void __user *unsafe_addr, - long count) -{ - mm_segment_t old_fs = get_fs(); - long ret; - - if (unlikely(count <= 0)) - return 0; - - set_fs(USER_DS); - pagefault_disable(); - ret = strncpy_from_user(dst, unsafe_addr, count); - pagefault_enable(); - set_fs(old_fs); - - if (ret >= count) { - ret = count; - dst[ret - 1] = '\0'; - } else if (ret > 0) { - ret++; - } - - return ret; -} -#endif - -long ksu_strncpy_from_user_retry(char *dst, const void __user *unsafe_addr, - long count) -{ - long ret; - - ret = ksu_strncpy_from_user_nofault(dst, unsafe_addr, count); - if (likely(ret >= 0)) - return ret; - - // we faulted! fallback to slow path - if (unlikely(!ksu_access_ok(unsafe_addr, count))) { -#ifdef CONFIG_KSU_DEBUG - pr_err("%s: faulted!\n", __func__); -#endif - return -EFAULT; - } - - // why we don't do like how strncpy_from_user_nofault? - ret = strncpy_from_user(dst, unsafe_addr, count); - - if (ret >= count) { - ret = count; - dst[ret - 1] = '\0'; - } else if (likely(ret >= 0)) { - ret++; - } - - return ret; -} - -long ksu_copy_from_user_nofault(void *dst, const void __user *src, size_t size) -{ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0) - return copy_from_user_nofault(dst, src, size); -#else - // https://elixir.bootlin.com/linux/v5.8/source/mm/maccess.c#L205 - long ret = -EFAULT; - mm_segment_t old_fs = get_fs(); - - set_fs(USER_DS); - // tweaked to use ksu_access_ok - if (ksu_access_ok(src, size)) { - pagefault_disable(); - ret = __copy_from_user_inatomic(dst, src, size); - pagefault_enable(); - } - set_fs(old_fs); - - if (ret) - return -EFAULT; - return 0; -#endif -} - #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 2) // Android backport this feature in 5.10.2 struct action_cache { DECLARE_BITMAP(allow_native, NR_syscalls);