Replacing sys_execve with the redhat9 kernel module causes system memory depletion.

Source: Internet
Author: User
Replacing sys_execve with the redhat9 kernel module causes system memory depletion-Linux general technology-Linux programming and kernel information. For details, see the following. Write a kernel module on redhat9, replace sys_execve call, load and run the system (/usr/bin/who) command cyclically on four terminals, about 7 hours later, the system will run out of memory and the message "out ofmemory: killed httpd" will be reported.
The following is my code, which seems to be very simple. Why is this?
# Define _ KERNEL __
# Define MODULE
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
// # Include
// # Include
# Include
# Include
# Include
# 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 <(unsigned long) & boot_cpu_data; ptr ++ = sizeof (void *))
{
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_cils (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_cils (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 calltable can't be found \ n ");
Return-EPERM;
}
Printk ("Load into _exec_controlor MODULE \ n ");

Monitor_intercept_cils ();

Return 0;
}

Int cleanup_module ()
{
Monitor_restore_cils ();
Return 0;
}
MODULE_LICENSE ("GPL ");

The Red Hat system is installed in vmare. Top result after 7 hours of running:


I am very grateful to all of you !!!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.