From 41b8f854a482a154b00a91726bcb4727a7a16ecc Mon Sep 17 00:00:00 2001 From: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com> Date: Thu, 24 Apr 2025 15:03:09 +0800 Subject: [PATCH] Add KSU_CMDLINE configuration to enable the KernelSU command line option and implement the corresponding status read function Co-authored-by: rsuntk Co-authored-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com> Signed-off-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com> --- kernel/Kconfig | 8 ++++++++ kernel/ksu.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/kernel/Kconfig b/kernel/Kconfig index 42dc5210..81d0cf75 100644 --- a/kernel/Kconfig +++ b/kernel/Kconfig @@ -46,6 +46,14 @@ config KSU_ALLOWLIST_WORKAROUND Enable session keyring init workaround for problematic devices. Useful for situations where the SU allowlist is not kept after a reboot +config KSU_CMDLINE + bool "Enable KernelSU cmdline" + depends on KSU && KSU != m + default n + help + Enable a cmdline called kernelsu.enabled + Value 1 means enabled, value 0 means disabled. + config KPM bool "Enable SukiSU KPM" depends on KSU diff --git a/kernel/ksu.c b/kernel/ksu.c index fc6bd801..adece70e 100644 --- a/kernel/ksu.c +++ b/kernel/ksu.c @@ -15,6 +15,24 @@ #include #endif +#ifdef CONFIG_KSU_CMDLINE +#include + +// use get_ksu_state()! +unsigned int enable_kernelsu = 1; // enabled by default +static int __init read_kernelsu_state(char *s) +{ + if (s) + enable_kernelsu = simple_strtoul(s, NULL, 0); + return 1; +} +__setup("kernelsu.enabled=", read_kernelsu_state); + +bool get_ksu_state(void) { return enable_kernelsu >= 1; } +#else +bool get_ksu_state(void) { return true; } +#endif /* CONFIG_KSU_CMDLINE */ + static struct workqueue_struct *ksu_workqueue; bool ksu_queue_work(struct work_struct *work) @@ -43,6 +61,15 @@ extern void ksu_ksud_exit(); int __init ksu_kernelsu_init(void) { + pr_info("kernelsu.enabled=%d\n", + get_ksu_state()); + +#ifdef CONFIG_KSU_CMDLINE + if (!get_ksu_state()) { + pr_info_once("drivers is disabled."); + return 0; + } +#endif #ifdef CONFIG_KSU_DEBUG pr_alert("*************************************************************"); pr_alert("** NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE **"); @@ -83,6 +110,11 @@ int __init ksu_kernelsu_init(void) void ksu_kernelsu_exit(void) { +#ifdef CONFIG_KSU_CMDLINE + if (!get_ksu_state()) { + return; + } +#endif ksu_allowlist_exit(); ksu_throne_tracker_exit(); @@ -104,6 +136,7 @@ MODULE_LICENSE("GPL"); MODULE_AUTHOR("weishu"); MODULE_DESCRIPTION("Android KernelSU"); +#include #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0) MODULE_IMPORT_NS(VFS_internal_I_am_really_a_filesystem_and_am_NOT_a_driver); #endif