Instructions for test_function

Slides:



Advertisements
Similar presentations
Calling sequence ESP.
Advertisements

Run-time Environment for a Program different logical parts of a program during execution stack – automatically allocated variables (local variables, subdivided.
Ch. 8 Functions.
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
The art of exploitation
Functions Functions and Parameters. History A function call needs to save the registers in use The called function will use the registers The registers.
 Procedures (subroutines) allow the programmer to structure programs making them : › easier to understand and debug and › allowing code to be reused.
RECITATION - 09/20/2010 BY SSESHADR Buflab. Agenda Reminders  Bomblab should be finished up  Exam 1 is on Tuesday 09/28/2010 Stack Discipline Buflab.
Memory Image of Running Programs Executable file on disk, running program in memory, activation record, C-style and Pascal-style parameter passing.
1 Function Calls Professor Jennifer Rexford COS 217 Reading: Chapter 4 of “Programming From the Ground Up” (available online from the course Web site)
Practical Session 3. The Stack The stack is an area in memory that its purpose is to provide a space for temporary storage of addresses and data items.
Computer Programming 1 Functions. Computer Programming 2 Objectives Take a first look at building functions Study how a function is called Investigate.
Microprocessors Frame Pointers and the use of the –fomit-frame-pointer switch Feb 25th, 2002.
1. 2 FUNCTION INLINE FUNCTION DIFFERENCE BETWEEN FUNCTION AND INLINE FUNCTION CONCLUSION 3.
September 22, 2014 Pengju (Jimmy) Jin Section E
Stacks and Frames Demystified CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
CMSC 414 Computer and Network Security Lecture 20 Jonathan Katz.
University of Washington CSE 351 : The Hardware/Software Interface Section 5 Structs as parameters, buffer overflows, and lab 3.
ESP int f(int x) {.... } int g(int y) { …. f(2); …. } int main() { …. g(1); …. } EIP 100: 200: 250: 300: 350:
Universal Concepts of Programming Creating and Initializing local variables on the stack Variable Scope and Lifetime Stack Parameters Stack Frames Passing.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2011.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 7 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Programmer's view on Computer Architecture by Istvan Haller.
Today’s topics Parameter passing on the system stack Parameter passing on the system stack Register indirect and base-indexed addressing modes Register.
Practical Session 4. Labels Definition - advanced label: (pseudo) instruction operands ; comment valid characters in labels are: letters, numbers, _,
Functions and Procedures. Function or Procedure u A separate piece of code u Possibly separately compiled u Located at some address in the memory used.
ITEC 352 Lecture 18 Functions in Assembly. Functions + Assembly Review Questions? Project due on Friday Exam –Average 76 Methods for functions in assembly.
CPSC 388 – Compiler Design and Construction Runtime Environments.
Lecture 18: 11/5/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Lecture 19: 11/7/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
What is exactly Exploit writing?  Writing a piece of code which is capable of exploit the vulnerability in the target software.
Low Level Programming Lecturer: Duncan Smeed The Interface Between High-Level and Low-Level Languages.
CS 155 Section 1 PP1 Eu-Jin Goh. Setting up Environment Demo.
Compiler Construction Code Generation Activation Records
CS415 Project 1: Understanding Setjmp/Longjmp Manpreet Singh
1 Assembly Language: Function Calls Jennifer Rexford.
Function Calling. Mips Assembly Call and Return Steps for procedure calling –Save the return address –Jump to the procedure (function) –Execute the procedure.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2014.
Gnu Debugger (GDB) Topics Overview Quick Reference Card Readings: Quick Reference Card February 4, 2010 CSCE 212Honors Computer Organization.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
Section 5: Procedures & Stacks
Assembly function call convention
Storage Classes There are three places in memory where data may be placed: In Data section declared with .data in assembly language in C - Static) On the.
C function call conventions and the stack
Computer Architecture and Assembly Language
Anton Burtsev February, 2017
143A: Principles of Operating Systems Lecture 4: Calling conventions
Functions and Procedures
Stack Frames and Advanced Procedures
More examples How many processes does this piece of code create?
Procedures – Overview Lecture 19 Mon, Mar 28, 2005.
Assembly Language Programming II: C Compiler Calling Sequences
Understanding Program Address Space
EECE.3170 Microprocessor Systems Design I
Practical Session 4.
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2015.
CNT4704: Analysis of Computer Communication Network Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Fall 2011.
EECE.3170 Microprocessor Systems Design I
C (and C++) Pointers April 4, 2019.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2016.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2013.
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2010.
Computer Architecture and System Programming Laboratory
Topic 2b ISA Support for High-Level Languages
Return-to-libc Attacks
By Hugues Leger / Intro to GDB debugger By Hugues Leger / 11/16/2019.
Presentation transcript:

