The K Project Jump to userland Userland Conclusion LSE Team - - PowerPoint PPT Presentation

the k project
SMART_READER_LITE
LIVE PREVIEW

The K Project Jump to userland Userland Conclusion LSE Team - - PowerPoint PPT Presentation

The K Project LSE Team Binary loading TSS The K Project Jump to userland Userland Conclusion LSE Team EPITA May 06, 2019 LSE Team (EPITA) The K Project May 06, 2019 1 / 17 Executable and Linkable Format The K Project LSE Team


slide-1
SLIDE 1

The K Project LSE Team Binary loading TSS Jump to userland Conclusion

The K Project

Userland LSE Team

EPITA

May 06, 2019

LSE Team (EPITA) The K Project May 06, 2019 1 / 17

slide-2
SLIDE 2

The K Project LSE Team Binary loading TSS Jump to userland Conclusion

Executable and Linkable Format

LSE Team (EPITA) The K Project May 06, 2019 2 / 17

slide-3
SLIDE 3

The K Project LSE Team Binary loading TSS Jump to userland Conclusion

Sections

.text: program code .rodata: readonly data (ex: Constant strings) .data: global data .bss: unitialized data .symtab: symbols table .init: executable code for the initialization of the program .fini: executable code for the program termination

LSE Team (EPITA) The K Project May 06, 2019 3 / 17

slide-4
SLIDE 4

The K Project LSE Team Binary loading TSS Jump to userland Conclusion

Segments and Sections

LSE Team (EPITA) The K Project May 06, 2019 4 / 17

slide-5
SLIDE 5

The K Project LSE Team Binary loading TSS Jump to userland Conclusion

Binary Loader

LSE Team (EPITA) The K Project May 06, 2019 5 / 17

slide-6
SLIDE 6

The K Project LSE Team Binary loading TSS Jump to userland Conclusion

Getting Elf program headers

Program headers can be found directly from Elf header with these fields:

e phoff: offset to program header structure array e phentsize: program header structure size in array e phnum: number of program header structures in array

LSE Team (EPITA) The K Project May 06, 2019 6 / 17

slide-7
SLIDE 7

The K Project LSE Team Binary loading TSS Jump to userland Conclusion

Elf program headers information

Program header structure then contains the following informations:

p type: program header type p flags: memory flags associated with program header p vaddr: expected virtual memory address of program header p off: program header offset in Elf p memsz: in memory size of program header p filesz: in file size of program header. It can differ from p memsz, then the remaining part must be filled with 0

LSE Team (EPITA) The K Project May 06, 2019 7 / 17

slide-8
SLIDE 8

The K Project LSE Team Binary loading TSS Jump to userland Conclusion

Memory layout

memory reserved address

User Code User Data User Stack User Head Kernel Code/Data

User Data Segment rw- User Code Segment r-x

phdr .p_memsz + phdr .p_vaddr brk 0xFFFFFFFFFF 0x00000000

LSE Team (EPITA) The K Project May 06, 2019 8 / 17

slide-9
SLIDE 9

The K Project LSE Team Binary loading TSS Jump to userland Conclusion

Events in userland

CS Error Code EFLAGS CS EIP ESP After Transfer to Handler Error Code ESP Before Transfer to Handler EFLAGS EIP SS ESP Stack Usage with No Privilege-Level Change Stack Usage with Privilege-Level Change Interrupted Procedure’s Interrupted Procedure’s and Handler’s Stack Handler’s Stack ESP After Transfer to Handler Transfer to Handler ESP Before Stack

LSE Team (EPITA) The K Project May 06, 2019 9 / 17

slide-10
SLIDE 10

The K Project LSE Team Binary loading TSS Jump to userland Conclusion

TSS

31 100 96 92 88 84 80 76 I/O Map Base Address 15 LDT Segment Selector GS FS DS SS CS 72 68 64 60 56 52 48 44 40 36 32 28 24 20 SS2 16 12 8 4 SS1 SS0 ESP0 Previous Task Link ESP1 ESP2 CR3 (PDBR) T ES EDI ESI EBP ESP EBX EDX ECX EAX EFLAGS EIP Reserved bits. Set to 0. Reserved Reserved Reserved Reserved Reserved Reserved Reserved Reserved Reserved Reserved Reserved Reserved

LSE Team (EPITA) The K Project May 06, 2019 10 / 17

slide-11
SLIDE 11

The K Project LSE Team Binary loading TSS Jump to userland Conclusion

TSS Descriptor

31 24 23 22 21 20 19 16 15 13 14 12 11 8 7 P

Base 31:24

G D P L

Type

31 16 15

Base Address 15:00 Segment Limit 15:00 Base 23:16

A V L

Limit 19:16

1 B 1

TSS Descriptor AVL B BASE DPL G Available for use by system software Busy flag Segment Base Address Descriptor Privilege Level Granularity LIMIT P TYPE Segment Limit Segment Present Segment Type 4

LSE Team (EPITA) The K Project May 06, 2019 11 / 17

slide-12
SLIDE 12

The K Project LSE Team Binary loading TSS Jump to userland Conclusion

Load TSS

movw $0x10, %ax ltr %ax /* The second GDT entry describe the TSS */

LSE Team (EPITA) The K Project May 06, 2019 12 / 17

slide-13
SLIDE 13

The K Project LSE Team Binary loading TSS Jump to userland Conclusion

GDT requirements

GDT should then contain:

Null descriptor Kernel code segment Kernel data segment Userland code segment Userland data segment TSS

LSE Team (EPITA) The K Project May 06, 2019 13 / 17

slide-14
SLIDE 14

The K Project LSE Team Binary loading TSS Jump to userland Conclusion

Register setting to go to Userland

To jump to Userland, register values must be:

cs, ds, ss, es esp must be set to a task stack address eip must be set to program entry point

LSE Team (EPITA) The K Project May 06, 2019 14 / 17

slide-15
SLIDE 15

The K Project LSE Team Binary loading TSS Jump to userland Conclusion

Events in userland

CS Error Code EFLAGS CS EIP ESP After Transfer to Handler Error Code ESP Before Transfer to Handler EFLAGS EIP SS ESP Stack Usage with No Privilege-Level Change Stack Usage with Privilege-Level Change Interrupted Procedure’s Interrupted Procedure’s and Handler’s Stack Handler’s Stack ESP After Transfer to Handler Transfer to Handler ESP Before Stack

LSE Team (EPITA) The K Project May 06, 2019 15 / 17

slide-16
SLIDE 16

The K Project LSE Team Binary loading TSS Jump to userland Conclusion

Events in userland

Did you notice DS and ES are not on the stack ?

LSE Team (EPITA) The K Project May 06, 2019 16 / 17

slide-17
SLIDE 17

The K Project LSE Team Binary loading TSS Jump to userland Conclusion

Contact

k[at]lse.epita.fr labos.lse with [K] tag #k (irc.rezosup.org) guillaume.pagnoux[at]lse.epita.fr tom.decrette[at]lse.epita.fr

LSE Team (EPITA) The K Project May 06, 2019 17 / 17