kernel: Set the tracepoint flag in a tracepoint manner
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
#include "linux/compiler.h"
|
#include <linux/compiler.h>
|
||||||
#include "linux/sched/signal.h"
|
#include <linux/sched/signal.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/task_work.h>
|
#include <linux/task_work.h>
|
||||||
#include <linux/thread_info.h>
|
#include <linux/thread_info.h>
|
||||||
@@ -42,6 +42,7 @@
|
|||||||
#include "selinux/selinux.h"
|
#include "selinux/selinux.h"
|
||||||
#include "kernel_compat.h"
|
#include "kernel_compat.h"
|
||||||
#include "supercalls.h"
|
#include "supercalls.h"
|
||||||
|
#include "sucompat.h"
|
||||||
#include "sulog.h"
|
#include "sulog.h"
|
||||||
|
|
||||||
#ifdef CONFIG_KSU_MANUAL_SU
|
#ifdef CONFIG_KSU_MANUAL_SU
|
||||||
@@ -261,8 +262,8 @@ void escape_to_root(void)
|
|||||||
ksu_sulog_report_su_grant(current_euid().val, NULL, "escape_to_root");
|
ksu_sulog_report_su_grant(current_euid().val, NULL, "escape_to_root");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for_each_thread(p, t){
|
for_each_thread (p, t) {
|
||||||
set_tsk_thread_flag(t, TIF_SYSCALL_TRACEPOINT);
|
ksu_set_task_tracepoint_flag(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,8 +381,8 @@ void escape_to_root_for_cmd_su(uid_t target_uid, pid_t target_pid)
|
|||||||
#if __SULOG_GATE
|
#if __SULOG_GATE
|
||||||
ksu_sulog_report_su_grant(target_uid, "cmd_su", "manual_escalation");
|
ksu_sulog_report_su_grant(target_uid, "cmd_su", "manual_escalation");
|
||||||
#endif
|
#endif
|
||||||
for_each_thread(p, t){
|
for_each_thread (p, t) {
|
||||||
set_tsk_thread_flag(t, TIF_SYSCALL_TRACEPOINT);
|
ksu_set_task_tracepoint_flag(t);
|
||||||
}
|
}
|
||||||
pr_info("cmd_su: privilege escalation completed for UID: %d, PID: %d\n", target_uid, target_pid);
|
pr_info("cmd_su: privilege escalation completed for UID: %d, PID: %d\n", target_uid, target_pid);
|
||||||
}
|
}
|
||||||
@@ -558,7 +559,7 @@ int ksu_handle_setuid(struct cred *new, const struct cred *old)
|
|||||||
|
|
||||||
if (new_uid.val == 2000) {
|
if (new_uid.val == 2000) {
|
||||||
if (ksu_su_compat_enabled) {
|
if (ksu_su_compat_enabled) {
|
||||||
set_tsk_thread_flag(current, TIF_SYSCALL_TRACEPOINT);
|
ksu_set_task_tracepoint_flag(current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -579,7 +580,7 @@ int ksu_handle_setuid(struct cred *new, const struct cred *old)
|
|||||||
spin_lock_irq(¤t->sighand->siglock);
|
spin_lock_irq(¤t->sighand->siglock);
|
||||||
ksu_seccomp_allow_cache(current->seccomp.filter, __NR_reboot);
|
ksu_seccomp_allow_cache(current->seccomp.filter, __NR_reboot);
|
||||||
if (ksu_su_compat_enabled) {
|
if (ksu_su_compat_enabled) {
|
||||||
set_tsk_thread_flag(current, TIF_SYSCALL_TRACEPOINT);
|
ksu_set_task_tracepoint_flag(current);
|
||||||
}
|
}
|
||||||
spin_unlock_irq(¤t->sighand->siglock);
|
spin_unlock_irq(¤t->sighand->siglock);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -593,12 +594,12 @@ int ksu_handle_setuid(struct cred *new, const struct cred *old)
|
|||||||
spin_unlock_irq(¤t->sighand->siglock);
|
spin_unlock_irq(¤t->sighand->siglock);
|
||||||
}
|
}
|
||||||
if (ksu_su_compat_enabled) {
|
if (ksu_su_compat_enabled) {
|
||||||
set_tsk_thread_flag(current, TIF_SYSCALL_TRACEPOINT);
|
ksu_set_task_tracepoint_flag(current);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Disable syscall tracepoint sucompat for non-allowed processes
|
// Disable syscall tracepoint sucompat for non-allowed processes
|
||||||
if (ksu_su_compat_enabled) {
|
if (ksu_su_compat_enabled) {
|
||||||
clear_tsk_thread_flag(current, TIF_SYSCALL_TRACEPOINT);
|
ksu_clear_task_tracepoint_flag(current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "ksud.h"
|
#include "ksud.h"
|
||||||
#include "kernel_compat.h"
|
#include "kernel_compat.h"
|
||||||
#include "selinux/selinux.h"
|
#include "selinux/selinux.h"
|
||||||
|
#include "sucompat.h"
|
||||||
|
|
||||||
|
|
||||||
static const char KERNEL_SU_RC[] =
|
static const char KERNEL_SU_RC[] =
|
||||||
@@ -74,7 +75,6 @@ void on_post_fs_data(void)
|
|||||||
done = true;
|
done = true;
|
||||||
pr_info("on_post_fs_data!\n");
|
pr_info("on_post_fs_data!\n");
|
||||||
ksu_load_allow_list();
|
ksu_load_allow_list();
|
||||||
extern void ksu_mark_running_process(void);
|
|
||||||
pr_info("mark tif for running process\n");
|
pr_info("mark tif for running process\n");
|
||||||
ksu_mark_running_process();
|
ksu_mark_running_process();
|
||||||
ksu_observer_init();
|
ksu_observer_init();
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include "klog.h" // IWYU pragma: keep
|
#include "klog.h" // IWYU pragma: keep
|
||||||
#include "ksud.h"
|
#include "ksud.h"
|
||||||
#include "kernel_compat.h"
|
#include "kernel_compat.h"
|
||||||
|
#include "sucompat.h"
|
||||||
#include "sulog.h"
|
#include "sulog.h"
|
||||||
|
|
||||||
#define SU_PATH "/system/bin/su"
|
#define SU_PATH "/system/bin/su"
|
||||||
@@ -402,7 +403,7 @@ void ksu_mark_running_process()
|
|||||||
bool ksu_root_process =
|
bool ksu_root_process =
|
||||||
uid == 0 && is_task_ksu_domain(get_task_cred(t));
|
uid == 0 && is_task_ksu_domain(get_task_cred(t));
|
||||||
if (ksu_root_process || ksu_is_allow_uid(uid)) {
|
if (ksu_root_process || ksu_is_allow_uid(uid)) {
|
||||||
set_tsk_thread_flag(t, TIF_SYSCALL_TRACEPOINT);
|
ksu_set_task_tracepoint_flag(t);
|
||||||
pr_info("sucompat: mark process: pid:%d, uid: %d, comm:%s\n",
|
pr_info("sucompat: mark process: pid:%d, uid: %d, comm:%s\n",
|
||||||
t->pid, uid, t->comm);
|
t->pid, uid, t->comm);
|
||||||
}
|
}
|
||||||
@@ -415,7 +416,7 @@ static void unmark_all_process()
|
|||||||
struct task_struct *p, *t;
|
struct task_struct *p, *t;
|
||||||
read_lock(&tasklist_lock);
|
read_lock(&tasklist_lock);
|
||||||
for_each_process_thread (p, t) {
|
for_each_process_thread (p, t) {
|
||||||
clear_tsk_thread_flag(t, TIF_SYSCALL_TRACEPOINT);
|
ksu_clear_task_tracepoint_flag(t);
|
||||||
}
|
}
|
||||||
read_unlock(&tasklist_lock);
|
read_unlock(&tasklist_lock);
|
||||||
pr_info("sucompat: unmark all user process done!\n");
|
pr_info("sucompat: unmark all user process done!\n");
|
||||||
|
|||||||
26
kernel/sucompat.h
Normal file
26
kernel/sucompat.h
Normal 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
|
||||||
Reference in New Issue
Block a user