ARM Linux崩溃分析(二)- 驱动程序导致系统崩溃的实例分析

本文通过一个简单的测试程序分析了驱动程序如何导致ARM Linux系统崩溃。测试过程中,insmod和rmmod命令触发了内核崩溃,原因是代码中对空指针进行了操作。错误分析显示,错误发生在函数test_exit的0x28处,通过objdump反编译确认了导致问题的汇编指令。解决此类问题需要具备一定的汇编阅读能力。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、 测试用例

写了一个简单的测试程序进行测试:
代码如下:

#include <linux/compat.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/pci.h>
#include <linux/fs.h>
#include <linux/poll.h>
#include <linux/interrupt.h>
#include <linux/cdev.h>
#include <linux/slab.h>
#include <linux/phantom.h>


static int __init test_init(void)
{
   
   
	printk("drivr test \n");
	return  0;
}

static void test_crash(void)
{
   
   
	char *pstr = NULL;
	printk("drivr exit \n");
	printk("drivr exit  111 \n");
	*pstr = 12;
	printk("%s \n",pstr);
	return;
}
static void __exit test_exit(void)
{
   
   
	test_crash();
	return ;
}


module_init(test_init);
module_exit(test_exit);

MODULE_AUTHOR("Alex<free5home5@163.com>");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("test driver");
MODULE_VERSION("v0.0.1");

我把它编译成了一个叫 driver_test.ko的驱动文件
执行:insmod driver_test.ko
然后执行rmmod driver_test.ko
内核直接崩溃了。

二、错误分析

代码一看就明白了,对空指针进行操作导致的崩溃。
错误打印如下:

Unable to handle kernel NULL pointer dereference at virtual address 00000000
Mem abort info:
  ESR = 0x96000046
  Exception class = DABT (current EL), IL = 32 bits
  SET = 0, FnV = 0
  EA = 0, S1PTW = 0
Data abort info:
  ISV = 0, ISS = 0x00000070
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值