kernel: added CMD_HOOK_MODE prctl to get the enabled su hook mode value

This commit is contained in:
rifsxd
2025-05-21 17:19:59 +06:00
parent 3b1d5f15f4
commit ce37e17c87
6 changed files with 42 additions and 0 deletions

View File

@@ -339,6 +339,18 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3,
return 0;
}
if (arg2 == CMD_HOOK_MODE) {
#ifdef CONFIG_KSU_KPROBES_HOOK
const char *mode = "Kprobes";
#else
const char *mode = "Manual";
#endif
if (copy_to_user((void __user *)arg3, mode, strlen(mode) + 1)) {
pr_info("hook: copy_to_user() failed\n");
}
return 0;
}
if (arg2 == CMD_REPORT_EVENT) {
if (!from_root) {
return 0;

View File

@@ -23,6 +23,7 @@
#define CMD_UID_SHOULD_UMOUNT 13
#define CMD_IS_SU_ENABLED 14
#define CMD_ENABLE_SU 15
#define CMD_HOOK_MODE 16
#define EVENT_POST_FS_DATA 1
#define EVENT_BOOT_COMPLETED 2

View File

@@ -25,6 +25,16 @@ Java_com_rifsxd_ksunext_Natives_getVersion(JNIEnv *env, jobject) {
return get_version();
}
extern "C"
JNIEXPORT jstring JNICALL
Java_com_rifsxd_ksunext_Natives_getHookMode(JNIEnv *env, jobject) {
char mode[16] = {0};
if (get_hook_mode(mode, sizeof(mode))) {
return env->NewStringUTF(mode);
}
return nullptr;
}
extern "C"
JNIEXPORT jintArray JNICALL
Java_com_rifsxd_ksunext_Natives_getAllowList(JNIEnv *env, jobject) {

View File

@@ -29,6 +29,7 @@
#define CMD_IS_UID_SHOULD_UMOUNT 13
#define CMD_IS_SU_ENABLED 14
#define CMD_ENABLE_SU 15
#define CMD_HOOK_MODE 16
static bool ksuctl(int cmd, void* arg1, void* arg2) {
int32_t result = 0;
@@ -61,6 +62,12 @@ int get_version() {
return version;
}
bool get_hook_mode(char *mode, int mode_len) {
if (!mode || mode_len == 0) return false;
memset(mode, 0, mode_len);
return ksuctl(CMD_HOOK_MODE, mode, nullptr);
}
bool get_allow_list(int *uids, int *size) {
return ksuctl(CMD_GET_SU_LIST, uids, size);
}

View File

@@ -11,6 +11,8 @@ bool become_manager(const char *);
int get_version();
bool get_hook_mode(char *mode, int mode_len);
bool get_allow_list(int *uids, int *size);
bool uid_should_umount(int uid);

View File

@@ -50,6 +50,16 @@ object Natives {
external fun uidShouldUmount(uid: Int): Boolean
/**
* Get a string indicating the SU hook mode enabled in kernel.
* The return values are:
* - "Manual": Manual hooks was enabled.
* - "Kprobes": Kprobes hooks was enabled (CONFIG_KSU_KPROBES_HOOK).
*
* @return return hook mode, or null if unavailable.
*/
external fun getHookMode(): String?
/**
* Get the profile of the given package.
* @param key usually the package name