当前位置:网站首页>Handling of legal instruction problems
Handling of legal instruction problems
2022-06-21 10:36:00 【Longcheng deficit】
Illegal (iLLegal) instruction Intuitively explain ---- Illegal order . On the surface CPU During the execution of instructions , Illegal instruction found , That is, unknown instructions or unauthorized instructions . If you just follow this idea , It's easy to fall into trust in the compiler . Actually , This problem , It may also be caused by the program itself . For example, embedded assembly is used , Then the writer is responsible for the instructions used . Another example is the stack 、 Memory error , here , The instruction accessed may be random data in memory or non instruction data , It can also lead to CPU Can't recognize . I saw a comprehensive analysis article on the Internet , Put it here for reference :
Illegal order (Illegal Instruction) Problem location - ArnoldLu - Blog Garden
I need to add something to this question :
I haven't thought it over before , Made the above conclusion , Then I thought about it , It doesn't feel so simple . For the first case , Use embedded assembly , Actual test , It is found that if the wrong assembly instruction is used , The compiler is not recognized . Wanting is also , Embedded assembly is also a format , There are also many ways to write extensions , The compiler does not follow a macro like definition , Directly trusted and used , Instead, it requires secondary treatment , Keep the basic processing flow , Regenerate assembly instructions that do not affect the context ( The use of registers is considered as a whole ). thus , It is impossible to cheat the machine easily by embedding assembly . About embedded assembly , For simple examples, please refer to the following links :
Is inline compilation terrible ? After reading this article , End it !
continue , For the second case , Modify code instructions , It is not a simple and easy thing . Modern operating systems use the virtual memory mechanism , further , Most of them use the paging mechanism . that , For program code snippets , When the operating system maps memory pages , Will mark such pages as read-only , therefore , Try to modify the code directly , It doesn't work .
For this point , It's not absolute . Can pass mprotect call , Modify the read / write properties of the page , Reference article :
Kernel hotfix , Is it really safe ?
To sum up the above two points , Artificial generation of illegal instructions , We need to think again .
The third supplement : stay X86 After the next attempt fails many times , Finally in the arm The servant successfully generated the above error instruction prompt . The specific process is as follows :
First , The program is simply handled , The following abnormal signal capture is added
void signal_handler(int signum) {
printf("Signal %d (number) captured \n", signum);
}
signal(SIGILL , signal_handler);
The above code expects that when an illegal instruction is generated , Captured by the application , And further processing .
And then to x86, Because simple error instructions are recognized by the compiler , So I mainly tried call and jmp Instructions . Both instructions are followed by a random address , Can compile through . however , Actual operation , Are similar paragraph errors , That is, it is mainly a memory error .
call Because it is similar to function call , There are operations such as entering and leaving the stack , The paragraph error is understandable , however jmp The order is an unconditional jump , The address you jump to may not contain valid code , For example, unable to decode . however , Multiple attempts , It is still a segment error .x86 Next abandon .
Try ARM platform . Found one with CPU Version dependent instructions ,swpb, This is one that existed in the early days ARM CPU Instructions on the , Interested readers can search for .
Use the following embedded assembly code
asm volatile("swpb %0,%2,[%3]"
: "=&r"(ret), "=m" (*ptr)
: "r"(newval), "r"(ptr)
: "cc", "memory"); //memory == no cache | cc == status register update Compile and pass . Execution procedure , Report illegal instructions .
gdb Trace debugging , When an illegal instruction is found , Yes swpb Command Division . Here's the picture :

Program received signal SIGILL, Illegal instruction. An illegal instruction was successfully generated .
This explanation , On the embedded platform , Maybe because of the embedded assembly 、 Compiler Version 、 Connection libraries, etc. cause illegal runtime instructions .
边栏推荐
- Introduction and template of segment tree Foundation (I)
- Polymorphic & class object & registered factory & Reflection & dynamic proxy
- 中国国际电子商务中心与易观分析联合发布:2021年4季度全国网络零售发展指数同比增长0.6%
- ESP8266/ESP32 +1.3“ or 0.96“ IIC OLED指针式时钟
- 远程办公市场调查报告
- 音视频格式简介、编解码、音视频同步
- EIG和沙特阿美签署谅解备忘录,扩大能源合作
- Start from scratch 10- background management system development
- cvte一面
- 流式编程:流支持,创建,中间操作以及终端操作
猜你喜欢

Three elements of basic concepts and methods of machine learning

TC software outline design document (mobile group control)
![触摸按键控制器TTP229-BSF使用心得[原创cnblogs.com/helesheng]](/img/2f/3594188c5e58d3501f76f4937a979c.png)
触摸按键控制器TTP229-BSF使用心得[原创cnblogs.com/helesheng]

js正则-梳理

Xidian AI ranked higher than Qingbei in terms of AI major, and Nantah ranked first in China in terms of Software Science in 2022

东方甄选双语直播火爆出圈,新东方转型初见端倪

Celsius 的暴雷,会是加密领域的“雷曼时刻”吗?

The backbone of the top 100 security companies! Meichuang technology was selected into the 2022 China top 100 Digital Security Report

开课报名|「Takin开源特训营」第一期来啦!手把手教你搞定全链路压测!

Brief introduction of quality control conditions before genotype filling
随机推荐
Equals and hashcode
DSP online upgrade (3) -- how to burn two projects in the on-chip flash of a DSP chip
The "first city" in Central China. How can Changsha be built?
程序員新人周一優化一行代碼,周三被勸退?
Regression analysis - basic content
使用shapeit进行单倍型分析
EIG和沙特阿美签署谅解备忘录,扩大能源合作
DSP online upgrade (2) -- design framework of bootloader
音视频格式简介、编解码、音视频同步
Talk about the multimodal project of fire
从零开始做网站11-博客开发
[cloud based co creation] enterprise digitalization accelerates "new intelligent manufacturing"
AI越进化越跟人类大脑像!Meta找到了机器的“前额叶皮层”,AI学者和神经科学家都惊了...
DSP online upgrade (1) -- understand the startup process of DSP chip
China international e-commerce center and Analysys jointly released: the national online retail development index in the fourth quarter of 2021 increased by 0.6% year on year
Bit segment operation of STM32, LED lighting based on stm32f103xxx multiple methods
support vector machine
开课报名|「Takin开源特训营」第一期来啦!手把手教你搞定全链路压测!
TC software detailed design document (mobile group control)
Unity中的地平面简介