Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 2 gecədir durmaksızın ARM Cortex üzərində reversing ilə məşğulam əlimdə olan STM32 MCU (ARM Cortex M4 processor depended) - ((greetZ Sənan:P )) üzərində RTOS proyekti hazırlayıram hal hazırda debugging prosesində maraqlı nüansla qarşılaşdım. İntel x86-64 arch üzərində aşkarlanmış EoP ARM üzərində tətbiq etməyi nəzərdə tutdum.
- Theory^^^^
- ARM Cortex M4 - 2 processor modundan və 2 privilige level-dan ibarətdir.
- Processor mode and privilege levels for software execution
- The processor modes are:
- Thread mode Used to execute application software. The processor enters Thread mode
- when it comes out of reset.
- Handler mode Used to handle exceptions. The processor returns to Thread mode when it
- has finished all exception processing.
- The privilege levels for software execution are:
- Unprivileged The software:
- • has limited access to the MSR and MRS instructions, and cannot use the
- CPS instruction
- • cannot access the system timer, NVIC, or system control block
- • might have restricted access to memory or peripherals.
- Unprivileged software executes at the unprivileged level.
- Privileged
- The software can use all the instructions and has access to all resources.
- Privileged software executes at the privileged level.
- ARM MCU-de CONTROL register-i (Special register) proqram təminatının privilege yaxud unprivileged modda icrasına nəzarət edir. Unprivileged proqram təminatı SVC instruction istifade etdikdə (supervisor call (syscall)) cari axış privileged moda yönləndirilə bilər.
- CMSIS core :
- __set_CONTROL(THREAD_MODE_UNPRIVILEGED | SP_PROCESS);
- disas mode:
- 0x0800027c <+68>: movs r3, #3
- 0x0800027e <+70>: str r3, [r7, #0]
- 0x08000280 <+72>: ldr r3, [r7, #0]
- 0x08000282 <+74>: msr CONTROL, r3
- inline asm:
- __ASM volatile ("MSR control, %0" : : "r" (control) : "memory");
- hardware state switching ===== >
- _______ ________
- | | | |
- | PRIV | ===========-> | UNPRIV |
- |_______| |________|
- CONTROL REGISTER
- ______________________________________________________3_2_1_0_
- | | | | |
- |_______________________________________________________|_|_|_|
- | |
- SPSEL ___| |
- |
- nPRIV _____|
- Table 2.10. CONTROL register bit assignments
- Bits Name Function
- [31:2] - Reserved.
- [1] SPSEL = Defines the currently active stack pointer: In Handler mode this bit reads as zero and ignores writes. The Cortex-M3 updates this bit automatically on exception return.
- 0 = MSP is the current stack pointer
- 1 = PSP is the current stack pointer.
- [0] nPRIV Defines the Thread mode privilege level:
- 0 = Privileged
- 1 = Unprivileged.
- Privileged moda keçid üçün isə SOFTWARE based interrupt istifadə edilməlidir. Daha sonra isə uyğun interrupt handler icra edilir. Context switching əvvəlində current state (registers) stack-e əlavə edilir. Və Unprivileged moda təkrar qayıtdıqda trap frame istifadə edilərək register state (old registers) bərpa edilir. GDB üzərində interrupt routin-i icra edildiyində NUCLEO üzərindəki RESET button vasitəsi ilə RESET interrupt vektoru handle etdikdə unpriv moda dönməmişdən əvvəl CONTROL REGİSTER STATE = nPRİV bit(1) bu state-də interrupt handle edilir. Bunun nəticəsində isə ortaya çıxır ki user depended registerləri istəyimizə uyğun dəyişib arbitrary code exec yola açmaq mümkündür.
- SVC FRAME ------------>
- ________ ________
- | | | |
- | UNPRIV | ===========-> | PRIV |
- |________| |________|
- will throw a HF handler
- `void HardFault_Handler(void)`
- |
- |
- |
- ----------------------------
- | hardware fault exception |
- ----------------------------
- |
- |
- hijack control flow
Advertisement
Add Comment
Please, Sign In to add comment