使用data breakpoint 追踪地址寄存器被修改的问题
一. 介绍
data breakpoint是一种特殊的断电,在处理检查到预设地址的值发生R/W操作时,发生断点中断。
二. 使用方法1
kernel有示例代码,在data_breakpoint.c中,在这里,kernel检查的是symbol的值发生变化,但是实际上测试发现直接使用寄存器地址也是可以的。
看看.config里面,CONFIG_SAMPLES是否选中。
位置在Kernel Hacking/Sample kernel code。
samples目录好像不在缺省编译的范围内,自己手动编译就行了。
make M=samples即可。
aarch32 linux4.9
kernel 有breakpoint的编码实例data_breakpoint.c
相关函数:
register_wide_hw_breakpoint //kernel space 地址
register_user_hw_breakpoint //user space 地址
breakpoint 与 watchpoint 的原理需要查阅armv7_architecture_reference_manual
watchpoint:If the cause of the debug exception is a Watchpoint debug event, then a Data Abort exception is generated
————————————————
版权声明:本文为CSDN博主「shenhuxi_yu」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/shenhuxi_yu/article/details/83155106
/*
- data_breakpoint.c - Sample HW Breakpoint file to watch kernel data address
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- usage: insmod data_breakpoint.ko ksym=<ksym_name>
- This file is a kernel module that places a breakpoint over ksym_name kernel
- variable using Hardware Breakpoint register. The corresponding handler which
- prints a backtrace is invoked every time a write operation is performed on
- that variable.
- Copyright © IBM Corporation, 2009
- Author: K.Prasad prasad@linux.vnet.ibm.com
/
#include <linux/module.h> / Needed by all modules /
#include <linux/kernel.h> / Needed for KERN_INFO /
#include <linux/init.h> / Needed for the macros */
#include <linux/kallsyms.h>
#include <linux/perf_event.h>
#include <linux/hw_breakpoint.h>
struct perf_event * __percpu *sample_hbp;
static char ksym_name[KSYM_NAME_LEN] = “pid_max”;
module_param_string(ksym, ksym_name, KSYM_NAME_LEN, S_IRUGO);
MODULE_PARM_DESC(ksym, “Kernel symbol to monitor; this module will report any”
" write operations on the kernel symbol");
static void sample_hbp_handler(struct perf_event *bp,
struct perf_sample_data *data,
struct pt_regs *regs)
{
printk(KERN_INFO “%s value is changed\n”, ksym_name);
dump_stack();
printk(KERN_INFO “Dump stack from sample_hbp_handler\n”);
}
static int __init hw_break_module_init(void)
{
int ret;
struct perf_event_attr attr;
hw_breakpoint_init(&attr);
attr.bp_addr = kallsyms_lookup_name(ksym_name);
attr.bp_len = HW_BREAKPOINT_LEN_4;
attr.bp_type = HW_BREAKPOINT_W | HW_BREAKPOINT_R;sample_hbp = register_wide_hw_breakpoint(&attr, sample_hbp_handler, NULL);
if (IS_ERR((void __force *)sample_hbp)) {ret = PTR_ERR((void __force *)sample_hbp);goto fail;
}printk(KERN_INFO "HW Breakpoint for %s write installed\n", ksym_name);return 0;
fail:
printk(KERN_INFO “Breakpoint registration failed\n”);
return ret;
}
static void __exit hw_break_module_exit(void)
{
unregister_wide_hw_breakpoint(sample_hbp);
printk(KERN_INFO “HW Breakpoint for %s write uninstalled\n”, ksym_name);
}
module_init(hw_break_module_init);
module_exit(hw_break_module_exit);
MODULE_LICENSE(“GPL”);
MODULE_AUTHOR(“K.Prasad”);
MODULE_DESCRIPTION(“ksym breakpoint”);
三. 使用方法2
上面是使用kernel的hw_breakpoint走watchpoint来注册的,实际上这里有一层封装,我们直接使用arch/arm下面的hw_breakpoint也是可以的。
这里直接给代码链接了:https://elixir.bootlin.com/linux/v4.6/source/arch/arm/kernel/hw_breakpoint.c
有很多操作寄存器的地方,比较底层了,不过便于理解。
三. 使用方法2
上面是使用kernel的hw_breakpoint走watchpoint来注册的,实际上这里有一层封装,我们直接使用arch/arm下面的hw_breakpoint也是可以的。
这里直接给代码链接了:https://elixir.bootlin.com/linux/v4.6/source/arch/arm/kernel/hw_breakpoint.c
有很多操作寄存器的地方,比较底层了,不过便于理解。
四. 第一种方法的结果
pid_max value is changed
CPU: 2 PID: 439 Comm: kworker/u8:3 Tainted: P W O 4.19.166 #2
Hardware name: xxxx (DT)
Workqueue: events_unbound call_usermodehelper_exec_work
Call trace:
dump_backtrace+0x0/0x164
show_stack+0x20/0x2c
dump_stack+0xb8/0xf0
sample_hbp_handler+0x28/0x3c [data_breakpoint]
__perf_event_overflow+0x94/0xe0
perf_swevent_event+0x98/0x104
perf_bp_event+0x6c/0x98
watchpoint_report+0x80/0x94
watchpoint_handler+0x100/0x208
do_debug_exception+0xe8/0x174
el1_dbg+0x18/0xa8
alloc_pid+0x80/0x284
copy_process+0xb48/0x1960
_do_fork+0xa0/0x434
kernel_thread+0x40/0x50
call_usermodehelper_exec_work+0x40/0xd8
process_one_work+0x210/0x3e8
worker_thread+0x228/0x3c4
kthread+0x13c/0x14c
ret_from_fork+0x10/0x18
Dump stack from sample_hbp_handler
六. 注意的地方
data breakpoint不同于breakpoint,发生异常后,因为寄存器中的值不会被清除,所以会一直循环中断
一般的,我们通过调用单步执行,并且清掉异常寄存器的值,让程序可以继续执行,这样在下次发生异常的时候还可以继续进入data watchpoint
使用data breakpoint 追踪地址寄存器被修改的问题相关推荐
- 使用dom breakpoint找到修改属性的javascript代码
Created by Jerry Wang, last modified on Sep 23, 2014 使用dom breakpoint能快速找到修改了某一个dom element的JavaScri ...
- GeoServer修改切片缓存目录和data目录
GeoServer修改切片缓存目录和data目录 在官网下载geoserver-war.zip包后,解压有geoserver.war,其中根目录有data文件夹,拷贝出来放到指定部署的共享目录下,然后 ...
- 基于docker部署的微服务架构(九): 分布式服务追踪 Spring Cloud Sleuth
为什么80%的码农都做不了架构师?>>> 前言 微服务架构中完成一项功能经常会在多个服务之间远程调用(RPC),形成调用链.每个服务节点可能在不同的机器上甚至是不同的集群上,需 ...
- 【pytorch】.detach() .detach_() 和 .data==>用于切断反向传播
当我们再训练网络的时候可能 希望保持一部分的网络参数不变,只对其中一部分的参数进行调整: 或者只训练部分分支网络,并不让其梯度对主网络的梯度造成影响, 这时候我们就需要使用detach()函数来切断一 ...
- pytorch .detach() .detach_() 和 .data用于切断反向传播
参考:https://pytorch-cn.readthedocs.io/zh/latest/package_references/torch-autograd/#detachsource 当我们再训 ...
- 没有添加跳新增,添加之后跳修改
最新项目需求在首页需要添加一个界面提示,用户添加汽车信息之后再次点击跳到修改,没有的话就跳到新增界面去,这样的一个功能,我用了整整2天的时间, 大致说下其思路,后台给了一个carcode值0就跳到新增 ...
- 开发自己的Data Access Application Block[下篇]
上接:[原创] 我的ORM: 开发自己的Data Access Application Block - Part I 4. Database 下面来介绍重中之重:Database,绝大部分的Data ...
- flaskr 报错及其修改
作者:hhh5460 官网有一个flaskr的例子,按照其8个步骤(包括测试),一步一步照着做,有3个地方报错. 究其原因,可能是flaskr这个例子年代比较久远,而现在python以及flask都有 ...
- 利用服务器修改服务器数据,用Jquery实现可编辑表格并用AJAX提交到服务器修改数据...
下面是js Code: $(function() { // 相当于在页面中的body标签加上onload事件 $(".caname").click(function() { // ...
最新文章
- PHP获取当前url路径的函数及服务器变量:QUERY_STRING、REQUEST_URI、SCRIPT...
- selenium代码练习
- JavaScript 技术篇-js正则表达式匹配字符串左右两边是否包含空格
- 美团王庆:当老板对指标进行灵魂拷问时,该如何诊断分析?
- fiddler 抓取手机app请求包
- apache 配置文件内使用 8080 端口_【SpringBoot 框架】- SpringBoot 配置文件
- webpack常用配置
- SonarQube代码质量管理平台C++插件sonar-cxx的安装
- 简单的CreateRemoteThread例程-初学者必看
- Python 基础,不看会后悔哦!
- python-time时间模块
- 一加、OPPO官宣合并,“父子团圆”能否拯救一加?
- 每秒上百万次的跨数据中心写操作,Uber是如何使用Cassandra处理的?
- 【python】QQ 空间照片下载器
- Python学习笔记2
- 质量管理三个概念:QC、QA和QM,你能分得清吗?
- OKRA-ERP简单实用产能分析
- 厉害了!自己动手也能做一个推荐系统!
- java 子类克隆_Java对象克隆了解
- linux 无线网卡 免驱动,Linux系统下安装USB无线网卡驱动方法
热门文章
- lr创建mysql odbc_LoadRunner利用ODBC编写MySql脚本(转)
- 令人头秃的集训第三周学习记录(练习题+感悟)
- python语言中的单行注释语句_Python入门基础系列(五)——单行和多行注释
- 使用群晖作mineportalbox(1):合理且不折腾地使用群晖硬件和套件
- linux kde磁盘扫描,在KDE桌面中使用Krusader进行更好的文件管理 | MOS86
- Ms Sql Server 2000 个人绿色版 5.62
- 关于IOS中设置中找不到开发者选项的解决办法
- 论汽车车机快速启动与开机动画、倒车影像三者关系
- 5G wifi 和 5G通信
- 一级建造师资格考试报名条件(2012-05-16)