page fault liberation army
play

Page Fault Liberation Army Its turtles Turing machines all the way - PowerPoint PPT Presentation

Page Fault Liberation Army Its turtles Turing machines all the way down! Julian Bangert, Sergey Bratus, Rebecca .bx Shapiro Trust Lab Dartmouth College Sunday, February 17, 13 Page Fault Liberation l The x86 MMU is not just


  1. Page Fault Liberation Army It’s turtles Turing machines all the way down! Julian Bangert, Sergey Bratus, Rebecca “.bx” Shapiro Trust Lab Dartmouth College Sunday, February 17, 13

  2. “Page Fault Liberation” l The x86 MMU is not just a look-up table! l x86 MMU performs complex logic on complex data structures l The MMU has state and transitions that brilliant hackers put to unorthodox uses. l Can it be programmed with its data? YES Sunday, February 17, 13

  3. Disclaimer • Turing complete it’s just a way of describing what kind of computations an environment can be programmed to do (T.-c. = any kind we know, in theory) • Wish we had a more granular scale better suited to exploit power Sunday, February 17, 13

  4. Today’s Slogan Any sufficiently advanced/complex input data/metadata acts as “ bytecode ” to the system that must interpret it; that system acts as a “ virtual machine ” for that bytecode (!) Sunday, February 17, 13

  5. Sunday, February 17, 13

  6. ALL KINDS OF DATA FLOWS, CONTROL FLOWS, FEATURES, BUGS,... “BYTECODE/TAPE” Sunday, February 17, 13

  7. ABI Metadata Machines Sarah Inteman/John Kiehl Sunday, February 17, 13

  8. ELF relocation machine LD.SO CODE Sunday, February 17, 13

  9. ELF metadata machines Relocations + symbols: a program in ABI for automaton to patch images loaded at a different virtual address than linked for. Sunday, February 17, 13

  10. RTLD arithmetic r : s : • R_X86_64_COPY: memcpy(r.r_offset, s.st_value, s.st_size) R_X86_64_64: *(base+r.r_offset) = s.st_value +r.r_addend +base R_X86_64_RELATIVE: *(base+r.r_offset) = r.r_addend+base Sunday, February 17, 13

  11. See 29c3 talk by Rebecca “ .bx ” Shapiro, https://github.com/bx/elf-bf-tools Sunday, February 17, 13

  12. Hacker research inspirations • “Backdooring binary objects, klog [Phrack 56:9] • “Cheating the ELF”, the grugq [also Phrack 58:5] • PLT redirection, Silvio Cesare [Phrack 56:7, ...] • Injecting objects, mayhem [Phrack 61:8] • ElfSh/ ERESI team , http://eresi-project.org/ • LOCREATE, skape [Uninformed 6, 2007] • Rewriting (unpacking) of binaries using REL* Sunday, February 17, 13

  13. “Page Fault Liberation” Let’s take an old and known thing... Sunday, February 17, 13

  14. “Page Fault Liberation” ...and see how far we can make it can go! Sunday, February 17, 13

  15. “Page Fault Liberation” and perhaps others can take it further! Sunday, February 17, 13

  16. “Hacking is a practical study of computational models’ limits” • [Apologies for repeating myself] • “What Church and Turing did with theorems, hackers do with exploits” • Great exploits (and effective defenses!) reveal truths about the target’s actual computational model. Sunday, February 17, 13

  17. CPU MMU Write Read IDT Pagetables Stack GDT Sunday, February 17, 13

  18. Traps + Tables = weird machine? • unmapped/bad memory reference trap , based on page tables & (current) IDT • hardware writes fault info on the stack - where it thinks the stack is (address in TSS) • If we point “ stack ” into page tables, GDT or TSS, can we get the “tape” of a Turing machine? Sunday, February 17, 13

  19. Trap-based “Design Patterns” • Overloading #PF for security policy, labeling memory (e.g., PaX, OpenWall) • Combining traps to trap on more complex events (OllyBone, “fetch from a page just written”) • Using several trap bits in different locations to label memory for data flow control (PaX UDEREF, SMAP/SMEP use) • Storing extra state in TLBs (PaX PageExec) • “Unorthodox” breakpoints, control flow, ... Sunday, February 17, 13

  20. Segment descriptor: Global Descriptor Table (GDT) Address (”offset”) Default segment must lie within selector segment limit From: duartes.org/gustavo/blog/ Sunday, February 17, 13

  21. OpenWall • Solar Designer, 1999 Kernel • cf. "Stack Smashing for Fun and Profit" Segments • Stack Data CS limit 3GB - 8 MB (for stack) • Exec from the stack is trapped • Code Kill if current inst = RET • Very specific threat, allows JIT, etc. User • (And many other hardening patches) Sunday, February 17, 13

  22. Virtual Address Translation 0xDEADBEEF Linear Address: 1011011011 cr3 + 1101111010 111011101111 4 * 37a 2db 37a EEF 0x10000 Present + 4 * 2db 0x11111 0x1111 1EEF Physical Address = l All P bits set l Ring 3: All U/S bits have to be set l Write: All R/W bits have to be set l What if we violate these rules? Sunday, February 17, 13

  23. ITS A TRAP Sunday, February 17, 13

  24. PaX • PaX is an awesome Linux hardening patch • Many 'firsts' on real-world OS's, e.g. NX on Intel and ASLR (PaX in 2000, OpenBSD in 2003) • PaX has NX on all CPUs since the Pentium (Intel has hardware support since P4?) • SEGMEXEC and PAGEEXEC • Leverages difference between instruction and data memory paths Sunday, February 17, 13

  25. PaX NX : SegmExec Virtual • Instruction: Virtual address = Linear + CS.base • Data: VA= Linear + DS.base Code • 3GB user space • All Segment limits = 1.5 GB • Data access goes to lower half of VA space Data Linear • Instruction fetch goes to upper half of VA space Sunday, February 17, 13

  26. PaX NX : PageExec • “ split TLB ” (iTLB for fetches, dTLB for loads) [Plex86 1997, to detect self-modifying code: http://pax.grsecurity.net/docs/pageexec.old.txt ] • TLBs are not synchronized with page tables in RAM (manually flushed every time tables change) • NX ~ User/Supervisor bit Sunday, February 17, 13

  27. PageExec data lookup If U=1 Access TLB Not found Pagetable Always U=0 Set user bit, read one byte to #PF fault fill TLB, if EIP=addr, clear user bit it’s a fetch Terminate Sunday, February 17, 13

  28. OllyBone: Trap on end of unpacker • Debugger plugin to analyze (un)packers • Want to break execution on a memory range (so you trap every time you exec from a page after writing it ) • The idea goes back to Plex86 (before PaX) who tried to do virtualization that way http://www.joestewart.org/ollybone/ Sunday, February 17, 13

  29. ShadowWalker Phrack 63:8, BlackHat 2005, DEFCON 13 • When a rootkit detector scans the code (as data !), why not give a different page than when the code is executed? • Instead of having different User bits, we could also have different page frame numbers (trap on P=0 in pagetables) Sunday, February 17, 13

  30. What’s in a trap handler (let’s roll our own) Sunday, February 17, 13

  31. IDT entries: ... 8: #DF ... 14: #PF ... Sunday, February 17, 13

  32. Call through a Trap Gate 32 bit? nested interrupts? New code segment Like a FAR call of old. If the new segment is in a lower (i.e. higher privilege) Ring, we load a new SP . Sunday, February 17, 13

  33. Pushes parameters to “handler’s stack” These two are only pushed if we changed the stack ESP “IRET” instruction can return from this Sunday, February 17, 13

  34. What if this fails? • Stack invalid? • Code segment invalid? • IDT entry not present? Causes “ Double Fault ”(#8). “Triple fault” = Reboot Usually DF means OS bug, so a lot of state might be corrupted (i.e. invalid kernel stack) Sunday, February 17, 13

  35. Hardware Task Switching Can use it for #PF and #DF traps instead of Trap Gates TR Sunday, February 17, 13

  36. Task gate • (unused) mechanism for hardware tasking • Reloads (nearly) all CPU state from memory • Task gate causes task switch on trap Sunday, February 17, 13

  37. IDT -> GDT ->TSS IDT It still pushes the error code (addressed indirectly through GDT) GDT Sunday, February 17, 13

  38. Brief digression Intel Manual: Sunday, February 17, 13

  39. Brief digression Intel Manual: Bypass (all) paging from the kernel? VM Escape? Wouldn’t that be nice? Sunday, February 17, 13

  40. Sunday, February 17, 13

  41. Maybe we should actually verify it.. CPU translates DWORD by DWORD Sunday, February 17, 13

  42. (CC-BY-SA)Lizzie Bitty/DevianArt Sunday, February 17, 13

  43. Look Ma, it’s a machine! Sunday, February 17, 13

  44. A one-instruction machine Instruction Format: • “Decrement-Branch-If- Label = (X <-Y,A,B) Negative” • Turing complete (!) Label: X=Y • “ “ Computer Architecture: If X<4: A Minimalist Perspective” Goto B by Gilreath and Laplathe Else (~$200) X-=4 • Or Wikipedia :) Goto A Sunday, February 17, 13

  45. Implementation sketch: • If EIP of a handler is pointed at invalid memory, we get another page fault immediately; keep EIP invalid in all tasks • Var Decrement: use TSS’ SP , pushing the stack decrements SP by 4. • Branch: <4 or not? Implement by double fault when SP cannot be decremented Sunday, February 17, 13

  46. Dramatis Personae I • One GDT to rule them all • One TSS Descriptor per instruction, aligned with the end of a page • IDT is mapped differently, per instruction • A target (branch-not-taken) in Int 14, #PF • B target (branch taken) in Int 8, #DF Sunday, February 17, 13

  47. Dramatis Personae II • Higher half of TSS (variables) • Map A.Y, B.Y (the value we want to load for next instruction) at their TSS addresses • map X (the value we want to write) at the addr of the current task • So we have the move and decrement Sunday, February 17, 13

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend