kernel: fmt
This commit is contained in:
@@ -31,70 +31,70 @@
|
||||
|
||||
static int sukisu_is_su_allow_uid(uid_t uid)
|
||||
{
|
||||
return ksu_is_allow_uid_for_current(uid) ? 1 : 0;
|
||||
return ksu_is_allow_uid_for_current(uid) ? 1 : 0;
|
||||
}
|
||||
|
||||
static int sukisu_get_ap_mod_exclude(uid_t uid)
|
||||
{
|
||||
return 0; /* Not supported */
|
||||
return 0; /* Not supported */
|
||||
}
|
||||
|
||||
static int sukisu_is_uid_should_umount(uid_t uid)
|
||||
{
|
||||
return ksu_uid_should_umount(uid) ? 1 : 0;
|
||||
return ksu_uid_should_umount(uid) ? 1 : 0;
|
||||
}
|
||||
|
||||
static int sukisu_is_current_uid_manager(void)
|
||||
{
|
||||
return is_manager();
|
||||
return is_manager();
|
||||
}
|
||||
|
||||
static uid_t sukisu_get_manager_uid(void)
|
||||
{
|
||||
return ksu_manager_uid;
|
||||
return ksu_manager_uid;
|
||||
}
|
||||
|
||||
static void sukisu_set_manager_uid(uid_t uid, int force)
|
||||
{
|
||||
if (force || ksu_manager_uid == -1)
|
||||
ksu_manager_uid = uid;
|
||||
if (force || ksu_manager_uid == -1)
|
||||
ksu_manager_uid = uid;
|
||||
}
|
||||
|
||||
struct CompactAddressSymbol {
|
||||
const char *symbol_name;
|
||||
void *addr;
|
||||
const char *symbol_name;
|
||||
void *addr;
|
||||
};
|
||||
|
||||
unsigned long sukisu_compact_find_symbol(const char *name);
|
||||
|
||||
static struct CompactAddressSymbol address_symbol[] = {
|
||||
{ "kallsyms_lookup_name", &kallsyms_lookup_name },
|
||||
{ "compact_find_symbol", &sukisu_compact_find_symbol },
|
||||
{ "is_run_in_sukisu_ultra", (void *)1 },
|
||||
{ "is_su_allow_uid", &sukisu_is_su_allow_uid },
|
||||
{ "get_ap_mod_exclude", &sukisu_get_ap_mod_exclude },
|
||||
{ "is_uid_should_umount", &sukisu_is_uid_should_umount },
|
||||
{ "is_current_uid_manager", &sukisu_is_current_uid_manager },
|
||||
{ "get_manager_uid", &sukisu_get_manager_uid },
|
||||
{ "sukisu_set_manager_uid", &sukisu_set_manager_uid }
|
||||
{ "kallsyms_lookup_name", &kallsyms_lookup_name },
|
||||
{ "compact_find_symbol", &sukisu_compact_find_symbol },
|
||||
{ "is_run_in_sukisu_ultra", (void *)1 },
|
||||
{ "is_su_allow_uid", &sukisu_is_su_allow_uid },
|
||||
{ "get_ap_mod_exclude", &sukisu_get_ap_mod_exclude },
|
||||
{ "is_uid_should_umount", &sukisu_is_uid_should_umount },
|
||||
{ "is_current_uid_manager", &sukisu_is_current_uid_manager },
|
||||
{ "get_manager_uid", &sukisu_get_manager_uid },
|
||||
{ "sukisu_set_manager_uid", &sukisu_set_manager_uid }
|
||||
};
|
||||
|
||||
unsigned long sukisu_compact_find_symbol(const char* name)
|
||||
{
|
||||
int i;
|
||||
unsigned long addr;
|
||||
int i;
|
||||
unsigned long addr;
|
||||
|
||||
for (i = 0; i < (sizeof(address_symbol) / sizeof(struct CompactAddressSymbol)); i++) {
|
||||
struct CompactAddressSymbol *symbol = &address_symbol[i];
|
||||
|
||||
if (strcmp(name, symbol->symbol_name) == 0)
|
||||
return (unsigned long)symbol->addr;
|
||||
}
|
||||
for (i = 0; i < (sizeof(address_symbol) / sizeof(struct CompactAddressSymbol)); i++) {
|
||||
struct CompactAddressSymbol *symbol = &address_symbol[i];
|
||||
|
||||
if (strcmp(name, symbol->symbol_name) == 0)
|
||||
return (unsigned long)symbol->addr;
|
||||
}
|
||||
|
||||
addr = kallsyms_lookup_name(name);
|
||||
if (addr)
|
||||
return addr;
|
||||
addr = kallsyms_lookup_name(name);
|
||||
if (addr)
|
||||
return addr;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(sukisu_compact_find_symbol);
|
||||
|
||||
300
kernel/kpm/kpm.c
300
kernel/kpm/kpm.c
@@ -44,240 +44,240 @@
|
||||
|
||||
#ifndef NO_OPTIMIZE
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
#define NO_OPTIMIZE __attribute__((optimize("O0")))
|
||||
#define NO_OPTIMIZE __attribute__((optimize("O0")))
|
||||
#elif defined(__clang__)
|
||||
#define NO_OPTIMIZE __attribute__((optnone))
|
||||
#define NO_OPTIMIZE __attribute__((optnone))
|
||||
#else
|
||||
#define NO_OPTIMIZE
|
||||
#define NO_OPTIMIZE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
noinline NO_OPTIMIZE void sukisu_kpm_load_module_path(const char *path,
|
||||
const char *args, void *ptr, int *result)
|
||||
const char *args, void *ptr, int *result)
|
||||
{
|
||||
pr_info("kpm: Stub function called (sukisu_kpm_load_module_path). "
|
||||
"path=%s args=%s ptr=%p\n", path, args, ptr);
|
||||
pr_info("kpm: Stub function called (sukisu_kpm_load_module_path). "
|
||||
"path=%s args=%s ptr=%p\n", path, args, ptr);
|
||||
|
||||
__asm__ volatile("nop");
|
||||
__asm__ volatile("nop");
|
||||
}
|
||||
EXPORT_SYMBOL(sukisu_kpm_load_module_path);
|
||||
|
||||
noinline NO_OPTIMIZE void sukisu_kpm_unload_module(const char *name,
|
||||
void *ptr, int *result)
|
||||
void *ptr, int *result)
|
||||
{
|
||||
pr_info("kpm: Stub function called (sukisu_kpm_unload_module). "
|
||||
"name=%s ptr=%p\n", name, ptr);
|
||||
pr_info("kpm: Stub function called (sukisu_kpm_unload_module). "
|
||||
"name=%s ptr=%p\n", name, ptr);
|
||||
|
||||
__asm__ volatile("nop");
|
||||
__asm__ volatile("nop");
|
||||
}
|
||||
EXPORT_SYMBOL(sukisu_kpm_unload_module);
|
||||
|
||||
noinline NO_OPTIMIZE void sukisu_kpm_num(int *result)
|
||||
{
|
||||
pr_info("kpm: Stub function called (sukisu_kpm_num).\n");
|
||||
pr_info("kpm: Stub function called (sukisu_kpm_num).\n");
|
||||
|
||||
__asm__ volatile("nop");
|
||||
__asm__ volatile("nop");
|
||||
}
|
||||
EXPORT_SYMBOL(sukisu_kpm_num);
|
||||
|
||||
noinline NO_OPTIMIZE void sukisu_kpm_info(const char *name, char *buf, int bufferSize,
|
||||
int *size)
|
||||
int *size)
|
||||
{
|
||||
pr_info("kpm: Stub function called (sukisu_kpm_info). "
|
||||
"name=%s buffer=%p\n", name, buf);
|
||||
pr_info("kpm: Stub function called (sukisu_kpm_info). "
|
||||
"name=%s buffer=%p\n", name, buf);
|
||||
|
||||
__asm__ volatile("nop");
|
||||
__asm__ volatile("nop");
|
||||
}
|
||||
EXPORT_SYMBOL(sukisu_kpm_info);
|
||||
|
||||
noinline NO_OPTIMIZE void sukisu_kpm_list(void *out, int bufferSize,
|
||||
int *result)
|
||||
int *result)
|
||||
{
|
||||
pr_info("kpm: Stub function called (sukisu_kpm_list). "
|
||||
"buffer=%p size=%d\n", out, bufferSize);
|
||||
pr_info("kpm: Stub function called (sukisu_kpm_list). "
|
||||
"buffer=%p size=%d\n", out, bufferSize);
|
||||
}
|
||||
EXPORT_SYMBOL(sukisu_kpm_list);
|
||||
|
||||
noinline NO_OPTIMIZE void sukisu_kpm_control(const char *name, const char *args, long arg_len,
|
||||
int *result)
|
||||
int *result)
|
||||
{
|
||||
pr_info("kpm: Stub function called (sukisu_kpm_control). "
|
||||
"name=%p args=%p arg_len=%ld\n", name, args, arg_len);
|
||||
pr_info("kpm: Stub function called (sukisu_kpm_control). "
|
||||
"name=%p args=%p arg_len=%ld\n", name, args, arg_len);
|
||||
|
||||
__asm__ volatile("nop");
|
||||
__asm__ volatile("nop");
|
||||
}
|
||||
EXPORT_SYMBOL(sukisu_kpm_control);
|
||||
|
||||
noinline NO_OPTIMIZE void sukisu_kpm_version(char *buf, int bufferSize)
|
||||
{
|
||||
pr_info("kpm: Stub function called (sukisu_kpm_version). "
|
||||
"buffer=%p\n", buf);
|
||||
pr_info("kpm: Stub function called (sukisu_kpm_version). "
|
||||
"buffer=%p\n", buf);
|
||||
}
|
||||
EXPORT_SYMBOL(sukisu_kpm_version);
|
||||
|
||||
noinline int sukisu_handle_kpm(unsigned long control_code, unsigned long arg1, unsigned long arg2,
|
||||
unsigned long result_code)
|
||||
unsigned long result_code)
|
||||
{
|
||||
int res = -1;
|
||||
if (control_code == SUKISU_KPM_LOAD) {
|
||||
char kernel_load_path[256];
|
||||
char kernel_args_buffer[256];
|
||||
int res = -1;
|
||||
if (control_code == SUKISU_KPM_LOAD) {
|
||||
char kernel_load_path[256];
|
||||
char kernel_args_buffer[256];
|
||||
|
||||
if (arg1 == 0) {
|
||||
res = -EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
if (arg1 == 0) {
|
||||
res = -EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!ksu_access_ok(arg1, sizeof(kernel_load_path))) {
|
||||
goto invalid_arg;
|
||||
}
|
||||
|
||||
strncpy_from_user((char *)&kernel_load_path, (const char *)arg1, sizeof(kernel_load_path));
|
||||
|
||||
if (arg2 != 0) {
|
||||
if (!ksu_access_ok(arg2, sizeof(kernel_args_buffer))) {
|
||||
goto invalid_arg;
|
||||
}
|
||||
if (!ksu_access_ok(arg1, sizeof(kernel_load_path))) {
|
||||
goto invalid_arg;
|
||||
}
|
||||
|
||||
strncpy_from_user((char *)&kernel_load_path, (const char *)arg1, sizeof(kernel_load_path));
|
||||
|
||||
if (arg2 != 0) {
|
||||
if (!ksu_access_ok(arg2, sizeof(kernel_args_buffer))) {
|
||||
goto invalid_arg;
|
||||
}
|
||||
|
||||
strncpy_from_user((char *)&kernel_args_buffer, (const char *)arg2, sizeof(kernel_args_buffer));
|
||||
}
|
||||
strncpy_from_user((char *)&kernel_args_buffer, (const char *)arg2, sizeof(kernel_args_buffer));
|
||||
}
|
||||
|
||||
sukisu_kpm_load_module_path((const char *)&kernel_load_path,
|
||||
(const char *)&kernel_args_buffer, NULL, &res);
|
||||
} else if (control_code == SUKISU_KPM_UNLOAD) {
|
||||
char kernel_name_buffer[256];
|
||||
sukisu_kpm_load_module_path((const char *)&kernel_load_path,
|
||||
(const char *)&kernel_args_buffer, NULL, &res);
|
||||
} else if (control_code == SUKISU_KPM_UNLOAD) {
|
||||
char kernel_name_buffer[256];
|
||||
|
||||
if (arg1 == 0) {
|
||||
res = -EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
if (arg1 == 0) {
|
||||
res = -EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!ksu_access_ok(arg1, sizeof(kernel_name_buffer))) {
|
||||
goto invalid_arg;
|
||||
}
|
||||
|
||||
strncpy_from_user((char *)&kernel_name_buffer, (const char *)arg1, sizeof(kernel_name_buffer));
|
||||
|
||||
sukisu_kpm_unload_module((const char *)&kernel_name_buffer, NULL, &res);
|
||||
} else if (control_code == SUKISU_KPM_NUM) {
|
||||
sukisu_kpm_num(&res);
|
||||
} else if (control_code == SUKISU_KPM_INFO) {
|
||||
char kernel_name_buffer[256];
|
||||
char buf[256];
|
||||
int size;
|
||||
if (!ksu_access_ok(arg1, sizeof(kernel_name_buffer))) {
|
||||
goto invalid_arg;
|
||||
}
|
||||
|
||||
strncpy_from_user((char *)&kernel_name_buffer, (const char *)arg1, sizeof(kernel_name_buffer));
|
||||
|
||||
sukisu_kpm_unload_module((const char *)&kernel_name_buffer, NULL, &res);
|
||||
} else if (control_code == SUKISU_KPM_NUM) {
|
||||
sukisu_kpm_num(&res);
|
||||
} else if (control_code == SUKISU_KPM_INFO) {
|
||||
char kernel_name_buffer[256];
|
||||
char buf[256];
|
||||
int size;
|
||||
|
||||
if (arg1 == 0 || arg2 == 0) {
|
||||
res = -EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
if (arg1 == 0 || arg2 == 0) {
|
||||
res = -EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!ksu_access_ok(arg1, sizeof(kernel_name_buffer))) {
|
||||
goto invalid_arg;
|
||||
}
|
||||
|
||||
strncpy_from_user((char *)&kernel_name_buffer, (const char __user *)arg1, sizeof(kernel_name_buffer));
|
||||
|
||||
sukisu_kpm_info((const char *)&kernel_name_buffer, (char *)&buf, sizeof(buf), &size);
|
||||
if (!ksu_access_ok(arg1, sizeof(kernel_name_buffer))) {
|
||||
goto invalid_arg;
|
||||
}
|
||||
|
||||
strncpy_from_user((char *)&kernel_name_buffer, (const char __user *)arg1, sizeof(kernel_name_buffer));
|
||||
|
||||
sukisu_kpm_info((const char *)&kernel_name_buffer, (char *)&buf, sizeof(buf), &size);
|
||||
|
||||
if (!ksu_access_ok(arg2, size)) {
|
||||
goto invalid_arg;
|
||||
}
|
||||
if (!ksu_access_ok(arg2, size)) {
|
||||
goto invalid_arg;
|
||||
}
|
||||
|
||||
res = copy_to_user(arg2, &buf, size);
|
||||
res = copy_to_user(arg2, &buf, size);
|
||||
|
||||
} else if (control_code == SUKISU_KPM_LIST) {
|
||||
char buf[1024];
|
||||
int len = (int) arg2;
|
||||
} else if (control_code == SUKISU_KPM_LIST) {
|
||||
char buf[1024];
|
||||
int len = (int) arg2;
|
||||
|
||||
if (len <= 0) {
|
||||
res = -EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
if (len <= 0) {
|
||||
res = -EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!ksu_access_ok(arg2, len)) {
|
||||
goto invalid_arg;
|
||||
}
|
||||
|
||||
sukisu_kpm_list((char *)&buf, sizeof(buf), &res);
|
||||
if (!ksu_access_ok(arg2, len)) {
|
||||
goto invalid_arg;
|
||||
}
|
||||
|
||||
sukisu_kpm_list((char *)&buf, sizeof(buf), &res);
|
||||
|
||||
if (res > len) {
|
||||
res = -ENOBUFS;
|
||||
goto exit;
|
||||
}
|
||||
if (res > len) {
|
||||
res = -ENOBUFS;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (copy_to_user(arg1, &buf, len) != 0)
|
||||
pr_info("kpm: Copy to user failed.");
|
||||
|
||||
} else if (control_code == SUKISU_KPM_CONTROL) {
|
||||
char kpm_name[KPM_NAME_LEN] = { 0 };
|
||||
char kpm_args[KPM_ARGS_LEN] = { 0 };
|
||||
if (copy_to_user(arg1, &buf, len) != 0)
|
||||
pr_info("kpm: Copy to user failed.");
|
||||
|
||||
} else if (control_code == SUKISU_KPM_CONTROL) {
|
||||
char kpm_name[KPM_NAME_LEN] = { 0 };
|
||||
char kpm_args[KPM_ARGS_LEN] = { 0 };
|
||||
|
||||
if (!ksu_access_ok(arg1, sizeof(kpm_name))) {
|
||||
goto invalid_arg;
|
||||
}
|
||||
if (!ksu_access_ok(arg1, sizeof(kpm_name))) {
|
||||
goto invalid_arg;
|
||||
}
|
||||
|
||||
if (!ksu_access_ok(arg2, sizeof(kpm_args))) {
|
||||
goto invalid_arg;
|
||||
}
|
||||
if (!ksu_access_ok(arg2, sizeof(kpm_args))) {
|
||||
goto invalid_arg;
|
||||
}
|
||||
|
||||
long name_len = strncpy_from_user((char *)&kpm_name, (const char __user *)arg1, sizeof(kpm_name));
|
||||
if (name_len <= 0) {
|
||||
res = -EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
long name_len = strncpy_from_user((char *)&kpm_name, (const char __user *)arg1, sizeof(kpm_name));
|
||||
if (name_len <= 0) {
|
||||
res = -EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
long arg_len = strncpy_from_user((char *)&kpm_args, (const char __user *)arg2, sizeof(kpm_args));
|
||||
long arg_len = strncpy_from_user((char *)&kpm_args, (const char __user *)arg2, sizeof(kpm_args));
|
||||
|
||||
sukisu_kpm_control((const char *)&kpm_name, (const char *)&kpm_args, arg_len, &res);
|
||||
sukisu_kpm_control((const char *)&kpm_name, (const char *)&kpm_args, arg_len, &res);
|
||||
|
||||
} else if (control_code == SUKISU_KPM_VERSION) {
|
||||
char buffer[256] = {0};
|
||||
} else if (control_code == SUKISU_KPM_VERSION) {
|
||||
char buffer[256] = {0};
|
||||
|
||||
sukisu_kpm_version((char*) &buffer, sizeof(buffer));
|
||||
sukisu_kpm_version((char*) &buffer, sizeof(buffer));
|
||||
|
||||
unsigned int outlen = (unsigned int) arg2;
|
||||
int len = strlen(buffer);
|
||||
if (len >= outlen) len = outlen - 1;
|
||||
|
||||
res = copy_to_user(arg1, &buffer, len + 1);
|
||||
}
|
||||
unsigned int outlen = (unsigned int) arg2;
|
||||
int len = strlen(buffer);
|
||||
if (len >= outlen) len = outlen - 1;
|
||||
|
||||
res = copy_to_user(arg1, &buffer, len + 1);
|
||||
}
|
||||
|
||||
exit:
|
||||
if (copy_to_user(result_code, &res, sizeof(res)) != 0)
|
||||
pr_info("kpm: Copy to user failed.");
|
||||
|
||||
return 0;
|
||||
if (copy_to_user(result_code, &res, sizeof(res)) != 0)
|
||||
pr_info("kpm: Copy to user failed.");
|
||||
|
||||
return 0;
|
||||
invalid_arg:
|
||||
pr_err("kpm: invalid pointer detected! arg1: %px arg2: %px\n", (void *)arg1, (void *)arg2);
|
||||
res = -EFAULT;
|
||||
goto exit;
|
||||
pr_err("kpm: invalid pointer detected! arg1: %px arg2: %px\n", (void *)arg1, (void *)arg2);
|
||||
res = -EFAULT;
|
||||
goto exit;
|
||||
}
|
||||
EXPORT_SYMBOL(sukisu_handle_kpm);
|
||||
|
||||
int sukisu_is_kpm_control_code(unsigned long control_code) {
|
||||
return (control_code >= CMD_KPM_CONTROL &&
|
||||
control_code <= CMD_KPM_CONTROL_MAX) ? 1 : 0;
|
||||
return (control_code >= CMD_KPM_CONTROL &&
|
||||
control_code <= CMD_KPM_CONTROL_MAX) ? 1 : 0;
|
||||
}
|
||||
|
||||
int do_kpm(void __user *arg)
|
||||
{
|
||||
struct ksu_kpm_cmd cmd;
|
||||
struct ksu_kpm_cmd cmd;
|
||||
|
||||
if (copy_from_user(&cmd, arg, sizeof(cmd))) {
|
||||
pr_err("kpm: copy_from_user failed\n");
|
||||
return -EFAULT;
|
||||
}
|
||||
if (copy_from_user(&cmd, arg, sizeof(cmd))) {
|
||||
pr_err("kpm: copy_from_user failed\n");
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
if (!ksu_access_ok(cmd.control_code, sizeof(int))) {
|
||||
pr_err("kpm: invalid control_code pointer %px\n", (void *)cmd.control_code);
|
||||
return -EFAULT;
|
||||
}
|
||||
if (!ksu_access_ok(cmd.control_code, sizeof(int))) {
|
||||
pr_err("kpm: invalid control_code pointer %px\n", (void *)cmd.control_code);
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
if (!ksu_access_ok(cmd.result_code, sizeof(int))) {
|
||||
pr_err("kpm: invalid result_code pointer %px\n", (void *)cmd.result_code);
|
||||
return -EFAULT;
|
||||
}
|
||||
if (!ksu_access_ok(cmd.result_code, sizeof(int))) {
|
||||
pr_err("kpm: invalid result_code pointer %px\n", (void *)cmd.result_code);
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
return sukisu_handle_kpm(cmd.control_code, cmd.arg1, cmd.arg2, cmd.result_code);
|
||||
return sukisu_handle_kpm(cmd.control_code, cmd.arg1, cmd.arg2, cmd.result_code);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
#include <linux/ioctl.h>
|
||||
|
||||
struct ksu_kpm_cmd {
|
||||
__aligned_u64 __user control_code;
|
||||
__aligned_u64 __user arg1;
|
||||
__aligned_u64 __user arg2;
|
||||
__aligned_u64 __user result_code;
|
||||
__aligned_u64 __user control_code;
|
||||
__aligned_u64 __user arg1;
|
||||
__aligned_u64 __user arg2;
|
||||
__aligned_u64 __user result_code;
|
||||
};
|
||||
|
||||
int sukisu_handle_kpm(unsigned long control_code, unsigned long arg1, unsigned long arg2, unsigned long result_code);
|
||||
|
||||
@@ -36,154 +36,154 @@
|
||||
#include "compact.h"
|
||||
|
||||
struct DynamicStructMember {
|
||||
const char *name;
|
||||
size_t size;
|
||||
size_t offset;
|
||||
const char *name;
|
||||
size_t size;
|
||||
size_t offset;
|
||||
};
|
||||
|
||||
struct DynamicStructInfo {
|
||||
const char *name;
|
||||
size_t count;
|
||||
size_t total_size;
|
||||
struct DynamicStructMember *members;
|
||||
const char *name;
|
||||
size_t count;
|
||||
size_t total_size;
|
||||
struct DynamicStructMember *members;
|
||||
};
|
||||
|
||||
#define DYNAMIC_STRUCT_BEGIN(struct_name) \
|
||||
static struct DynamicStructMember struct_name##_members[] = {
|
||||
static struct DynamicStructMember struct_name##_members[] = {
|
||||
|
||||
#define DEFINE_MEMBER(struct_name, member) \
|
||||
{ \
|
||||
.name = #member, \
|
||||
.size = sizeof(((struct struct_name *)0)->member), \
|
||||
.offset = offsetof(struct struct_name, member) \
|
||||
},
|
||||
{ \
|
||||
.name = #member, \
|
||||
.size = sizeof(((struct struct_name *)0)->member), \
|
||||
.offset = offsetof(struct struct_name, member) \
|
||||
},
|
||||
|
||||
#define DYNAMIC_STRUCT_END(struct_name) \
|
||||
}; \
|
||||
static struct DynamicStructInfo struct_name##_info = { \
|
||||
.name = #struct_name, \
|
||||
.count = sizeof(struct_name##_members) / sizeof(struct DynamicStructMember), \
|
||||
.total_size = sizeof(struct struct_name), \
|
||||
.members = struct_name##_members \
|
||||
};
|
||||
}; \
|
||||
static struct DynamicStructInfo struct_name##_info = { \
|
||||
.name = #struct_name, \
|
||||
.count = sizeof(struct_name##_members) / sizeof(struct DynamicStructMember), \
|
||||
.total_size = sizeof(struct struct_name), \
|
||||
.members = struct_name##_members \
|
||||
};
|
||||
|
||||
DYNAMIC_STRUCT_BEGIN(mount)
|
||||
DEFINE_MEMBER(mount, mnt_parent)
|
||||
DEFINE_MEMBER(mount, mnt)
|
||||
DEFINE_MEMBER(mount, mnt_id)
|
||||
DEFINE_MEMBER(mount, mnt_group_id)
|
||||
DEFINE_MEMBER(mount, mnt_expiry_mark)
|
||||
DEFINE_MEMBER(mount, mnt_master)
|
||||
DEFINE_MEMBER(mount, mnt_devname)
|
||||
DEFINE_MEMBER(mount, mnt_parent)
|
||||
DEFINE_MEMBER(mount, mnt)
|
||||
DEFINE_MEMBER(mount, mnt_id)
|
||||
DEFINE_MEMBER(mount, mnt_group_id)
|
||||
DEFINE_MEMBER(mount, mnt_expiry_mark)
|
||||
DEFINE_MEMBER(mount, mnt_master)
|
||||
DEFINE_MEMBER(mount, mnt_devname)
|
||||
DYNAMIC_STRUCT_END(mount)
|
||||
|
||||
DYNAMIC_STRUCT_BEGIN(vfsmount)
|
||||
DEFINE_MEMBER(vfsmount, mnt_root)
|
||||
DEFINE_MEMBER(vfsmount, mnt_sb)
|
||||
DEFINE_MEMBER(vfsmount, mnt_flags)
|
||||
DEFINE_MEMBER(vfsmount, mnt_root)
|
||||
DEFINE_MEMBER(vfsmount, mnt_sb)
|
||||
DEFINE_MEMBER(vfsmount, mnt_flags)
|
||||
DYNAMIC_STRUCT_END(vfsmount)
|
||||
|
||||
DYNAMIC_STRUCT_BEGIN(mnt_namespace)
|
||||
DEFINE_MEMBER(mnt_namespace, ns)
|
||||
DEFINE_MEMBER(mnt_namespace, root)
|
||||
DEFINE_MEMBER(mnt_namespace, seq)
|
||||
DEFINE_MEMBER(mnt_namespace, mounts)
|
||||
DEFINE_MEMBER(mnt_namespace, ns)
|
||||
DEFINE_MEMBER(mnt_namespace, root)
|
||||
DEFINE_MEMBER(mnt_namespace, seq)
|
||||
DEFINE_MEMBER(mnt_namespace, mounts)
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 15, 0)
|
||||
DEFINE_MEMBER(mnt_namespace, count)
|
||||
DEFINE_MEMBER(mnt_namespace, count)
|
||||
#endif
|
||||
DYNAMIC_STRUCT_END(mnt_namespace)
|
||||
|
||||
#ifdef CONFIG_KPROBES
|
||||
DYNAMIC_STRUCT_BEGIN(kprobe)
|
||||
DEFINE_MEMBER(kprobe, addr)
|
||||
DEFINE_MEMBER(kprobe, symbol_name)
|
||||
DEFINE_MEMBER(kprobe, offset)
|
||||
DEFINE_MEMBER(kprobe, pre_handler)
|
||||
DEFINE_MEMBER(kprobe, post_handler)
|
||||
DEFINE_MEMBER(kprobe, addr)
|
||||
DEFINE_MEMBER(kprobe, symbol_name)
|
||||
DEFINE_MEMBER(kprobe, offset)
|
||||
DEFINE_MEMBER(kprobe, pre_handler)
|
||||
DEFINE_MEMBER(kprobe, post_handler)
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 15, 0)
|
||||
DEFINE_MEMBER(kprobe, fault_handler)
|
||||
DEFINE_MEMBER(kprobe, fault_handler)
|
||||
#endif
|
||||
DEFINE_MEMBER(kprobe, flags)
|
||||
DEFINE_MEMBER(kprobe, flags)
|
||||
DYNAMIC_STRUCT_END(kprobe)
|
||||
#endif
|
||||
|
||||
DYNAMIC_STRUCT_BEGIN(vm_area_struct)
|
||||
DEFINE_MEMBER(vm_area_struct,vm_start)
|
||||
DEFINE_MEMBER(vm_area_struct,vm_end)
|
||||
DEFINE_MEMBER(vm_area_struct,vm_flags)
|
||||
DEFINE_MEMBER(vm_area_struct,anon_vma)
|
||||
DEFINE_MEMBER(vm_area_struct,vm_pgoff)
|
||||
DEFINE_MEMBER(vm_area_struct,vm_file)
|
||||
DEFINE_MEMBER(vm_area_struct,vm_private_data)
|
||||
DEFINE_MEMBER(vm_area_struct,vm_start)
|
||||
DEFINE_MEMBER(vm_area_struct,vm_end)
|
||||
DEFINE_MEMBER(vm_area_struct,vm_flags)
|
||||
DEFINE_MEMBER(vm_area_struct,anon_vma)
|
||||
DEFINE_MEMBER(vm_area_struct,vm_pgoff)
|
||||
DEFINE_MEMBER(vm_area_struct,vm_file)
|
||||
DEFINE_MEMBER(vm_area_struct,vm_private_data)
|
||||
#ifdef CONFIG_ANON_VMA_NAME
|
||||
DEFINE_MEMBER(vm_area_struct, anon_name)
|
||||
DEFINE_MEMBER(vm_area_struct, anon_name)
|
||||
#endif
|
||||
DEFINE_MEMBER(vm_area_struct, vm_ops)
|
||||
DEFINE_MEMBER(vm_area_struct, vm_ops)
|
||||
DYNAMIC_STRUCT_END(vm_area_struct)
|
||||
|
||||
DYNAMIC_STRUCT_BEGIN(vm_operations_struct)
|
||||
DEFINE_MEMBER(vm_operations_struct, open)
|
||||
DEFINE_MEMBER(vm_operations_struct, close)
|
||||
DEFINE_MEMBER(vm_operations_struct, name)
|
||||
DEFINE_MEMBER(vm_operations_struct, access)
|
||||
DEFINE_MEMBER(vm_operations_struct, open)
|
||||
DEFINE_MEMBER(vm_operations_struct, close)
|
||||
DEFINE_MEMBER(vm_operations_struct, name)
|
||||
DEFINE_MEMBER(vm_operations_struct, access)
|
||||
DYNAMIC_STRUCT_END(vm_operations_struct)
|
||||
|
||||
DYNAMIC_STRUCT_BEGIN(netlink_kernel_cfg)
|
||||
DEFINE_MEMBER(netlink_kernel_cfg, groups)
|
||||
DEFINE_MEMBER(netlink_kernel_cfg, flags)
|
||||
DEFINE_MEMBER(netlink_kernel_cfg, input)
|
||||
DEFINE_MEMBER(netlink_kernel_cfg, groups)
|
||||
DEFINE_MEMBER(netlink_kernel_cfg, flags)
|
||||
DEFINE_MEMBER(netlink_kernel_cfg, input)
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 11, 0)
|
||||
DEFINE_MEMBER(netlink_kernel_cfg, cb_mutex)
|
||||
DEFINE_MEMBER(netlink_kernel_cfg, cb_mutex)
|
||||
#endif
|
||||
DEFINE_MEMBER(netlink_kernel_cfg, bind)
|
||||
DEFINE_MEMBER(netlink_kernel_cfg, unbind)
|
||||
DEFINE_MEMBER(netlink_kernel_cfg, bind)
|
||||
DEFINE_MEMBER(netlink_kernel_cfg, unbind)
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0)
|
||||
DEFINE_MEMBER(netlink_kernel_cfg, compare)
|
||||
DEFINE_MEMBER(netlink_kernel_cfg, compare)
|
||||
#endif
|
||||
DYNAMIC_STRUCT_END(netlink_kernel_cfg)
|
||||
|
||||
DYNAMIC_STRUCT_BEGIN(task_struct)
|
||||
DEFINE_MEMBER(task_struct, pid)
|
||||
DEFINE_MEMBER(task_struct, tgid)
|
||||
DEFINE_MEMBER(task_struct, cred)
|
||||
DEFINE_MEMBER(task_struct, real_cred)
|
||||
DEFINE_MEMBER(task_struct, comm)
|
||||
DEFINE_MEMBER(task_struct, parent)
|
||||
DEFINE_MEMBER(task_struct, group_leader)
|
||||
DEFINE_MEMBER(task_struct, mm)
|
||||
DEFINE_MEMBER(task_struct, active_mm)
|
||||
DEFINE_MEMBER(task_struct, pid)
|
||||
DEFINE_MEMBER(task_struct, tgid)
|
||||
DEFINE_MEMBER(task_struct, cred)
|
||||
DEFINE_MEMBER(task_struct, real_cred)
|
||||
DEFINE_MEMBER(task_struct, comm)
|
||||
DEFINE_MEMBER(task_struct, parent)
|
||||
DEFINE_MEMBER(task_struct, group_leader)
|
||||
DEFINE_MEMBER(task_struct, mm)
|
||||
DEFINE_MEMBER(task_struct, active_mm)
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 0)
|
||||
DEFINE_MEMBER(task_struct, pids[PIDTYPE_PID].pid)
|
||||
DEFINE_MEMBER(task_struct, pids[PIDTYPE_PID].pid)
|
||||
#else
|
||||
DEFINE_MEMBER(task_struct, thread_pid)
|
||||
DEFINE_MEMBER(task_struct, thread_pid)
|
||||
#endif
|
||||
DEFINE_MEMBER(task_struct, files)
|
||||
DEFINE_MEMBER(task_struct, seccomp)
|
||||
DEFINE_MEMBER(task_struct, files)
|
||||
DEFINE_MEMBER(task_struct, seccomp)
|
||||
#ifdef CONFIG_THREAD_INFO_IN_TASK
|
||||
DEFINE_MEMBER(task_struct, thread_info)
|
||||
DEFINE_MEMBER(task_struct, thread_info)
|
||||
#endif
|
||||
#ifdef CONFIG_CGROUPS
|
||||
DEFINE_MEMBER(task_struct, cgroups)
|
||||
DEFINE_MEMBER(task_struct, cgroups)
|
||||
#endif
|
||||
#ifdef CONFIG_SECURITY
|
||||
DEFINE_MEMBER(task_struct, security)
|
||||
DEFINE_MEMBER(task_struct, security)
|
||||
#endif
|
||||
DEFINE_MEMBER(task_struct, thread)
|
||||
DEFINE_MEMBER(task_struct, thread)
|
||||
DYNAMIC_STRUCT_END(task_struct)
|
||||
|
||||
#define STRUCT_INFO(name) &(name##_info)
|
||||
|
||||
static struct DynamicStructInfo *dynamic_struct_infos[] = {
|
||||
STRUCT_INFO(mount),
|
||||
STRUCT_INFO(vfsmount),
|
||||
STRUCT_INFO(mnt_namespace),
|
||||
STRUCT_INFO(mount),
|
||||
STRUCT_INFO(vfsmount),
|
||||
STRUCT_INFO(mnt_namespace),
|
||||
#ifdef CONFIG_KPROBES
|
||||
STRUCT_INFO(kprobe),
|
||||
STRUCT_INFO(kprobe),
|
||||
#endif
|
||||
STRUCT_INFO(vm_area_struct),
|
||||
STRUCT_INFO(vm_operations_struct),
|
||||
STRUCT_INFO(netlink_kernel_cfg),
|
||||
STRUCT_INFO(task_struct)
|
||||
STRUCT_INFO(vm_area_struct),
|
||||
STRUCT_INFO(vm_operations_struct),
|
||||
STRUCT_INFO(netlink_kernel_cfg),
|
||||
STRUCT_INFO(task_struct)
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -192,21 +192,21 @@ static struct DynamicStructInfo *dynamic_struct_infos[] = {
|
||||
*/
|
||||
int sukisu_super_find_struct(const char *struct_name, size_t *out_size, int *out_members)
|
||||
{
|
||||
for (size_t i = 0; i < (sizeof(dynamic_struct_infos) / sizeof(dynamic_struct_infos[0])); i++) {
|
||||
struct DynamicStructInfo *info = dynamic_struct_infos[i];
|
||||
|
||||
if (strcmp(struct_name, info->name) == 0) {
|
||||
if (out_size)
|
||||
*out_size = info->total_size;
|
||||
|
||||
if (out_members)
|
||||
*out_members = info->count;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
for (size_t i = 0; i < (sizeof(dynamic_struct_infos) / sizeof(dynamic_struct_infos[0])); i++) {
|
||||
struct DynamicStructInfo *info = dynamic_struct_infos[i];
|
||||
|
||||
if (strcmp(struct_name, info->name) == 0) {
|
||||
if (out_size)
|
||||
*out_size = info->total_size;
|
||||
|
||||
if (out_members)
|
||||
*out_members = info->count;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
EXPORT_SYMBOL(sukisu_super_find_struct);
|
||||
|
||||
@@ -217,34 +217,34 @@ EXPORT_SYMBOL(sukisu_super_find_struct);
|
||||
* return -2 if member not defined
|
||||
*/
|
||||
int sukisu_super_access(const char *struct_name, const char *member_name, size_t *out_offset,
|
||||
size_t *out_size)
|
||||
size_t *out_size)
|
||||
{
|
||||
for (size_t i = 0; i < (sizeof(dynamic_struct_infos) / sizeof(dynamic_struct_infos[0])); i++) {
|
||||
struct DynamicStructInfo *info = dynamic_struct_infos[i];
|
||||
|
||||
if (strcmp(struct_name, info->name) == 0) {
|
||||
for (size_t i1 = 0; i1 < info->count; i1++) {
|
||||
if (strcmp(info->members[i1].name, member_name) == 0) {
|
||||
if (out_offset)
|
||||
*out_offset = info->members[i].offset;
|
||||
|
||||
if (out_size)
|
||||
*out_size = info->members[i].size;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
for (size_t i = 0; i < (sizeof(dynamic_struct_infos) / sizeof(dynamic_struct_infos[0])); i++) {
|
||||
struct DynamicStructInfo *info = dynamic_struct_infos[i];
|
||||
|
||||
if (strcmp(struct_name, info->name) == 0) {
|
||||
for (size_t i1 = 0; i1 < info->count; i1++) {
|
||||
if (strcmp(info->members[i1].name, member_name) == 0) {
|
||||
if (out_offset)
|
||||
*out_offset = info->members[i].offset;
|
||||
|
||||
if (out_size)
|
||||
*out_size = info->members[i].size;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
EXPORT_SYMBOL(sukisu_super_access);
|
||||
|
||||
#define DYNAMIC_CONTAINER_OF(offset, member_ptr) ({ \
|
||||
(offset != (size_t)-1) ? (void*)((char*)(member_ptr) - offset) : NULL; \
|
||||
(offset != (size_t)-1) ? (void*)((char*)(member_ptr) - offset) : NULL; \
|
||||
})
|
||||
|
||||
/*
|
||||
@@ -254,27 +254,27 @@ EXPORT_SYMBOL(sukisu_super_access);
|
||||
* return -2 if target member not defined
|
||||
*/
|
||||
int sukisu_super_container_of(const char *struct_name, const char *member_name, void *ptr,
|
||||
void **out_ptr)
|
||||
void **out_ptr)
|
||||
{
|
||||
if (ptr == NULL)
|
||||
return -3;
|
||||
if (ptr == NULL)
|
||||
return -3;
|
||||
|
||||
for (size_t i = 0; i < (sizeof(dynamic_struct_infos) / sizeof(dynamic_struct_infos[0])); i++) {
|
||||
struct DynamicStructInfo *info = dynamic_struct_infos[i];
|
||||
|
||||
if (strcmp(struct_name, info->name) == 0) {
|
||||
for (size_t i1 = 0; i1 < info->count; i1++) {
|
||||
if (strcmp(info->members[i1].name, member_name) == 0) {
|
||||
*out_ptr = (void *)DYNAMIC_CONTAINER_OF(info->members[i1].offset, ptr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
for (size_t i = 0; i < (sizeof(dynamic_struct_infos) / sizeof(dynamic_struct_infos[0])); i++) {
|
||||
struct DynamicStructInfo *info = dynamic_struct_infos[i];
|
||||
|
||||
if (strcmp(struct_name, info->name) == 0) {
|
||||
for (size_t i1 = 0; i1 < info->count; i1++) {
|
||||
if (strcmp(info->members[i1].name, member_name) == 0) {
|
||||
*out_ptr = (void *)DYNAMIC_CONTAINER_OF(info->members[i1].offset, ptr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
EXPORT_SYMBOL(sukisu_super_container_of);
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
extern int sukisu_super_find_struct(const char *struct_name, size_t *out_size, int *out_members);
|
||||
extern int sukisu_super_access(const char *struct_name, const char *member_name, size_t *out_offset,
|
||||
size_t *out_size);
|
||||
size_t *out_size);
|
||||
extern int sukisu_super_container_of(const char *struct_name, const char *member_name, void *ptr,
|
||||
void **out_ptr);
|
||||
void **out_ptr);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user