Skip to content

Commit

Permalink
kernel: clean memory when exit
Browse files Browse the repository at this point in the history
  • Loading branch information
tiann committed Mar 24, 2024
1 parent 5167dc7 commit 858ec91
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 13 deletions.
6 changes: 5 additions & 1 deletion kernel/core_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -838,5 +838,9 @@ void __init ksu_core_init(void)

void ksu_core_exit(void)
{
pr_info("ksu_kprobe_exit\n");
#ifdef CONFIG_KPROBES
pr_info("ksu_core_kprobe_exit\n");
// we dont use this now
// ksu_kprobe_exit();
#endif
}
15 changes: 11 additions & 4 deletions kernel/ksu.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ int ksu_handle_execveat(int *fd, struct filename **filename_ptr, void *argv,
flags);
}

extern void ksu_enable_sucompat();
extern void ksu_enable_ksud();
extern void ksu_sucompat_init();
extern void ksu_sucompat_exit();
extern void ksu_ksud_init();
extern void ksu_ksud_exit();

int __init kernelsu_init(void)
{
Expand All @@ -56,8 +58,8 @@ int __init kernelsu_init(void)
ksu_throne_tracker_init();

#ifdef CONFIG_KPROBES
ksu_enable_sucompat();
ksu_enable_ksud();
ksu_sucompat_init();
ksu_ksud_init();
#else
pr_alert("KPROBES is disabled, KernelSU may not work, please check https://kernelsu.org/guide/how-to-integrate-for-non-gki.html");
#endif
Expand All @@ -78,6 +80,11 @@ void kernelsu_exit(void)

destroy_workqueue(ksu_workqueue);

#ifdef CONFIG_KPROBES
ksu_ksud_exit();
ksu_sucompat_exit();
#endif

ksu_core_exit();
}

Expand Down
11 changes: 10 additions & 1 deletion kernel/ksud.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ static void stop_input_hook()
}

// ksud: module support
void ksu_enable_ksud()
void ksu_ksud_init()
{
#ifdef CONFIG_KPROBES
int ret;
Expand All @@ -608,3 +608,12 @@ void ksu_enable_ksud()
INIT_WORK(&stop_input_hook_work, do_stop_input_hook);
#endif
}

void ksu_ksud_exit() {
#ifdef CONFIG_KPROBES
unregister_kprobe(&execve_kp);
// this should be done before unregister vfs_read_kp
// unregister_kprobe(&vfs_read_kp);
unregister_kprobe(&input_handle_event_kp);
#endif
}
10 changes: 9 additions & 1 deletion kernel/sucompat.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ static struct kprobe execve_kp = {
#endif

// sucompat: permited process can execute 'su' to gain root access.
void ksu_enable_sucompat()
void ksu_sucompat_init()
{
#ifdef CONFIG_KPROBES
int ret;
Expand All @@ -254,3 +254,11 @@ void ksu_enable_sucompat()
pr_info("sucompat: faccessat_kp: %d\n", ret);
#endif
}

void ksu_sucompat_exit() {
#ifdef CONFIG_KPROBES
unregister_kprobe(&execve_kp);
unregister_kprobe(&newfstatat_kp);
unregister_kprobe(&faccessat_kp);
#endif
}
7 changes: 3 additions & 4 deletions kernel/throne_tracker.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,12 @@ void track_throne()
ksu_queue_work(&ksu_update_uid_work);
}

int ksu_throne_tracker_init()
void ksu_throne_tracker_init()
{
INIT_WORK(&ksu_update_uid_work, do_update_uid);
return 0;
}

int ksu_throne_tracker_exit()
void ksu_throne_tracker_exit()
{
return 0;
// nothing to do
}
4 changes: 2 additions & 2 deletions kernel/throne_tracker.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef __KSU_H_UID_OBSERVER
#define __KSU_H_UID_OBSERVER

int ksu_throne_tracker_init();
void ksu_throne_tracker_init();

int ksu_throne_tracker_exit();
void ksu_throne_tracker_exit();

void track_throne();

Expand Down

0 comments on commit 858ec91

Please sign in to comment.