据我所知,linux内核是铁板一块的。这意味着,如果任何内核模块崩溃,整个系统应该崩溃。然而,我并没有看到同样的情况。这是我的越野车计划?为什么我的机器没坏?我如何修改我的程序使我的系统崩溃?
#include <linux/init.h>
#include <linux/module.h> /** needed by all modules **/
#include <linux/kernel.h> /** This is for KERN_ALERT **/
MODULE_LICENSE("SJ BSD/GPL");
int t = 100;
static int hello_init(void)
{
printk(KERN_ALERT "Hello SJ\n");
t = t *10;
t = t/0;
printk(KERN_ALERT "The value of t is %d\n",t);
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye..SJ\n");
}
module_init(hello_init);
module_exit(hello_exit);这是我得到的输出-
# insmod ./hello.ko
Segmentation fault
#uname -a
2.6.32.26-175.fc12.i686.PAE #1 SMP Wed Dec 1 21:45:50 UTC 2010 i686 i686 i386 GNU/Linuxdmesg尾巴是
id: 20883, comm: insmod Tainted: P (2.6.32.26-175.fc12.i686.PAE #1) OptiPlex 990
EIP: 0060:[<f7e9e02f>] EFLAGS: 00010246 CPU: 4
EIP is at param_init+0x1a/0x27 [param]
EAX: 00000000 EBX: f7e9e0b0 ECX: c0aa8e60 EDX: 00000000
ESI: 00000000 EDI: f7e9e015 EBP: f2d39f84 ESP: f2d39f7c
DS: 007b ES: 007b FS: 00d8 GS: 00e0 SS: 0068
Process insmod (pid: 20883, ti=f2d38000 task=f6630000 task.ti=f2d38000)
Stack:
f7e9e079 00000000 f2d39f9c c040305b 00000000 f7e9e0b0 00000000 bfe0ed78
<0> f2d39fac c04716da 09932018 00000000 f2d38000 c040903b 09932018 000169c9
<0> 09932008 00000000 bfe0ed78 bfe0ed98 00000080 0000007b 0000007b 00000000
Call Trace:
[<c040305b>] ? do_one_initcall+0x51/0x13f
[<c04716da>] ? sys_init_module+0xac/0x1e2
[<c040903b>] ? sysenter_do_call+0x12/0x28
Code: 1f 44 00 00 68 66 e0 e9 f7 e8 cf 93 90 c8 58 c9 c3 55 89 e5 0f 1f 44 00 00 ff 35 18 e2 e9 f7 68 79 e0 e9 f7 e8 b4 93 90 c8 31 c0 <c7> 05 00 00 00 00 64 00 00 00 c9 c3 90 04 00 00 00 14 00 00 00
EIP: [<f7e9e02f>] param_init+0x1a/0x27 [param] SS:ESP 0068:f2d39f7c我预计整个系统都会崩溃。但是,机器尚未崩溃或重新启动。只是那个特殊的模块崩溃了。我想让整个系统瘫痪。它应该是理想的,因为内核是单块的。内核中的任何问题都应该关闭整个机器。然而,我并没有看到同样的情况。有什么问题吗?你能给它加点光吗?我的概念在这里不正确吗?
发布于 2014-04-13 08:12:42
我使用了编写函数的旧方法,它可靠地破坏了VM的内核。
VM正在运行Red Hat Enterprise Linux Server release 6.3。
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
int t = 100;
int init_module(void)
{
printk(KERN_ALERT "Hello SJ\n");
t = t *10;
t = t/0;
printk(KERN_ALERT "The value of t is %d\n",t);
}
void cleanup_module(void)
{
}根据您的更新,我最好的猜测是,insmod工具在将函数插入内核之前正在编译和运行函数,这就是为什么insmod命令本身是分段错误的原因。原因是您的dmesg输出表明,分段错误的是Process insmod。不过,要验证这一点,您必须查看系统的insmod源代码。
要确定insmod是以内核模式运行模块还是以用户模式运行模块,一个有趣的实验是将一些特权指令(如rdmsr)作为内联汇编程序放入模块中,看看insmod是否会因此而窒息。
https://stackoverflow.com/questions/23040321
复制相似问题