add mutex for sucompat mark

This commit is contained in:
Ylarod
2025-11-06 21:29:56 +08:00
committed by ShirkNeko
parent cf50be122e
commit e54989e51a

View File

@@ -1,4 +1,5 @@
#include "linux/compiler.h" #include "linux/compiler.h"
#include "linux/printk.h"
#include "linux/sched.h" #include "linux/sched.h"
#include "selinux/selinux.h" #include "selinux/selinux.h"
#include <linux/dcache.h> #include <linux/dcache.h>
@@ -439,9 +440,11 @@ static struct kprobe *pts_kp = NULL;
#ifdef CONFIG_KRETPROBES #ifdef CONFIG_KRETPROBES
static int tracepoint_reg_count = 0; static int tracepoint_reg_count = 0;
static DEFINE_MUTEX(tracepoint_reg_mutex);
static int syscall_regfunc_handler(struct kretprobe_instance *ri, struct pt_regs *regs) static int syscall_regfunc_handler(struct kretprobe_instance *ri, struct pt_regs *regs)
{ {
mutex_lock(&tracepoint_reg_mutex);
if (tracepoint_reg_count < 1) { if (tracepoint_reg_count < 1) {
// while install our tracepoint, mark our processes // while install our tracepoint, mark our processes
unmark_all_process(); unmark_all_process();
@@ -451,11 +454,13 @@ static int syscall_regfunc_handler(struct kretprobe_instance *ri, struct pt_regs
mark_all_process(); mark_all_process();
} }
tracepoint_reg_count++; tracepoint_reg_count++;
mutex_unlock(&tracepoint_reg_mutex);
return 0; return 0;
} }
static int syscall_unregfunc_handler(struct kretprobe_instance *ri, struct pt_regs *regs) static int syscall_unregfunc_handler(struct kretprobe_instance *ri, struct pt_regs *regs)
{ {
mutex_lock(&tracepoint_reg_mutex);
if (tracepoint_reg_count <= 1) { if (tracepoint_reg_count <= 1) {
// while uninstall our tracepoint, unmark all processes // while uninstall our tracepoint, unmark all processes
unmark_all_process(); unmark_all_process();
@@ -465,6 +470,7 @@ static int syscall_unregfunc_handler(struct kretprobe_instance *ri, struct pt_re
ksu_mark_running_process(); ksu_mark_running_process();
} }
tracepoint_reg_count--; tracepoint_reg_count--;
mutex_unlock(&tracepoint_reg_mutex);
return 0; return 0;
} }