Instructions for test_function Text Segment Source Code void test_function(int a) { int flag = a*a; } int main( ) int num = 8; test_function(num); Instructions for test_function gcc, gdb Instructions for main ~ ~ Source code is compiled with gcc to produce object code. Using gdb, we run the program in debug mode. The instructions for the program are loaded into the text segment of memory.

Instructions for test_function Text Segment Source Code void test_function(int a) { int flag = a*a; } int main( ) int num = 8; test_function(num); Instructions for test_function Instructions for main eip ~ ~ ~ ~ Stack Registers The program execution starts at the first line of the main function. A portion of memory is set aside as the stack; currently there is only one stack frame (i.e. the stack frame for main) which comprises the entire stack. The base pointer ebp points directly beneath the stack, and the stack pointer esp points at the top of the stack. The instruction pointer eip points to the next instruction (in the text segment) that will be executed. Recall that ebp, esp, and eip are all registers; they are saved in the CPU, and they each hold the address that they are currently pointing to. esp Stack frame for main ebp

Instructions for test_function Text Segment Source Code void test_function(int a) { int flag = a*a; } int main( ) int num = 8; test_function(num); Instructions for test_function Instructions for main eip ~ ~ ~ ~ Stack Registers The main variable num is declared and initialized, which causes it to be loaded onto the stack. esp Stack frame for main ebp

Instructions for test_function Text Segment Source Code void test_function(int a) { int flag = a*a; } int main( ) int num = 8; test_function(num); Instructions for test_function Instructions for main eip ~ ~ ~ ~ Note: this is the address we want to return to after the function call (i.e. the return address) Stack esp ebp Stack frame for main Registers In preparation for the function call, the argument (i.e. the value of num, which is 8) is placed on the function stack. We also note the return address that eip should come back to after the function call.

~ ~ ~ ~ Text Segment Source Code eip Stack esp ebp Registers void test_function(int a) { int flag = a*a; } int main( ) int num = 8; test_function(num); eip Instructions for test_function Instructions for main ~ ~ ~ ~ Stack esp Stack frame for test_function ebp Registers At the beginning of the function call, several things happen. The instruction pointer eip will jump to the next address to be executed in the test_function portion of the text segment of memory. The stack frame for main is expanded by eight bytes, so that it can accommodate the return address (noted in the last slide) and old value of ebp (which will be used to reconstruct the stack after the function call). These are saved at the top of the (expanded) stack frame for main. Finally, a new stack frame is designated for test_function, above the stack frame for main. Stack frame for main

~ ~ ~ ~ Text Segment Source Code eip Stack esp ebp Registers void test_function(int a) { int flag = a*a; } int main( ) int num = 8; test_function(num); Instructions for test_function eip Instructions for main ~ ~ ~ ~ Stack esp ebp Stack frame for main Stack frame for test_function Registers In test_function, the local (i.e. function) variable flag is declared and initialized to be a*a. Since the parameter a is equal to the value of the argument (8), flag will be set to 64 (or 0x40 in hex). This is loaded into the stack frame for test_function.

Instructions for test_function Text Segment Source Code void test_function(int a) { int flag = a*a; } int main( ) int num = 8; test_function(num); Instructions for test_function Instructions for main eip ~ ~ ~ ~ Stack Registers With the function call completed, eip jumps back to the return address, and esp and ebp are moved back to their original positions to mark out the stack frame for main. The contents of the memory previously used to store flag, return_address, etc. is not deleted or changed, but it is no longer viewed as being part of the main stack frame (and there is no such thing as the stack frame for test_function anymore). esp Stack frame for main ebp