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

Pid: 3793, comm: insmod Not tainted (2.6.24.7-92. fc8 #1)
EIPs: 0060 :[ ] EFLAGS: 00010286 CPU: 0
EIP is at init_module + 0x13/0x29 [test2]
EAX: c0487967 EBX: c3c05268 ECX: 00000000 EDX: c06357b4
ESI: c3c05240 EDI: 00000001 EBP: d0aac1_esp: ced43ebc
DS: 007b ES: 007b FS: 00d8 GS: 0033 SS: 0068
Process insmod (pid: 3793, ti = ced43000 task = c92d0690 task. ti = ced43000)
Stack: 00000000 c044d064 00000000 00000000 c1025520 00000200 2017001b 00000000
C3d9b990 00000438 describe03 c91ea004 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
Call Trace:
[ ] Sys_init_module + 0x14d6/0x15f9
[ ] Printk + 0x0/0x1f
[ ] Syscall_call + 0x7/0xb
======================================
Code: aa d0 a1 2c c4 aa d0 89 50 14 c7 04 24 04 c1 aa d0 e8 69 37 98 ef 58 c3 83 ec 04 8b 15 2c c4 aa d0 83 c2 14 8b 02 a3 0c d6 aa d0 02 6c c0 aa d0 c7 04 24 18 c1 aa d0 e8 42 37 98 ef 31 c0 5a
EIP :[ ] Init_module + 0x13/0x29 [test2] SS: ESP 0068: ced43ebc


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 !!
Related Article

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.