sysprog3 Part2
Click here to load reader
-
Upload
ahmed-mekkawy -
Category
Technology
-
view
527 -
download
1
description
Transcript of sysprog3 Part2
![Page 1: sysprog3 Part2](https://reader038.fdocuments.net/reader038/viewer/2022100603/5593f8681a28ab9b088b466c/html5/thumbnails/1.jpg)
C for Linux
Session 3
BY:Eng.Ahmed Teirelbar
Software EngineerShuja' Consulting
![Page 2: sysprog3 Part2](https://reader038.fdocuments.net/reader038/viewer/2022100603/5593f8681a28ab9b088b466c/html5/thumbnails/2.jpg)
gdb Basics
● -g● In execution
● run● continue● step● breakpoint● variables● directives● execute code
![Page 3: sysprog3 Part2](https://reader038.fdocuments.net/reader038/viewer/2022100603/5593f8681a28ab9b088b466c/html5/thumbnails/3.jpg)
Pointer Concepts
● An array is a pointer to the first element● Pointer subscript access● Scope issues – Back to the stack picture● NULL pointer
![Page 4: sysprog3 Part2](https://reader038.fdocuments.net/reader038/viewer/2022100603/5593f8681a28ab9b088b466c/html5/thumbnails/4.jpg)
Pointers
● SEGV ● Memory overwrites – “but it worked before!!!”● null termination issues● Core dump
![Page 5: sysprog3 Part2](https://reader038.fdocuments.net/reader038/viewer/2022100603/5593f8681a28ab9b088b466c/html5/thumbnails/5.jpg)
Debugging and Detection
● More gdb ● dumping memory● Casting● Watchpoints
● Detection● Sanity checks● Macros with sizeof● Magic numbers in Structures
![Page 6: sysprog3 Part2](https://reader038.fdocuments.net/reader038/viewer/2022100603/5593f8681a28ab9b088b466c/html5/thumbnails/6.jpg)
Allocation and Memory
● The Heap data structure
● Back to the process picture
● Very brief overview of system memory allocation● brk()● Granularity & page size● Allocation algorithms● Block data● Alignment● Swapping
![Page 7: sysprog3 Part2](https://reader038.fdocuments.net/reader038/viewer/2022100603/5593f8681a28ab9b088b466c/html5/thumbnails/7.jpg)
Memory Leaks
● What is it?● Why do we care? what is the OOM killer?● Detection
● Your own code, macros● top and /proc/meminfo● Valgrind and profiling ● http://valgrind.org/● http://www.advancedlinuxprogramming.com/ (Appendix A.2)
![Page 8: sysprog3 Part2](https://reader038.fdocuments.net/reader038/viewer/2022100603/5593f8681a28ab9b088b466c/html5/thumbnails/8.jpg)
Structures/Unions in Memory
● Alignment● Sizeof struct, union, pointer
● Casting● Traversals of pointers
![Page 9: sysprog3 Part2](https://reader038.fdocuments.net/reader038/viewer/2022100603/5593f8681a28ab9b088b466c/html5/thumbnails/9.jpg)
Functions & the Stack● Overview
● Base offset/Frame pointer● RET● Local variables
● objdump
● gdb & stack trace● where● up/down● Huge for core dumps
● Recursion & your stack
![Page 10: sysprog3 Part2](https://reader038.fdocuments.net/reader038/viewer/2022100603/5593f8681a28ab9b088b466c/html5/thumbnails/10.jpg)
The Infamous Stack Overflow Attack
● Overview of Concept● How it works?
● The vulnerability● Integrate the whole stack picture● How you place the exploiting code –high level
● How do you protect against it?● Heap overflow
![Page 11: sysprog3 Part2](https://reader038.fdocuments.net/reader038/viewer/2022100603/5593f8681a28ab9b088b466c/html5/thumbnails/11.jpg)
Structures w/Functions:
● Higher level of operation● Object and Interface
● Modularity of a defined interface● Easier implementation per piece● Unit test● Module-level behavioral Changes
Data Abstraction
![Page 12: sysprog3 Part2](https://reader038.fdocuments.net/reader038/viewer/2022100603/5593f8681a28ab9b088b466c/html5/thumbnails/12.jpg)
Data Abstraction Cont'd
● Data Hiding● Extension of type● Type-level behavioral changes (decoupling)
● Can be taken too far – be sensible