A module written to modify the system call always reports a segment error!
Source: Internet
Author: User
A module written to modify the system call always reports a segment error! -- Linux general technology-Linux programming and kernel information. The following is a detailed description. Recently I wrote an LKM for modifying system calls. My kernel is 2.6.24 and is from fedora8. The source code is as follows:
# Ifndef _ KERNEL __
# Define _ KERNEL __
# Endif
# Ifndef MODULE
# Define MODULE
# Endif
# Ifdef CONFIG_MODVERSIONS
# Define MODVERSIONS
# Include
# Endif
# Include
# Include
# Include
# Include
MODULE_LICENSE ("GPL ");
// Because sys_call_table is not exposed in the 2.6 kernel, I checked the address of sys_call_table in/boot/System. map.
Void ** sys_call_table = (void **) 0xc06357a0;
Int (* orig_open) (const char * filename, int flags, int mode );
Int new_open (const char * filename, int flags, int mode)
{
// It's just a test.
Printk ("this is a test \ n ");
Return orig_open (filename, flags, mode );
}
Int init_module (void)
{
Orig_open = sys_call_table [_ NR_open];
Sys_call_table [_ NR_open] = new_open;
Printk ("init_module exe \ n ");
Return 0;
}
Void cleanup_module (void)
{
Sys_call_table [_ NR_open] = orig_open;
Printk ("cleanup_module exe \ n ");
}
Compilation is normal, but when insmod test2.ko is used, a segment error occurs.
When the system reported a segment error, I used dmesg to view the error message as follows:
<1> BUG: unable to handle kernel paging request at virtual address c06357b4
Printing eip: d0aac056 * PVDF = 0e9dd163 * pte = 00635161
Oops: 0003 [#1] SMP
Modules linked in: test2 (U) addsym (U) using autofs4 fuse rfcomm l2cap bluetooth sunrpc when using xt_state when using iptable_filter when x_tables loop dm_multipath ipv6 when gameport snd_rawmidi when using commandid parport snd_seq floppy when using snd_pcm when ac button pcnet32 snd unzip pcspkr soundcore mii unzip i2c_core sr_mod sg cdrom BusLogic dm_snapshot dm_zero dm_mirror dm_mod ata_piix pata_acpi ata_generic libata sd_mod scsi_mod ext3 jbd mbcache uhci_hcd extends
By adding printk to the code, I found that after orig_open = sys_call_table [_ NR_open] is executed, orig_open has been correctly assigned the sys_open value, which is consistent with the sys_open VALUE IN System. map.
The error occurs in the init_module's value assignment to sys_call_table [_ NR_open]: sys_call_table [_ NR_open] = new_open;
The error message is unable to handle kernel paging request at virtual address c06357b4. The system call number of sys_open is 5. The address of my sys_call_table is c06357a0. C06357b4 is just c06357a0 + 5*4.
Therefore, I guess that a new value cannot be written to sys_call_table [_ NR_open. But the moudle I read on the Internet and in my book that modifies the system call is written in this way. Why is this error reported when I load the module? Isn't there any new changes to my 2.6.24 kernel?
You are in urgent need of expert help. Thank you !!
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.