kernel: Simplify state management logic
This commit is contained in:
@@ -129,9 +129,8 @@ ifeq ($(CONFIG_KSU_MANUAL_HOOK), y)
|
|||||||
ccflags-y += -DKSU_MANUAL_HOOK
|
ccflags-y += -DKSU_MANUAL_HOOK
|
||||||
$(info -- SukiSU: KSU_MANUAL_HOOK)
|
$(info -- SukiSU: KSU_MANUAL_HOOK)
|
||||||
else
|
else
|
||||||
ccflags-y += -DKSU_HAVE_SYSCALL_TRACEPOINTS_HOOK
|
|
||||||
ccflags-y += -DKSU_LKM_MODE
|
|
||||||
ccflags-y += -DKSU_KPROBES_HOOK
|
ccflags-y += -DKSU_KPROBES_HOOK
|
||||||
|
ccflags-y += -DKSU_TP_HOOK
|
||||||
$(info -- SukiSU: KSU_TRACEPOINT_HOOK)
|
$(info -- SukiSU: KSU_TRACEPOINT_HOOK)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ int ksu_handle_faccessat(int *dfd, const char __user **filename_user, int *mode,
|
|||||||
{
|
{
|
||||||
const char su[] = SU_PATH;
|
const char su[] = SU_PATH;
|
||||||
|
|
||||||
#ifndef KSU_HAVE_SYSCALL_TRACEPOINTS_HOOK
|
#ifdef KSU_MANUAL_HOOK
|
||||||
if (!ksu_su_compat_enabled) {
|
if (!ksu_su_compat_enabled) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -104,10 +104,10 @@ int ksu_handle_stat(int *dfd, const char __user **filename_user, int *flags)
|
|||||||
// const char sh[] = SH_PATH;
|
// const char sh[] = SH_PATH;
|
||||||
const char su[] = SU_PATH;
|
const char su[] = SU_PATH;
|
||||||
|
|
||||||
#ifndef KSU_HAVE_SYSCALL_TRACEPOINTS_HOOK
|
#ifdef KSU_MANUAL_HOOK
|
||||||
if (!ksu_su_compat_enabled) {
|
if (!ksu_su_compat_enabled) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (!ksu_is_allow_uid_for_current(current_uid().val)) {
|
if (!ksu_is_allow_uid_for_current(current_uid().val)) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -156,10 +156,10 @@ int ksu_handle_execveat_sucompat(int *fd, struct filename **filename_ptr,
|
|||||||
const char sh[] = KSUD_PATH;
|
const char sh[] = KSUD_PATH;
|
||||||
const char su[] = SU_PATH;
|
const char su[] = SU_PATH;
|
||||||
|
|
||||||
#ifndef KSU_HAVE_SYSCALL_TRACEPOINTS_HOOK
|
#ifdef KSU_MANUAL_HOOK
|
||||||
if (!ksu_su_compat_enabled) {
|
if (!ksu_su_compat_enabled) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (unlikely(!filename_ptr))
|
if (unlikely(!filename_ptr))
|
||||||
return 0;
|
return 0;
|
||||||
@@ -208,10 +208,10 @@ int ksu_handle_execve_sucompat(int *fd, const char __user **filename_user,
|
|||||||
const char su[] = SU_PATH;
|
const char su[] = SU_PATH;
|
||||||
char path[sizeof(su) + 1];
|
char path[sizeof(su) + 1];
|
||||||
|
|
||||||
#ifndef KSU_HAVE_SYSCALL_TRACEPOINTS_HOOK
|
#ifdef KSU_MANUAL_HOOK
|
||||||
if (!ksu_su_compat_enabled){
|
if (!ksu_su_compat_enabled){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (unlikely(!filename_user))
|
if (unlikely(!filename_user))
|
||||||
return 0;
|
return 0;
|
||||||
@@ -247,7 +247,7 @@ int ksu_handle_execve_sucompat(int *fd, const char __user **filename_user,
|
|||||||
int __ksu_handle_devpts(struct inode *inode)
|
int __ksu_handle_devpts(struct inode *inode)
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifndef KSU_HAVE_SYSCALL_TRACEPOINTS_HOOK
|
#ifdef KSU_MANUAL_HOOK
|
||||||
if (!ksu_su_compat_enabled)
|
if (!ksu_su_compat_enabled)
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/uaccess.h>
|
#include <linux/uaccess.h>
|
||||||
#include <linux/version.h>
|
#include <linux/version.h>
|
||||||
|
#include <linux/kprobes.h>
|
||||||
|
|
||||||
#include "arch.h"
|
#include "arch.h"
|
||||||
#include "allowlist.h"
|
#include "allowlist.h"
|
||||||
@@ -498,13 +499,12 @@ static int do_get_full_version(void __user *arg)
|
|||||||
static int do_get_hook_type(void __user *arg)
|
static int do_get_hook_type(void __user *arg)
|
||||||
{
|
{
|
||||||
struct ksu_hook_type_cmd cmd = {0};
|
struct ksu_hook_type_cmd cmd = {0};
|
||||||
const char *type = "Unknown";
|
const char *type = "Tracepoint";
|
||||||
|
|
||||||
#if defined(KSU_HAVE_SYSCALL_TRACEPOINTS_HOOK)
|
#if defined(KSU_MANUAL_HOOK)
|
||||||
type = "Tracepoint";
|
|
||||||
#elif defined(KSU_MANUAL_HOOK)
|
|
||||||
type = "Manual";
|
type = "Manual";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 13, 0)
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 13, 0)
|
||||||
strscpy(cmd.hook_type, type, sizeof(cmd.hook_type));
|
strscpy(cmd.hook_type, type, sizeof(cmd.hook_type));
|
||||||
#else
|
#else
|
||||||
@@ -768,6 +768,7 @@ int ksu_handle_sys_reboot(int magic1, int magic2, unsigned int cmd, void __user
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef KSU_KPROBES_HOOK
|
||||||
// Reboot hook for installing fd
|
// Reboot hook for installing fd
|
||||||
static int reboot_handler_pre(struct kprobe *p, struct pt_regs *regs)
|
static int reboot_handler_pre(struct kprobe *p, struct pt_regs *regs)
|
||||||
{
|
{
|
||||||
@@ -784,6 +785,7 @@ static struct kprobe reboot_kp = {
|
|||||||
.symbol_name = REBOOT_SYMBOL,
|
.symbol_name = REBOOT_SYMBOL,
|
||||||
.pre_handler = reboot_handler_pre,
|
.pre_handler = reboot_handler_pre,
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
void ksu_supercalls_init(void)
|
void ksu_supercalls_init(void)
|
||||||
{
|
{
|
||||||
@@ -793,17 +795,20 @@ void ksu_supercalls_init(void)
|
|||||||
for (i = 0; ksu_ioctl_handlers[i].handler; i++) {
|
for (i = 0; ksu_ioctl_handlers[i].handler; i++) {
|
||||||
pr_info(" %-18s = 0x%08x\n", ksu_ioctl_handlers[i].name, ksu_ioctl_handlers[i].cmd);
|
pr_info(" %-18s = 0x%08x\n", ksu_ioctl_handlers[i].name, ksu_ioctl_handlers[i].cmd);
|
||||||
}
|
}
|
||||||
|
#ifdef KSU_KPROBES_HOOK
|
||||||
int rc = register_kprobe(&reboot_kp);
|
int rc = register_kprobe(&reboot_kp);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
pr_err("reboot kprobe failed: %d\n", rc);
|
pr_err("reboot kprobe failed: %d\n", rc);
|
||||||
} else {
|
} else {
|
||||||
pr_info("reboot kprobe registered successfully\n");
|
pr_info("reboot kprobe registered successfully\n");
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ksu_supercalls_exit(void){
|
void ksu_supercalls_exit(void) {
|
||||||
|
#ifdef KSU_KPROBES_HOOK
|
||||||
unregister_kprobe(&reboot_kp);
|
unregister_kprobe(&reboot_kp);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void ksu_ioctl_audit(unsigned int cmd, const char *cmd_name, uid_t uid, int ret)
|
static inline void ksu_ioctl_audit(unsigned int cmd, const char *cmd_name, uid_t uid, int ret)
|
||||||
|
|||||||
@@ -320,7 +320,7 @@ static inline void ksu_handle_task_alloc(struct pt_regs *regs)
|
|||||||
static void ksu_sys_enter_handler(void *data, struct pt_regs *regs, long id)
|
static void ksu_sys_enter_handler(void *data, struct pt_regs *regs, long id)
|
||||||
{
|
{
|
||||||
if (unlikely(check_syscall_fastpath(id))) {
|
if (unlikely(check_syscall_fastpath(id))) {
|
||||||
#ifdef KSU_LKM_MODE
|
#ifdef KSU_TP_HOOK
|
||||||
if (ksu_su_compat_enabled) {
|
if (ksu_su_compat_enabled) {
|
||||||
// Handle newfstatat
|
// Handle newfstatat
|
||||||
if (id == __NR_newfstatat) {
|
if (id == __NR_newfstatat) {
|
||||||
|
|||||||
Reference in New Issue
Block a user