linux内存替换,求助:redhat9内核模块替换sys_execve导致系统内存耗尽问题
发布日期:2021-06-24 12:27:31 浏览次数:2 分类:技术文章

本文共 1809 字,大约阅读时间需要 6 分钟。

#include void **sys_calls_table;

#ifndef HIDDEN_SCT

extern void *sys_call_table[];

#endif

#if defined(HIDDEN_SCT)

#ifdef NO_SYS_CLOSE

unsigned long sys_close_ = SYS_CLOSE_ADDR;

#else

unsigned int sys_close_ = (unsigned long )sys_close;

#endif

void ** get_sys_call_table_addr(void)

{

unsigned long ptr;

extern int loops_per_jiffy;

unsigned long *p;

for (ptr=(unsigned long)&loops_per_jiffy ; ptr {

p = (unsigned long *)ptr;

if (p[6] == sys_close_)

{

return (void **)p;

}

}

return NULL;

}

#endif

static asmlinkage int (*old_sys_execve)(struct pt_regs regs);

asmlinkage int new_sys_execve(struct pt_regs regs)

{

int error;

char * filename;

filename = getname((char *) regs.ebx);

error = PTR_ERR(filename);

if (IS_ERR(filename))

goto out;

error = do_execve(filename, (char **) regs.ecx, (char **) regs.edx, &regs);

if (error == 0)

current->ptrace &= ~PT_DTRACE;

putname(filename);

out:

return error;

}

int Monitor_intercept_calls (void)

{

/* execve() */

old_sys_execve = sys_calls_table[__NR_execve];

sys_calls_table[__NR_execve] = new_sys_execve;

printk("old_exec = %lu, new_exec = %lu\n", (unsigned long)old_sys_execve, (unsigned long)new_sys_execve);

return 0;

}

int Monitor_restore_calls (void)

{

/* Restore open() call */

if ( sys_calls_table[__NR_execve] != new_sys_execve)

return 1;

sys_calls_table[__NR_execve] = old_sys_execve;

return 0;

}

int init_module()

{

lock_kernel();

#ifdef HIDDEN_SCT

sys_calls_table = get_sys_call_table_addr();

#else

sys_calls_table = sys_call_table;

#endif

unlock_kernel();

if (!sys_calls_table) {

printk("System calls table can't be found\n");

return -EPERM;

}

printk("Load CMD_EXEC_CONTROLOR MODULE\n");

Monitor_intercept_calls();

return 0;

}

int cleanup_module()

{

Monitor_restore_calls();

return 0;

}

MODULE_LICENSE("GPL");

红帽系统是在vmare中安装的。运行7小时后,top结果如图所示:

请教各位高人,不胜感激!!!

转载地址:https://blog.csdn.net/weixin_32697149/article/details/116684892 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Linux启动屏幕打印日志,linux启动时如何在屏幕上找到文本显示?这...
下一篇:linux hadoop etc目录,题目Linux平台下Hadoop的安装配置

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2024年04月27日 18时10分46秒