kernel: Set the tracepoint flag in a tracepoint manner

This commit is contained in:
weishu
2025-11-06 03:57:37 +00:00
committed by ShirkNeko
parent 752ec03694
commit a30b932969
4 changed files with 35 additions and 7 deletions

View File

@@ -1,5 +1,5 @@
#include "linux/compiler.h"
#include "linux/sched/signal.h"
#include <linux/compiler.h>
#include <linux/sched/signal.h>
#include <linux/slab.h>
#include <linux/task_work.h>
#include <linux/thread_info.h>
@@ -61,6 +61,7 @@
#include "selinux/selinux.h"
#include "kernel_compat.h"
#include "supercalls.h"
#include "sucompat.h"
#include "sulog.h"
@@ -1243,7 +1244,7 @@ int ksu_handle_setuid(struct cred *new, const struct cred *old)
if (new_uid.val == 2000) {
if (ksu_su_compat_enabled) {
set_tsk_thread_flag(current, TIF_SYSCALL_TRACEPOINT);
ksu_set_task_tracepoint_flag(current);
}
}
@@ -1264,7 +1265,7 @@ int ksu_handle_setuid(struct cred *new, const struct cred *old)
spin_lock_irq(&current->sighand->siglock);
ksu_seccomp_allow_cache(current->seccomp.filter, __NR_reboot);
if (ksu_su_compat_enabled) {
set_tsk_thread_flag(current, TIF_SYSCALL_TRACEPOINT);
ksu_set_task_tracepoint_flag(current);
}
spin_unlock_irq(&current->sighand->siglock);
return 0;
@@ -1278,12 +1279,12 @@ int ksu_handle_setuid(struct cred *new, const struct cred *old)
spin_unlock_irq(&current->sighand->siglock);
}
if (ksu_su_compat_enabled) {
set_tsk_thread_flag(current, TIF_SYSCALL_TRACEPOINT);
ksu_set_task_tracepoint_flag(current);
}
} else {
// Disable syscall tracepoint sucompat for non-allowed processes
if (ksu_su_compat_enabled) {
clear_tsk_thread_flag(current, TIF_SYSCALL_TRACEPOINT);
ksu_clear_task_tracepoint_flag(current);
}
}

View File

@@ -26,6 +26,7 @@
#include "ksud.h"
#include "kernel_compat.h"
#include "selinux/selinux.h"
#include "sucompat.h"
static const char KERNEL_SU_RC[] =
"\n"
@@ -83,7 +84,6 @@ void on_post_fs_data(void)
done = true;
pr_info("%s!\n", __func__);
ksu_load_allow_list();
extern void ksu_mark_running_process(void);
pr_info("mark tif for running process\n");
ksu_mark_running_process();
ksu_observer_init();

View File

@@ -30,6 +30,7 @@
#include "klog.h" // IWYU pragma: keep
#include "ksud.h"
#include "kernel_compat.h"
#include "sucompat.h"
#include "sulog.h"
#define SU_PATH "/system/bin/su"

26
kernel/sucompat.h Normal file
View File

@@ -0,0 +1,26 @@
#ifndef __KSU_H_SUCOMPAT
#define __KSU_H_SUCOMPAT
#include <linux/sched.h>
#include <linux/thread_info.h>
#include <linux/version.h>
void ksu_mark_running_process(void);
static inline void ksu_set_task_tracepoint_flag(struct task_struct *t)
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 11, 0)
set_task_syscall_work(t, SYSCALL_TRACEPOINT);
#else
set_tsk_thread_flag(t, TIF_SYSCALL_TRACEPOINT);
#endif
}
static inline void ksu_clear_task_tracepoint_flag(struct task_struct *t)
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 11, 0)
clear_task_syscall_work(t, SYSCALL_TRACEPOINT);
#else
clear_tsk_thread_flag(t, TIF_SYSCALL_TRACEPOINT);
#endif
}
#endif