[skip ci]kernel: Migrating KPM to ioctl

This commit is contained in:
ShirkNeko
2025-11-04 00:09:42 +08:00
parent 7103779a11
commit d286f49e11
5 changed files with 51 additions and 35 deletions

View File

@@ -45,10 +45,6 @@
#include "manual_su.h" #include "manual_su.h"
#endif #endif
#ifdef CONFIG_KPM
#include "kpm/kpm.h"
#endif
bool ksu_module_mounted = false; bool ksu_module_mounted = false;
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
@@ -442,18 +438,6 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3,
pr_info("option: 0x%x, cmd: %ld\n", option, arg2); pr_info("option: 0x%x, cmd: %ld\n", option, arg2);
#endif #endif
#ifdef CONFIG_KPM
if(sukisu_is_kpm_control_code(arg2)) {
int res;
pr_info("KPM: calling before arg2=%d\n", (int) arg2);
res = sukisu_handle_kpm(arg2, arg3, arg4, arg5);
return 0;
}
#endif
#ifdef CONFIG_KSU_MANUAL_SU #ifdef CONFIG_KSU_MANUAL_SU
if (arg2 == CMD_MANUAL_SU_REQUEST) { if (arg2 == CMD_MANUAL_SU_REQUEST) {
struct manual_su_request request; struct manual_su_request request;

View File

@@ -209,3 +209,16 @@ int sukisu_is_kpm_control_code(unsigned long arg2) {
return (arg2 >= CMD_KPM_CONTROL && return (arg2 >= CMD_KPM_CONTROL &&
arg2 <= CMD_KPM_CONTROL_MAX) ? 1 : 0; arg2 <= CMD_KPM_CONTROL_MAX) ? 1 : 0;
} }
int do_kpm(void __user *arg)
{
struct ksu_kpm_cmd cmd;
if (copy_from_user(&cmd, arg, sizeof(cmd))) {
pr_err("kpm: copy_from_user failed\n");
return -EFAULT;
}
return sukisu_handle_kpm(cmd.arg2, cmd.arg3, cmd.arg4, cmd.arg5);
}

View File

@@ -1,58 +1,70 @@
#ifndef __SUKISU_KPM_H #ifndef __SUKISU_KPM_H
#define __SUKISU_KPM_H #define __SUKISU_KPM_H
extern int sukisu_handle_kpm(unsigned long arg2, unsigned long arg3, unsigned long arg4, #include <linux/types.h>
unsigned long arg5); #include <linux/ioctl.h>
extern int sukisu_is_kpm_control_code(unsigned long arg2);
struct ksu_kpm_cmd {
__aligned_u64 arg2;
__aligned_u64 arg3;
__aligned_u64 arg4;
__aligned_u64 arg5;
};
int sukisu_handle_kpm(unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5);
int sukisu_is_kpm_control_code(unsigned long arg2);
int do_kpm(void __user *arg);
#define KSU_IOCTL_KPM _IOC(_IOC_READ|_IOC_WRITE, 'K', 200, 0)
/* KPM Control Code */ /* KPM Control Code */
#define CMD_KPM_CONTROL 28 #define CMD_KPM_CONTROL 1
#define CMD_KPM_CONTROL_MAX 35 #define CMD_KPM_CONTROL_MAX 10
/* Control Code */ /* Control Code */
/* /*
* prctl(xxx, 28, "PATH", "ARGS") * prctl(xxx, 1, "PATH", "ARGS")
* success return 0, error return -N * success return 0, error return -N
*/ */
#define SUKISU_KPM_LOAD 28 #define SUKISU_KPM_LOAD 1
/* /*
* prctl(xxx, 29, "NAME") * prctl(xxx, 2, "NAME")
* success return 0, error return -N * success return 0, error return -N
*/ */
#define SUKISU_KPM_UNLOAD 29 #define SUKISU_KPM_UNLOAD 2
/* /*
* num = prctl(xxx, 30) * num = prctl(xxx, 3)
* error return -N * error return -N
* success return +num or 0 * success return +num or 0
*/ */
#define SUKISU_KPM_NUM 30 #define SUKISU_KPM_NUM 3
/* /*
* prctl(xxx, 31, Buffer, BufferSize) * prctl(xxx, 4, Buffer, BufferSize)
* success return +out, error return -N * success return +out, error return -N
*/ */
#define SUKISU_KPM_LIST 31 #define SUKISU_KPM_LIST 4
/* /*
* prctl(xxx, 32, "NAME", Buffer[256]) * prctl(xxx, 5, "NAME", Buffer[256])
* success return +out, error return -N * success return +out, error return -N
*/ */
#define SUKISU_KPM_INFO 32 #define SUKISU_KPM_INFO 5
/* /*
* prctl(xxx, 33, "NAME", "ARGS") * prctl(xxx, 6, "NAME", "ARGS")
* success return KPM's result value * success return KPM's result value
* error return -N * error return -N
*/ */
#define SUKISU_KPM_CONTROL 33 #define SUKISU_KPM_CONTROL 6
/* /*
* prctl(xxx, 34, buffer, bufferSize) * prctl(xxx, 7, buffer, bufferSize)
* success return KPM's result value * success return KPM's result value
* error return -N * error return -N
*/ */
#define SUKISU_KPM_VERSION 34 #define SUKISU_KPM_VERSION 7
#endif #endif

View File

@@ -542,6 +542,9 @@ static const struct ksu_ioctl_cmd_map ksu_ioctl_handlers[] = {
{ .cmd = KSU_IOCTL_DYNAMIC_MANAGER, .name = "SET_DYNAMIC_MANAGER", .handler = do_dynamic_manager, .perm_check = manager_or_root}, { .cmd = KSU_IOCTL_DYNAMIC_MANAGER, .name = "SET_DYNAMIC_MANAGER", .handler = do_dynamic_manager, .perm_check = manager_or_root},
{ .cmd = KSU_IOCTL_GET_MANAGERS, .name = "GET_MANAGERS", .handler = do_get_managers, .perm_check = manager_or_root}, { .cmd = KSU_IOCTL_GET_MANAGERS, .name = "GET_MANAGERS", .handler = do_get_managers, .perm_check = manager_or_root},
{ .cmd = KSU_IOCTL_ENABLE_UID_SCANNER, .name = "SET_ENABLE_UID_SCANNER", .handler = do_enable_uid_scanner, .perm_check = manager_or_root}, { .cmd = KSU_IOCTL_ENABLE_UID_SCANNER, .name = "SET_ENABLE_UID_SCANNER", .handler = do_enable_uid_scanner, .perm_check = manager_or_root},
#ifdef CONFIG_KPM
{ .cmd = KSU_IOCTL_KPM, .name = "KPM_OPERATION", .handler = do_kpm, .perm_check = manager_or_root},
#endif
{ .cmd = 0, .name = NULL, .handler = NULL, .perm_check = NULL} // Sentine { .cmd = 0, .name = NULL, .handler = NULL, .perm_check = NULL} // Sentine
}; };

View File

@@ -5,6 +5,10 @@
#include <linux/ioctl.h> #include <linux/ioctl.h>
#include "ksu.h" #include "ksu.h"
#ifdef CONFIG_KPM
#include "kpm/kpm.h"
#endif
// Magic numbers for reboot hook to install fd // Magic numbers for reboot hook to install fd
#define KSU_INSTALL_MAGIC1 0xDEADBEEF #define KSU_INSTALL_MAGIC1 0xDEADBEEF
#define KSU_INSTALL_MAGIC2 0xCAFEBABE #define KSU_INSTALL_MAGIC2 0xCAFEBABE