Machine-Level Programming IV: Structured Data

Size: px
Start display at page:

Download "Machine-Level Programming IV: Structured Data"

Transcription

1 Machine-Level Programming IV: Structured Data Topics Arrays Structs

2 Basic Data Types Integral 2 Stored & operated on in general registers Signed vs. unsigned depends on instructions used Intel GAS Bytes C byte b 1 [unsigned] char word w 2 [unsigned] short double word l 4 [unsigned] int Floating Point Stored & operated on in floating point registers Intel GAS Bytes C Single s 4 float Double l 8 double Extended t 10/12 long double

3 Array Allocation Basic Principle T A[L]; Array of data type T and length L Contiguously allocated region of L * sizeof(t) bytes char string[12]; int val[5]; double a[4]; x x + 12 x x + 4 x + 8 x + 12 x + 16 x + 20 x x + 8 x + 16 x + 24 x char *p[3]; x x + 4 x + 8

4 Array Access Basic Principle T A[L]; Array of data type T and length L Identifier A can be used as a pointer to array element 0 int val[5]; Reference Type val[4] int 3 val int * x Value val+1 int * x + 4 &val[2] int * x + 8 val[5] int?? *(val+1) int 5 x x + 4 x + 8 x + 12 x + 16 x + 20 val + i int * x + 4 i

5 Array Example typedef int zip_dig[5]; zip_dig cmu = { 1, 5, 2, 1, 3 }; zip_dig mit = { 0, 2, 1, 3, 9 }; zip_dig ucb = { 9, 4, 7, 2, 0 }; 5 Notes zip_dig cmu; zip_dig mit; zip_dig ucb; Declaration zip_dig cmu equivalent to int cmu[5] Example arrays were allocated in successive 20 byte blocks Not guaranteed to happen in general

6 Array Accessing Example Computation Register %edx contains starting address of array Register %eax contains array index Desired digit at 4*%eax + %edx Use memory reference (%edx,%eax,4) int get_digit (zip_dig z, int dig) { return z[dig]; } Memory Reference Code # %edx = z # %eax = dig movl (%edx,%eax,4),%eax # z[dig] 6

7 7 Referencing Examples zip_dig cmu; zip_dig mit; zip_dig ucb; Code Does Not Do Any Bounds Checking! Reference Address mit[3] * 3 = 48 3 mit[5] * 5 = 56 9 mit[-1] *-1 = 32 3 cmu[15] *15 = 76?? Value Out of range behavior implementation-dependent No guaranteed relative allocation of different arrays Guaranteed? Yes No No No

8 Array Loop Example Original Source Transformed Version 8 As generated by GCC Eliminate loop variable i Convert array code to pointer code Express in do-while form No need to test at entrance int zd2int(zip_dig z) { int i; int zi = 0; for (i = 0; i < 5; i++) { zi = 10 * zi + z[i]; } return zi; } int zd2int(zip_dig z) { int zi = 0; int *zend = z + 4; do { zi = 10 * zi + *z; z++; } while(z <= zend); return zi; }

9 Array Loop Implementation Registers 9 %ecx %eax %ebx z zi zend Computations 10*zi + *z implemented as *z + 2*(zi+4*zi) z++ increments by 4 int zd2int(zip_dig z) { int zi = 0; int *zend = z + 4; do { zi = 10 * zi + *z; z++; } while(z <= zend); return zi; } # %ecx = z xorl %eax,%eax # zi = 0 leal 16(%ecx),%ebx # zend = z+4.l59: leal (%eax,%eax,4),%edx # 5*zi movl (%ecx),%eax # *z addl $4,%ecx # z++ leal (%eax,%edx,2),%eax # zi = *z + 2*(5*zi) cmpl %ebx,%ecx # z : zend jle.l59 # if <= goto loop

10 Structures Concept Contiguously-allocated region of memory Refer to members within structure by names Members may be of different types struct rec { int i; int a[3]; int *p; }; Memory Layout i a p Accessing Structure Member void set_i(struct rec *r, int val) { r->i = val; } Assembly # %eax = val # %edx = r movl %eax,(%edx) # Mem[r] = val 10

11 Generating Pointer to Struct. Member struct rec { int i; int a[3]; int *p; }; r i a p r *idx Generating Pointer to Array Element Offset of each structure member determined at compile time int * find_a (struct rec *r, int idx) { return &r->a[idx]; } # %ecx = idx # %edx = r leal 0(,%ecx,4),%eax # 4*idx leal 4(%eax,%edx),%eax # r+4*idx+4 11

12 Structure Referencing (Cont.) C Code struct rec { int i; int a[3]; int *p; }; void set_p(struct rec *r) { r->p = &r->a[r->i]; } i a p i a Element i # %edx = r movl (%edx),%ecx # r->i leal 0(,%ecx,4),%eax # 4*(r->i) leal 4(%edx,%eax),%eax # r+4+4*(r->i) movl %eax,16(%edx) # Update r->p 12

13 Alignment Aligned Data 13 Primitive data type requires K bytes Address must be multiple of K Required on some machines; advised on IA32 treated differently by Linux and Windows! Motivation for Aligning Data Memory accessed by (aligned) double or quad-words Compiler Inefficient to load or store datum that spans quad word boundaries Virtual memory very tricky when datum spans 2 pages Inserts gaps in structure to ensure correct alignment of fields

14 Specific Cases of Alignment Size of Primitive Data Type: 14 1 byte (e.g., char) no restrictions on address 2 bytes (e.g., short) lowest 1 bit of address must be bytes (e.g., int, float, char *, etc.) lowest 2 bits of address must be bytes (e.g., double) Windows (and most other OS s & instruction sets):» lowest 3 bits of address must be Linux:» lowest 2 bits of address must be 00 2» i.e., treated the same as a 4-byte primitive data type 12 bytes (long double) Linux:» lowest 2 bits of address must be 00 2» i.e., treated the same as a 4-byte primitive data type

15 Satisfying Alignment with Structures Offsets Within Structure Must satisfy element s alignment requirement Overall Structure Placement Each structure has alignment requirement K Largest alignment of any element Initial address & structure length must be multiples of K struct S1 { char c; int i[2]; double v; } *p; Example (under Windows): K = 8, due to double element c i[0] i[1] v p+0 p+4 p+8 p+16 p Multiple of 4 Multiple of 8 Multiple of 8 Multiple of 8

16 Linux vs. Windows Windows (including Cygwin): K = 8, due to double element struct S1 { char c; int i[2]; double v; } *p; Linux: c i[0] i[1] v p+0 p+4 p+8 p+16 p+24 Multiple of 4 Multiple of 8 Multiple of 8 Multiple of 8 K = 4; double treated like a 4-byte data type c i[0] i[1] p+0 p+4 p+8 v p+12 p Multiple of 4 Multiple of 4 Multiple of 4 Multiple of 4

17 Overall Alignment Requirement struct S2 { double x; int i[2]; char c; } *p; p must be multiple of: 8 for Windows 4 for Linux x i[0] i[1] c p+0 p+8 p+12 p+16 Windows: p+24 Linux: p+20 struct S3 { float x[2]; int i[2]; char c; p must be multiple of 4 (in either OS) } *p; x[0] x[1] i[0] i[1] c p+0 p+4 p+8 p+12 p+16 p+20 17

18 Ordering Elements Within Structure struct S4 { char c1; double v; char c2; int i; } *p; 10 bytes wasted space in Windows c1 v p+0 p+8 p+16 p+20 p+24 c2 i struct S5 { double v; char c1; char c2; int i; } *p; 2 bytes wasted space v c1 c2 p+0 p+8 p+12 p+16 i 18

19 Arrays of Structures Principle Allocated by repeating allocation for array type In general, may nest arrays & structures to arbitrary depth struct S6 { short i; float v; short j; } a[10]; a[1].i a[1].v a[1].j a+12 a+16 a+20 a+24 a[0] a[1] a[2] a+0 a+12 a+24 a+36 19

20 Satisfying Alignment within Structure Achieving Alignment Starting address of structure array must be multiple of worst-case alignment for any element a must be multiple of 4 Offset of element within structure must be multiple of element s alignment requirement v s offset of 4 is a multiple of 4 Overall size of structure must be multiple of worst-case alignment for any element Structure padded with unused space to be 12 bytes a+0 a[0] struct S6 { short i; float v; short j; } a[10]; a[i] a+12i Multiple of 4 a[1].i a+12i a+12i+4 a[1].v a[1].j 20 Multiple of 4

21 Summary Arrays in C Contiguous allocation of memory Pointer to first element No bounds checking Compiler Optimizations Compiler often turns array code into pointer code (zd2int) Uses addressing modes to scale array indices Structures Allocate bytes in order declared Pad in middle and at end to satisfy alignment 21

22 Machine-Level Programming V: Miscellaneous Topics Topics Linux Memory Layout Understanding Pointers Buffer Overflow Floating Point Code 22

23 Upper 2 hex digits of address 23 FF C0 BF 80 7F Red Hat v. 6.2 ~1920MB memory limit 40 3F Stack Heap DLLs Heap Data Text Stack Heap DLLs Data Text Linux Memory Layout Runtime stack (8MB limit) Dynamically allocated storage When call malloc, calloc, new Dynamically Linked Libraries Library routines (e.g., printf, malloc) Linked into object code when first executed Statically allocated data E.g., arrays & strings declared in code Executable machine instructions Read-only

24 BF Linux Memory Allocation Initially Stack BF Linked Stack BF Some Heap Stack BF More Heap Stack 80 7F 80 7F 80 7F 80 7F Heap Heap 40 3F 40 3F DLLs 40 3F DLLs 40 3F DLLs Data Text Data Text Data Text Heap Data Text

25 C operators Operators Associativity () [] ->. left to right! ~ * & (type) sizeof right to left * / % left to right + - left to right << >> left to right < <= > >= left to right ==!= left to right & left to right ^ left to right left to right && left to right left to right?: right to left = += -= *= /= %= &= ^=!= <<= >>= right to left, left to right Note: Unary +, -, and * have higher precedence than binary forms 25

26 C pointer declarations int *p int *p[13] int *(p[13]) int **p int (*p)[13] int *f() int (*f)() int (*(*f())[13])() int (*(*x[3])())[5] 26 p is a pointer to int p is an array[13] of pointer to int p is an array[13] of pointer to int p is a pointer to a pointer to an int p is a pointer to an array[13] of int f is a function returning a pointer to int f is a pointer to a function returning int f is a function returning ptr to an array[13] of pointers to functions returning int x is an array[3] of pointers to functions returning pointers to array[5] of ints

27 Internet Worm and IM War November, 1988 Internet Worm attacks thousands of Internet hosts. How did it happen? July, 1999 Microsoft launches MSN Messenger (instant messaging system). Messenger clients can access popular AOL Instant Messaging Service (AIM) servers AIM client MSN server MSN client AIM server 27 AIM client

28 Internet Worm and IM War (cont.) August 1999 Mysteriously, Messenger clients can no longer access AIM servers. Microsoft and AOL begin the IM war: AOL changes server to disallow Messenger clients Microsoft makes changes to clients to defeat AOL changes. At least 13 such skirmishes. How did it happen? The Internet Worm and AOL/Microsoft War were both based on stack buffer overflow exploits! many Unix functions do not check argument sizes. allows target buffers to overflow. 28

29 String Library Code 29 Implementation of Unix function gets No way to specify limit on number of characters to read Similar problems with other Unix functions /* Get string from stdin */ char *gets(char *dest) { int c = getc(); char *p = dest; while (c!= EOF && c!= '\n') { *p++ = c; c = getc(); } *p = '\0'; return dest; } strcpy: Copies string of arbitrary length scanf, fscanf, sscanf, when given %s conversion specification

30 Vulnerable Buffer Code /* Echo Line */ void echo() { char buf[4]; /* Way too small! */ gets(buf); puts(buf); } int main() { printf("type a string:"); echo(); return 0; } 30

31 Buffer Overflow Executions unix>./bufdemo Type a string: unix>./bufdemo Type a string:12345 Segmentation Fault unix>./bufdemo Type a string: Segmentation Fault 31

32 Buffer Overflow Stack Stack Frame for main Return Address Saved %ebp [3][2][1][0] buf %ebp /* Echo Line */ void echo() { char buf[4]; /* Way too small! */ gets(buf); puts(buf); } 32 Stack Frame for echo echo: pushl %ebp movl %esp,%ebp subl $20,%esp pushl %ebx addl $-12,%esp leal -4(%ebp),%ebx pushl %ebx call gets... # Save %ebp on stack # Allocate space on stack # Save %ebx # Allocate space on stack # Compute buf as %ebp-4 # Push buf on stack # Call gets

33 Buffer Overflow Stack Example unix> gdb bufdemo (gdb) break echo Breakpoint 1 at 0x (gdb) run Breakpoint 1, 0x in echo () (gdb) print /x *(unsigned *)$ebp $1 = 0xbffff8f8 (gdb) print /x *((unsigned *)$ebp + 1) $3 = 0x804864d Stack Frame for main Stack Frame for main Before call to gets Return Address Saved %ebp [3][2][1][0] buf %ebp Return Address 86 4d bfsaved ff %ebpf8 0xbffff8d8 [3][2][1][0] xx xx xx xx buf Stack Frame for echo Stack Frame for echo : call c <echo> d: mov 0xffffffe8(%ebp),%ebx # Return Point

34 Buffer Overflow Example #1 Before Call to gets Input = 123 Stack Frame for main Stack Frame for main Return Address Saved %ebp [3][2][1][0] buf %ebp Return Address 86 4d bfsaved ff %ebpf8 0xbffff8d8 [3][2][1][0] buf Stack Frame for echo Stack Frame for echo No Problem 34

35 Buffer Overflow Stack Example #2 Stack Frame for main Stack Frame for main Input = Return Address Saved %ebp [3][2][1][0] buf Stack Frame for echo echo code: %ebp Return Address 86 4d bfsaved ff 00 %ebp35 0xbffff8d8 [3][2][1][0] buf Stack Frame for echo Saved value of %ebp set to 0xbfff0035 Bad news when later attempt to restore %ebp : push %ebx : call 80483e4 <_init+0x50> # gets : mov 0xffffffe8(%ebp),%ebx b: mov %ebp,%esp d: pop %ebp # %ebp gets set to invalid value e: ret 35

36 Buffer Overflow Stack Example #3 Stack Frame for main Stack Frame for main Input = Return Address Saved %ebp [3][2][1][0] buf %ebp Return Address Saved %ebp35 0xbffff8d8 [3][2][1][0] buf Stack Frame for echo Stack Frame for echo Invalid address %ebp and return address corrupted No longer pointing to desired return point : call c <echo> d: mov 0xffffffe8(%ebp),%ebx # Return Point 36

37 Malicious Use of Buffer Overflow Stack after call to gets() return address A void foo(){ bar();... } void bar() { char buf[64]; gets(buf);... } data written by gets() B B pad exploit code foo stack frame bar stack frame 37 Input string contains byte representation of executable code Overwrite return address with address of buffer When bar() executes ret, will jump to exploit code

38 Exploits Based on Buffer Overflows Buffer overflow bugs allow remote machines to execute arbitrary code on victim machines. Internet worm Early versions of the finger server (fingerd) used gets() to read the argument sent by the client: finger Worm attacked fingerd server by sending phony argument: finger exploit-code padding new-return-address exploit code: executed a root shell on the victim machine with a direct TCP connection to the attacker. 38

39 Exploits Based on Buffer Overflows Buffer overflow bugs allow remote machines to execute arbitrary code on victim machines. IM War AOL exploited existing buffer overflow bug in AIM clients exploit code: returned 4-byte signature (the bytes at some location in the AIM client) to server. When Microsoft changed code to match signature, AOL changed signature location. 39

40 Date: Wed, 11 Aug :30: (PDT) From: Phil Bucking Subject: AOL exploiting buffer overrun bug in their own software! To: Mr. Smith, I am writing you because I have discovered something that I think k you might find interesting because you are an Internet security expert with experience in this area. I have also tried to contact AOL but received no response. I am a developer who has been working on a revolutionary new instant messaging client that should be released later this year.... It appears that the AIM client has a buffer overrun bug. By itself this might not be the end of the world, as MS surely has had its share. But AOL is now *exploiting their own buffer overrun bug* to help in its efforts to block MS Instant Messenger.... Since you have significant credibility with the press I hope that t you can use this information to help inform people that behind AOL's friendly exterior they are nefariously compromising peoples' security. Sincerely, Phil Bucking Founder, Bucking Consulting philbucking@yahoo.com It was later determined that this originated from within Microsoft! 40

41 Code Red Worm History June 18, Microsoft announces buffer overflow vulnerability in IIS Internet server July 19, over 250,000 machines infected by new virus in 9 hours White house must change its IP address. Pentagon shut down public WWW servers for day When We Set Up CS:APP Web Site Received strings of form GET /default.ida?nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn...nnnn NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN%u9090%u6858%ucbd3%u780 1%u9090%u6858%ucbd3%u7801%u9090%u6858%ucbd3%u7801%u9090%u909 0%u8190%u00c3%u0003%u8b00%u531b%u53ff%u0078%u0000%u00=a HTTP/1.0" "-" "-" 41

42 Code Red Exploit Code Starts 100 threads running Spread self Generate random IP addresses & send attack string Between 1st & 19th of month Attack Send 98,304 packets; sleep for 4-1/2 hours; repeat» Denial of service attack Between 21st & 27th of month Deface server s home page After waiting 2 hours 42

43 Code Red Effects Later Version Even More Malicious Code Red II As of April, 2002, over 18,000 machines infected Still spreading Paved Way for NIMDA Variety of propagation methods One was to exploit vulnerabilities left behind by Code Red II 43

44 Avoiding Overflow Vulnerability /* Echo Line */ void echo() { char buf[4]; /* Way too small! */ fgets(buf, 4, stdin); puts(buf); } Use Library Routines that Limit String Lengths fgets instead of gets strncpy instead of strcpy Don t use scanf with %s conversion specification Use fgets to read the string 44

45 IA32 Floating Point History 8086: first computer to implement IEEE FP separate 8087 FPU (floating point unit) 486: merged FPU and Integer Unit onto one chip Summary Hardware to add, multiply, and divide Floating point data registers Various control & status registers Integer Unit Instruction decoder and sequencer FPU Floating Point Formats 45 single precision (C float): 32 bits double precision (C double): 64 bits extended precision (C long double): 80 bits Memory

46 FPU Data Register Stack FPU register format (extended precision) s exp frac 0 FPU registers 8 registers Logically forms shallow stack Top called %st(0) When push too many, bottom values disappear Top %st(3) %st(2) %st(1) %st(0) stack grows down 46

47 FPU instructions Large number of floating point instructions and formats ~50 basic instruction types load, store, add, multiply sin, cos, tan, arctan, and log! Sample instructions: Instruction Effect Description fldz push 0.0 Load zero flds Addr push M[Addr] Load single precision real fmuls Addr %st(0) <- %st(0)*m[addr] Multiply faddp %st(1) <- %st(0)+%st(1); pop Add and pop 47

48 Floating Point Code Example Compute Inner Product of Two Vectors 48 Single precision arithmetic Common computation float ipf (float x[], float y[], int n) { int i; float result = 0.0; } for (i = 0; i < n; i++) { result += x[i] * y[i]; } return result; pushl %ebp movl %esp,%ebp pushl %ebx # setup movl 8(%ebp),%ebx # %ebx=&x movl 12(%ebp),%ecx # %ecx=&y movl 16(%ebp),%edx # %edx=n fldz # push +0.0 xorl %eax,%eax # i=0 cmpl %edx,%eax # if i>=n done jge.l3.l5: flds (%ebx,%eax,4) # push x[i] fmuls (%ecx,%eax,4) # st(0)*=y[i] faddp # st(1)+=st(0); pop incl %eax # i++ cmpl %edx,%eax # if i<n repeat jl.l5.l3: movl -4(%ebp),%ebx # finish movl %ebp, %esp popl %ebp ret # st(0) = result

49 Inner Product Stack Trace Initialization 1. fldz 0.0 %st(0) Iteration 0 Iteration 1 2. flds (%ebx,%eax,4) 0.0 %st(1) x[0] %st(0) 3. fmuls (%ecx,%eax,4) 0.0 %st(1) x[0]*y[0] %st(0) 5. flds (%ebx,%eax,4) x[0]*y[0] x[1] 6. fmuls (%ecx,%eax,4) x[0]*y[0] x[1]*y[1] %st(1) %st(0) %st(1) %st(0) faddp 0.0+x[0]*y[0] %st(0) 7. faddp x[0]*y[0]+x[1]*y[1] %st(0)

50 Final Observations Memory Layout OS/machine dependent (including kernel version) Basic partitioning: stack/data/text/heap/dll found in most machines Type Declarations in C Notation obscure, but very systematic Working with Strange Code Important to analyze nonstandard cases E.g., what happens when stack corrupted due to buffer overflow Helps to step through with GDB IA32 Floating Point Strange shallow stack architecture 50

Machine-Level Programming V: Miscellaneous Topics Sept. 24, 2002

Machine-Level Programming V: Miscellaneous Topics Sept. 24, 2002 15-213 The course that gives CMU its Zip! Machine-Level Programming V: Miscellaneous Topics Sept. 24, 2002 Topics Linux Memory Layout Understanding Pointers Buffer Overflow Floating Point Code class09.ppt

More information

Linux Memory Layout The course that gives CMU its Zip! Machine-Level Programming IV: Miscellaneous Topics Sept. 24, Text & Stack Example

Linux Memory Layout The course that gives CMU its Zip! Machine-Level Programming IV: Miscellaneous Topics Sept. 24, Text & Stack Example Machine-Level Programming IV: Miscellaneous Topics Sept. 24, 22 class09.ppt 15-213 The course that gives CMU its Zip! Topics Linux Memory Layout Understanding Pointers Buffer Overflow Floating Point Code

More information

Giving credit where credit is due

Giving credit where credit is due JDEP 284H Foundations of Computer Systems Machine-Level Programming V: Wrap-up Dr. Steve Goddard goddard@cse.unl.edu Giving credit where credit is due Most of slides for this lecture are based on slides

More information

Linux Memory Layout. Lecture 6B Machine-Level Programming V: Miscellaneous Topics. Linux Memory Allocation. Text & Stack Example. Topics.

Linux Memory Layout. Lecture 6B Machine-Level Programming V: Miscellaneous Topics. Linux Memory Allocation. Text & Stack Example. Topics. Lecture 6B Machine-Level Programming V: Miscellaneous Topics Topics Linux Memory Layout Understanding Pointers Buffer Overflow Upper 2 hex digits of address Red Hat v. 6.2 ~1920MB memory limit FF C0 Used

More information

Buffer Overflow. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Buffer Overflow. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Buffer Overflow Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu IA-32/Linux Memory Layout Runtime stack (8MB limit) Heap Dynamically allocated storage

More information

BUFFER OVERFLOW. Jo, Heeseung

BUFFER OVERFLOW. Jo, Heeseung BUFFER OVERFLOW Jo, Heeseung IA-32/LINUX MEMORY LAYOUT Heap Runtime stack (8MB limit) Dynamically allocated storage When call malloc(), calloc(), new() DLLs (shared libraries) Data Text Dynamically linked

More information

Buffer Overflow. Jo, Heeseung

Buffer Overflow. Jo, Heeseung Buffer Overflow Jo, Heeseung IA-32/Linux Memory Layout Heap Runtime stack (8MB limit) Dynamically allocated storage When call malloc(), calloc(), new() DLLs (shared libraries) Data Text Dynamically linked

More information

Sungkyunkwan University

Sungkyunkwan University November, 1988 Internet Worm attacks thousands of Internet hosts. How did it happen? November, 1988 Internet Worm attacks thousands of Internet hosts. How did it happen? July, 1999 Microsoft launches MSN

More information

Assembly IV: Complex Data Types. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Assembly IV: Complex Data Types. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University ssembly IV: Complex Data Types Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Basic Data Types Integer Stored & operated on in general registers

More information

Referencing Examples

Referencing Examples Referencing Examples zip_dig cmu; 1 5 2 1 3 16 20 24 28 32 36 zip_dig mit; 0 2 1 3 9 36 40 44 48 52 56 zip_dig nwu; 6 0 2 0 1 56 60 64 68 72 76 Code Does Not Do ny Bounds Checking! Reference ddress Value

More information

Buffer Overflows. Buffer Overflow. Many of the following slides are based on those from

Buffer Overflows. Buffer Overflow. Many of the following slides are based on those from s Many of the following slides are based on those from 1 Complete Powerpoint Lecture Notes for Computer Systems: A Programmer's Perspective (CS:APP) Randal E. Bryant and David R. O'Hallaron http://csapp.cs.cmu.edu/public/lectures.html

More information

Introduction to Computer Systems , fall th Lecture, Sep. 28 th

Introduction to Computer Systems , fall th Lecture, Sep. 28 th Introduction to Computer Systems 15 213, fall 2009 9 th Lecture, Sep. 28 th Instructors: Majd Sakr and Khaled Harras Last Time: Structures struct rec { int i; int a[3]; int *p; }; Memory Layout i a p 0

More information

Machine-Level Prog. V Miscellaneous Topics

Machine-Level Prog. V Miscellaneous Topics Machine-Level Prog. V Miscellaneous Topics Today Buffer overflow Extending IA32 to 64 bits Next time Memory Fabián E. Bustamante, Spring 2010 Internet worm and IM war November, 1988 Internet Worm attacks

More information

Basic Data Types. Lecture 6A Machine-Level Programming IV: Structured Data. Array Allocation. Array Access Basic Principle

Basic Data Types. Lecture 6A Machine-Level Programming IV: Structured Data. Array Allocation. Array Access Basic Principle Lecture 6 Machine-Level Programming IV: Structured Data Topics rrays Structs Unions Basic Data Types Integral Stored & operated on in general registers Signed vs. unsigned depends on instructions used

More information

Computer Systems CEN591(502) Fall 2011

Computer Systems CEN591(502) Fall 2011 Computer Systems CEN591(502) Fall 2011 Sandeep K. S. Gupta Arizona State University 9 th lecture Machine-Level Programming (4) (Slides adapted from CSAPP) Announcements Potentially Makeup Classes on Sat

More information

Machine-Level Prog. IV - Structured Data

Machine-Level Prog. IV - Structured Data Machine-Level Prog. IV - Structured Data Today! rrays! Structures! Unions Next time! Buffer overflow, x86-64 Fabián E. Bustamante, 2007 Basic data types! Integral Stored & operated on in general registers

More information

Buffer Overflow. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Buffer Overflow. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Buffer Overflow Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu x86-64/linux Memory Layout Stack Runtime stack (8MB limit) Heap Dynamically allocated

More information

Systems I. Machine-Level Programming VII: Structured Data

Systems I. Machine-Level Programming VII: Structured Data Systems I Machine-Level Programming VII: Structured Data Topics rrays Structs Unions Basic Data Types Integral Stored & operated on in general registers Signed vs. unsigned depends on instructions used

More information

Buffer Overflow. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Buffer Overflow. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University Buffer Overflow Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong (jinkyu@skku.edu)

More information

Introduction to Computer Systems , fall th Lecture, Sep. 14 th

Introduction to Computer Systems , fall th Lecture, Sep. 14 th Introduction to Computer Systems 15 213, fall 2009 7 th Lecture, Sep. 14 th Instructors: Majd Sakr and Khaled Harras Last Time For loops for loop while loop do while loop goto version for loop while loop

More information

CS241 Computer Organization Spring Loops & Arrays

CS241 Computer Organization Spring Loops & Arrays CS241 Computer Organization Spring 2015 Loops & Arrays 2-26 2015 Outline! Loops C loops: while, for, do-while Translation to jump to middle! Arrays Read: CS:APP2 Chapter 3, sections 3.6 3.7 IA32 Overview

More information

Machine Programming 4: Structured Data

Machine Programming 4: Structured Data Machine Programming 4: Structured Data CS61, Lecture 6 Prof. Stephen Chong September 20, 2011 Announcements Assignment 2 (Binary bomb) due Thursday We are trying out Piazza to allow class-wide questions

More information

Machine-Level Programming IV: Structured Data

Machine-Level Programming IV: Structured Data Machine-Level Programming IV: Structured Data Topics Arrays Structs Unions Basic Data Types Integral 2 Stored & operated on in general registers Signed vs. unsigned depends on instructions used Intel GAS

More information

Machine-Level Programming V: Advanced Topics

Machine-Level Programming V: Advanced Topics Machine-Level Programming V: Advanced Topics Slides courtesy of: Randy Bryant & Dave O Hallaron 1 Today Structures Alignment Unions Memory Layout Buffer Overflow Vulnerability Protection 2 R.A. Rutenbar,

More information

Data Structures in Memory!

Data Structures in Memory! Data Structures in Memory! Arrays One- dimensional Mul/- dimensional (nested) Mul/- level Structs Alignment Unions 1 What is memory again? 2 Data Structures in Assembly Arrays? Strings? Structs? 3 Array

More information

Machine- Level Programming V: Advanced Topics

Machine- Level Programming V: Advanced Topics Machine- Level Programming V: Advanced Topics Andrew Case Slides adapted from Jinyang Li, Randy Bryant & Dave O Hallaron 1 Today Structures and Unions Memory Layout Buffer Overflow Vulnerability ProtecEon

More information

Floating Point Stored & operated on in floating point registers Intel GAS Bytes C Single s 4 float Double l 8 double Extended t 10/12/16 long double

Floating Point Stored & operated on in floating point registers Intel GAS Bytes C Single s 4 float Double l 8 double Extended t 10/12/16 long double Basic Data Types Integral Stored & operated on in general (integer) registers Signed vs. unsigned depends on instructions used Intel GS Bytes C byte b 1 [unsigned] char word w 2 [unsigned] short double

More information

Integral. ! Stored & operated on in general registers. ! Signed vs. unsigned depends on instructions used

Integral. ! Stored & operated on in general registers. ! Signed vs. unsigned depends on instructions used Basic Data Types Machine-Level Programming IV: Structured Data Topics! rrays! Structs! Unions Integral! Stored & operated on in general registers! Signed vs. unsigned depends on instructions used Intel

More information

Basic Data Types The course that gives CMU its Zip! Machine-Level Programming IV: Data Feb. 5, 2008

Basic Data Types The course that gives CMU its Zip! Machine-Level Programming IV: Data Feb. 5, 2008 Machine-Level Programming IV: Data Feb. 5, 2008 class07.ppt 15-213 The course that gives CMU its Zip! Structured Data rrays Structs Unions Basic Data Types Integral Stored & operated on in general registers

More information

Basic Data Types The course that gives CMU its Zip! Machine-Level Programming IV: Structured Data Sept. 18, 2003.

Basic Data Types The course that gives CMU its Zip! Machine-Level Programming IV: Structured Data Sept. 18, 2003. Machine-Level Programming IV: Structured Data Sept. 18, 2003 class08.ppt 15-213 The course that gives CMU its Zip! Topics rrays Structs Unions Basic Data Types Integral Stored & operated on in general

More information

The course that gives CMU its Zip! Floating Point Arithmetic Feb 17, 2000

The course that gives CMU its Zip! Floating Point Arithmetic Feb 17, 2000 15-213 The course that gives CMU its Zip! Floating Point Arithmetic Feb 17, 2000 Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties IA32 floating point Floating

More information

Machine-Level Prog. V Miscellaneous Topics

Machine-Level Prog. V Miscellaneous Topics Machine-Level Prog. V Miscellaneous Topics Today Buffer overflow Extending IA32 to 64 bits Next time Memory Fabián E. Bustamante, 2007 Internet worm and IM war November, 1988 Internet Worm attacks thousands

More information

CSC 252: Computer Organization Spring 2018: Lecture 9

CSC 252: Computer Organization Spring 2018: Lecture 9 CSC 252: Computer Organization Spring 2018: Lecture 9 Instructor: Yuhao Zhu Department of Computer Science University of Rochester Action Items: Assignment 2 is due tomorrow, midnight Assignment 3 is out

More information

h"p://news.illinois.edu/news/12/0927transient_electronics_johnrogers.html

hp://news.illinois.edu/news/12/0927transient_electronics_johnrogers.html Researchers at the University of Illinois, in collaborafon with TuHs University and Northwestern University, have demonstrated a new type of biodegradable electronics technology that could introduce new

More information

X86 Assembly Buffer Overflow III:1

X86 Assembly Buffer Overflow III:1 X86 Assembly Buffer Overflow III:1 Admin Link to buffer overflow demo http://nsfsecurity.pr.erau.edu/bom/ ASM quick-reference from Larry Zhang (thanks!) http://www.cs.uaf.edu/2010/fall/cs301/support/x86/gcc.html

More information

Giving credit where credit is due

Giving credit where credit is due CSCE 230J Computer Organization Machine-Level Programming IV: Structured Data Giving credit where credit is due Most of slides for this lecture are based on slides created by Drs. Bryant and O Hallaron,

More information

Giving credit where credit is due

Giving credit where credit is due CSCE 230J Computer Organization Machine-Level Programming IV: Structured Data Dr. Steve Goddard goddard@cse.unl.edu http://cse.unl.edu/~goddard/courses/csce230j Giving credit where credit is due Most of

More information

CISC 360. Machine-Level Programming IV: Structured Data Sept. 24, 2008

CISC 360. Machine-Level Programming IV: Structured Data Sept. 24, 2008 CISC 360 Machine-Level Programming IV: Structured Data Sept. 24, 2008 Basic Data Types 2 CISC 360, Fa09 Array Allocation char string[12]; int val[5]; x x + 12 double a[4]; x x + 4 x + 8 x + 12 x + 16 x

More information

Machine-level Programs Adv. Topics

Machine-level Programs Adv. Topics Computer Systems Machine-level Programs Adv. Topics Han, Hwansoo x86-64 Linux Memory Layout 0x00007FFFFFFFFFFF Stack Runtime stack (8MB limit) E. g., local variables Heap Dynamically allocated as needed

More information

Buffer overflows. Specific topics:

Buffer overflows. Specific topics: Buffer overflows Buffer overflows are possible because C does not check array boundaries Buffer overflows are dangerous because buffers for user input are often stored on the stack Specific topics: Address

More information

Page 1. Basic Data Types CISC 360. Machine-Level Programming IV: Structured Data Sept. 24, Array Access. Array Allocation.

Page 1. Basic Data Types CISC 360. Machine-Level Programming IV: Structured Data Sept. 24, Array Access. Array Allocation. CISC 360 Basic Data Types Machine-Level Programming IV: Structured Data Sept. 24, 2008 2 CISC 360, Fa09 rray llocation rray ccess char string[12]; int val[5]; 1 5 2 1 3 int val[5]; x x + 12 x x + 4 x +

More information

CS , Fall 2001 Exam 1

CS , Fall 2001 Exam 1 Andrew login ID: Full Name: CS 15-213, Fall 2001 Exam 1 October 9, 2001 Instructions: Make sure that your exam is not missing any sheets, then write your full name and Andrew login ID on the front. Write

More information

Machine Programming 5: Buffer Overruns and Stack Exploits

Machine Programming 5: Buffer Overruns and Stack Exploits Machine Programming 5: Buffer Overruns and Stack Exploits CS61, Lecture 6 Prof. Stephen Chong September 22, 2011 Thinking about grad school in Computer Science? Panel discussion Tuesday September 27th,

More information

Buffer overflows (a security interlude) Address space layout the stack discipline + C's lack of bounds-checking HUGE PROBLEM

Buffer overflows (a security interlude) Address space layout the stack discipline + C's lack of bounds-checking HUGE PROBLEM Buffer overflows (a security interlude) Address space layout the stack discipline + C's lack of bounds-checking HUGE PROBLEM x86-64 Linux Memory Layout 0x00007fffffffffff not drawn to scale Stack... Caller

More information

Memory Organization and Addressing

Memory Organization and Addressing Memory Organization and essing CSCI 224 / ECE 317: Computer Architecture Instructor: Prof. Jason Fritts Slides adapted from Bryant & O Hallaron s slides 1 Data Representation in Memory Memory organization

More information

CS241 Computer Organization Spring Buffer Overflow

CS241 Computer Organization Spring Buffer Overflow CS241 Computer Organization Spring 2015 Buffer Overflow 4-02 2015 Outline! Linking & Loading, continued! Buffer Overflow Read: CSAPP2: section 3.12: out-of-bounds memory references & buffer overflow K&R:

More information

Why do we need Pointers? Call by Value vs. Call by Reference in detail Implementing Arrays Buffer Overflow / The Stack Hack

Why do we need Pointers? Call by Value vs. Call by Reference in detail Implementing Arrays Buffer Overflow / The Stack Hack Chapter 16 Why do we need Pointers? Call by Value vs. Call by Reference in detail Implementing Arrays Buffer Overflow / The Stack Hack A problem with parameter passing via stack Consider the following

More information

Lecture 7: More procedures; array access Computer Architecture and Systems Programming ( )

Lecture 7: More procedures; array access Computer Architecture and Systems Programming ( ) Systems Group Department of Computer Science ETH Zürich Lecture 7: More procedures; array access Computer Architecture and Systems Programming (252-0061-00) Timothy Roscoe Herbstsemester 2012 1 Last Time

More information

Machine-Level Programming V: Advanced Topics

Machine-Level Programming V: Advanced Topics Machine-Level Programming V: Advanced Topics CENG331 - Computer Organization Instructor: Murat Manguoglu Adapted from slides of the textbook: http://csapp.cs.cmu.edu/ Today Memory Layout Buffer Overflow

More information

Machine Representa/on of Programs: Arrays, Structs and Unions. This lecture. Arrays Structures Alignment Unions CS Instructor: Sanjeev Se(a

Machine Representa/on of Programs: Arrays, Structs and Unions. This lecture. Arrays Structures Alignment Unions CS Instructor: Sanjeev Se(a Machine Representa/on of Programs: rrays, Structs and Unions Instructor: Sanjeev Se(a 1 This lecture rrays Structures lignment Unions 2 1 This lecture rrays One- dimensional Mul(- dimensional (nested)

More information

Assembly IV: Complex Data Types. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Assembly IV: Complex Data Types. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University ssembly IV: Complex Data Types Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Basic Data Types Integer Stored & operated on in general registers

More information

CMSC 313 Fall2009 Midterm Exam 2 Section 01 Nov 11, 2009

CMSC 313 Fall2009 Midterm Exam 2 Section 01 Nov 11, 2009 CMSC 313 Fall2009 Midterm Exam 2 Section 01 Nov 11, 2009 Name Score out of 70 UMBC Username Notes: a. Please write clearly. Unreadable answers receive no credit. b. For TRUE/FALSE questions, write the

More information

Assembly I: Basic Operations. Jo, Heeseung

Assembly I: Basic Operations. Jo, Heeseung Assembly I: Basic Operations Jo, Heeseung Moving Data (1) Moving data: movl source, dest Move 4-byte ("long") word Lots of these in typical code Operand types Immediate: constant integer data - Like C

More information

ASSEMBLY I: BASIC OPERATIONS. Jo, Heeseung

ASSEMBLY I: BASIC OPERATIONS. Jo, Heeseung ASSEMBLY I: BASIC OPERATIONS Jo, Heeseung MOVING DATA (1) Moving data: movl source, dest Move 4-byte ("long") word Lots of these in typical code Operand types Immediate: constant integer data - Like C

More information

Assembly IV: Complex Data Types

Assembly IV: Complex Data Types ssembly IV: Complex Data Types Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong

More information

Prac*ce problem on webpage

Prac*ce problem on webpage Last year, for the first *me, spending by Apple and Google on patent lawsuits and unusually big- dollar patent purchases exceeded spending on research and development of new products But in 2008, Mr. Phillips

More information

Machine-Level Programming V: Advanced Topics

Machine-Level Programming V: Advanced Topics Machine-Level Programming V: Advanced Topics CSE 238/2038/2138: Systems Programming Instructor: Fatma CORUT ERGİN Slides adapted from Bryant & O Hallaron s slides 1 Today Memory Layout Buffer Overflow

More information

Instruction Set Architecture

Instruction Set Architecture CS:APP Chapter 4 Computer Architecture Instruction Set Architecture Randal E. Bryant Carnegie Mellon University http://csapp.cs.cmu.edu CS:APP Instruction Set Architecture Assembly Language View Processor

More information

The Hardware/So=ware Interface CSE351 Winter 2013

The Hardware/So=ware Interface CSE351 Winter 2013 The Hardware/So=ware Interface CSE351 Winter 2013 Data Structures I: rrays Data Structures in ssembly rrays One- dimensional Mul:- dimensional (nested) Mul:- level Structs lignment Unions 2 rray llocaeon

More information

Machine Programming 1: Introduction

Machine Programming 1: Introduction Machine Programming 1: Introduction CS61, Lecture 3 Prof. Stephen Chong September 8, 2011 Announcements (1/2) Assignment 1 due Tuesday Please fill in survey by 5pm today! Assignment 2 will be released

More information

Instruction Set Architecture

Instruction Set Architecture CS:APP Chapter 4 Computer Architecture Instruction Set Architecture Randal E. Bryant Carnegie Mellon University http://csapp.cs.cmu.edu CS:APP Instruction Set Architecture Assembly Language View! Processor

More information

Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction

Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction E I P CPU isters Condition Codes Addresses Data Instructions Memory Object Code Program Data OS Data Topics Assembly Programmer

More information

1 /* file cpuid2.s */ 4.asciz "The processor Vendor ID is %s \n" 5.section.bss. 6.lcomm buffer, section.text. 8.globl _start.

1 /* file cpuid2.s */ 4.asciz The processor Vendor ID is %s \n 5.section.bss. 6.lcomm buffer, section.text. 8.globl _start. 1 /* file cpuid2.s */ 2.section.data 3 output: 4.asciz "The processor Vendor ID is %s \n" 5.section.bss 6.lcomm buffer, 12 7.section.text 8.globl _start 9 _start: 10 movl $0, %eax 11 cpuid 12 movl $buffer,

More information

Machine-Level Programming I: Introduction Jan. 30, 2001

Machine-Level Programming I: Introduction Jan. 30, 2001 15-213 Machine-Level Programming I: Introduction Jan. 30, 2001 Topics Assembly Programmer s Execution Model Accessing Information Registers Memory Arithmetic operations IA32 Processors Totally Dominate

More information

Assembly Language: Function Calls

Assembly Language: Function Calls Assembly Language: Function Calls 1 Goals of this Lecture Help you learn: Function call problems: Calling and returning Passing parameters Storing local variables Handling registers without interference

More information

Computer Organization: A Programmer's Perspective

Computer Organization: A Programmer's Perspective A Programmer's Perspective Machine-Level Programming (4: Data Structures) Gal A. Kaminka galk@cs.biu.ac.il Today Arrays One-dimensional Multi-dimensional (nested) Multi-level Structures Allocation Access

More information

Assembly I: Basic Operations. Computer Systems Laboratory Sungkyunkwan University

Assembly I: Basic Operations. Computer Systems Laboratory Sungkyunkwan University Assembly I: Basic Operations Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Moving Data (1) Moving data: movl source, dest Move 4-byte ( long )

More information

2 Systems Group Department of Computer Science ETH Zürich. Argument Build 3. %r8d %rax. %r9d %rbx. Argument #6 %rcx. %r10d %rcx. Static chain ptr %rdx

2 Systems Group Department of Computer Science ETH Zürich. Argument Build 3. %r8d %rax. %r9d %rbx. Argument #6 %rcx. %r10d %rcx. Static chain ptr %rdx Last Time Lecture 7: More procedures; array access Computer rchitecture and Systems Programming (252-0061-00) Timothy Roscoe Herbstsemester 2012 For loops - goto version goto jump to middle version Jump

More information

Assembly Language: Function Calls" Goals of this Lecture"

Assembly Language: Function Calls Goals of this Lecture Assembly Language: Function Calls" 1 Goals of this Lecture" Help you learn:" Function call problems:" Calling and returning" Passing parameters" Storing local variables" Handling registers without interference"

More information

Machine- Level Programming V: Advanced Topics

Machine- Level Programming V: Advanced Topics Machine- Level Programming V: Advanced Topics CS 485: Systems Programming Fall 2015 Instructor: James Griffioen Adapted from slides by R. Bryant and D. O Hallaron (hjp://csapp.cs.cmu.edu/public/instructors.html)

More information

Y86 Processor State. Instruction Example. Encoding Registers. Lecture 7A. Computer Architecture I Instruction Set Architecture Assembly Language View

Y86 Processor State. Instruction Example. Encoding Registers. Lecture 7A. Computer Architecture I Instruction Set Architecture Assembly Language View Computer Architecture I Instruction Set Architecture Assembly Language View Processor state Registers, memory, Instructions addl, movl, andl, How instructions are encoded as bytes Layer of Abstraction

More information

CS241 Computer Organization Spring Data Alignment

CS241 Computer Organization Spring Data Alignment CS241 Computer Organization Spring 2015 Data Alignment 3-26 2015 Outline! Data Alignment! C: pointers to functions! Memory Layout Read: CS:APP2 Chapter 3, sections 3.8-3.9 Quiz next Thursday, April 2nd

More information

Last time. Last Time. Last time. Dynamic Array Multiplication. Dynamic Nested Arrays

Last time. Last Time. Last time. Dynamic Array Multiplication. Dynamic Nested Arrays Last time Lecture 8: Structures, alignment, floats Computer Architecture and Systems Programming (252-0061-00) Timothy Roscoe Herbstsemester 2012 %rax %rbx %rcx %rdx %rsi %rdi %rsp Return alue Callee saed

More information

Machine-Level Programming V: Advanced Topics

Machine-Level Programming V: Advanced Topics Machine-Level Programming V: Advanced Topics CS140 - Assembly Language and Computer Organization March 29, 2016 Slides courtesy of: Randal E. Bryant and David R. O Hallaron 1 Today Memory Layout Buffer

More information

Assembly Language: Function Calls" Goals of this Lecture"

Assembly Language: Function Calls Goals of this Lecture Assembly Language: Function Calls" 1 Goals of this Lecture" Help you learn:" Function call problems:" Calling and urning" Passing parameters" Storing local variables" Handling registers without interference"

More information

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 16, SPRING 2013 TOPICS TODAY Project 6 Perils & Pitfalls of Memory Allocation C Function Call Conventions in Assembly Language PERILS

More information

Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p

Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p text C program (p1.c p2.c) Compiler (gcc -S) text Asm

More information

Machine-Level Programming V: Buffer overflow

Machine-Level Programming V: Buffer overflow Carnegie Mellon Machine-Level Programming V: Buffer overflow Slides adapted from Bryant and O Hallaron Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition 1 Recall: Memory

More information

Machine- level Programming IV: Data Structures. Topics Arrays Structs Unions

Machine- level Programming IV: Data Structures. Topics Arrays Structs Unions Machine- level Programming IV: Data Structures Topics Arrays Structs Unions 1! Basic Data Types Integral Stored & operated on in general registers Signed vs. unsigned depends on instrucbons used Intel

More information

CS , Fall 2002 Exam 1

CS , Fall 2002 Exam 1 Andrew login ID: Full Name: CS 15-213, Fall 2002 Exam 1 October 8, 2002 Instructions: Make sure that your exam is not missing any sheets, then write your full name and Andrew login ID on the front. Write

More information

An Experience Like No Other. Stack Discipline Aug. 30, 2006

An Experience Like No Other. Stack Discipline Aug. 30, 2006 15-410 An Experience Like No Other Discipline Aug. 30, 2006 Bruce Maggs Dave Eckhardt Slides originally stolen from 15-213 15-410, F 06 Synchronization Registration If you're here but not registered, please

More information

Assembly Language: Function Calls. Goals of this Lecture. Function Call Problems

Assembly Language: Function Calls. Goals of this Lecture. Function Call Problems Assembly Language: Function Calls 1 Goals of this Lecture Help you learn: Function call problems: Calling and urning Passing parameters Storing local variables Handling registers without interference Returning

More information

Machine-Level Programming V: Advanced Topics

Machine-Level Programming V: Advanced Topics Machine-Level Programming V: Advanced Topics 15-213: Introduction to Computer Systems 9 th Lecture, June 7 Instructor: Brian Railing 1 Today Memory Layout Buffer Overflow Vulnerability Protection Unions

More information

CAS CS Computer Systems Spring 2015 Solutions to Problem Set #2 (Intel Instructions) Due: Friday, March 20, 1:00 pm

CAS CS Computer Systems Spring 2015 Solutions to Problem Set #2 (Intel Instructions) Due: Friday, March 20, 1:00 pm CAS CS 210 - Computer Systems Spring 2015 Solutions to Problem Set #2 (Intel Instructions) Due: Friday, March 20, 1:00 pm This problem set is to be completed individually. Explain how you got to your answers

More information

How to Write Fast Numerical Code Spring 2013 Lecture: Architecture/Microarchitecture and Intel Core

How to Write Fast Numerical Code Spring 2013 Lecture: Architecture/Microarchitecture and Intel Core How to Write Fast Numerical Code Spring 2013 Lecture: Architecture/Microarchitecture and Intel Core Instructor: Markus Püschel TA: Daniele Spampinato & Alen Stojanov Technicalities Research project: Let

More information

u Arrays One-dimensional Multi-dimensional (nested) Multi-level u Structures Allocation Access Alignment u Floating Point

u Arrays One-dimensional Multi-dimensional (nested) Multi-level u Structures Allocation Access Alignment u Floating Point u Arrays One-dimensional Multi-dimensional (nested) Multi-level u Structures Allocation Access Alignment u Floating Point u Basic Principle T A[L]; Array of data type T and length L Contiguously allocated

More information

Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition 1 Machine-Level Programming V: Advanced Topics 15-213/18-213/14-513/15-513: Introduction to Computer Systems 9 th Lecture, September 25, 2018 2 Today Memory Layout Buffer Overflow Vulnerability Protection

More information

Assembly III: Procedures. Jo, Heeseung

Assembly III: Procedures. Jo, Heeseung Assembly III: Procedures Jo, Heeseung IA-32 Stack (1) Characteristics Region of memory managed with stack discipline Grows toward lower addresses Register indicates lowest stack address - address of top

More information

ASSEMBLY III: PROCEDURES. Jo, Heeseung

ASSEMBLY III: PROCEDURES. Jo, Heeseung ASSEMBLY III: PROCEDURES Jo, Heeseung IA-32 STACK (1) Characteristics Region of memory managed with stack discipline Grows toward lower addresses Register indicates lowest stack address - address of top

More information

CMPSC 497 Buffer Overflow Vulnerabilities

CMPSC 497 Buffer Overflow Vulnerabilities Systems and Internet Infrastructure Security Network and Security Research Center Department of Computer Science and Engineering Pennsylvania State University, University Park PA CMPSC 497 Buffer Overflow

More information

Introduction to Computer Systems. Exam 1. February 22, This is an open-book exam. Notes are permitted, but not computers.

Introduction to Computer Systems. Exam 1. February 22, This is an open-book exam. Notes are permitted, but not computers. 15-213 Introduction to Computer Systems Exam 1 February 22, 2005 Name: Andrew User ID: Recitation Section: This is an open-book exam. Notes are permitted, but not computers. Write your answer legibly in

More information

Assembly III: Procedures. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Assembly III: Procedures. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Assembly III: Procedures Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu IA-32 (1) Characteristics Region of memory managed with stack discipline

More information

Machine Level Programming: Arrays, Structures and More

Machine Level Programming: Arrays, Structures and More Machine Level Programming: rrays, Structures and More Computer Systems Organization (Spring 2016) CSCI-U 201, Section 2 Instructor: Joanna Klukowska Slides adapted from Randal E. Bryant and David R. O

More information

Introduction to Computer Systems. Exam 1. February 22, Model Solution fp

Introduction to Computer Systems. Exam 1. February 22, Model Solution fp 15-213 Introduction to Computer Systems Exam 1 February 22, 2005 Name: Andrew User ID: Recitation Section: Model Solution fp This is an open-book exam. Notes are permitted, but not computers. Write your

More information

CISC 360. Machine-Level Programming I: Introduction Sept. 18, 2008

CISC 360. Machine-Level Programming I: Introduction Sept. 18, 2008 CISC 360 Machine-Level Programming I: Introduction Sept. 18, 2008 Topics Assembly Programmerʼs Execution Model Accessing Information Registers Memory Arithmetic operations IA32 Processors Totally Dominate

More information

Systems I. Machine-Level Programming I: Introduction

Systems I. Machine-Level Programming I: Introduction Systems I Machine-Level Programming I: Introduction Topics Assembly Programmerʼs Execution Model Accessing Information Registers IA32 Processors Totally Dominate General Purpose CPU Market Evolutionary

More information

The course that gives CMU its Zip! Machine-Level Programming III: Procedures Sept. 17, 2002

The course that gives CMU its Zip! Machine-Level Programming III: Procedures Sept. 17, 2002 15-213 The course that gives CMU its Zip! Machine-Level Programming III: Procedures Sept. 17, 2002 Topics IA32 stack discipline Register saving conventions Creating pointers to local variables class07.ppt

More information

CISC 360 Instruction Set Architecture

CISC 360 Instruction Set Architecture CISC 360 Instruction Set Architecture Michela Taufer October 9, 2008 Powerpoint Lecture Notes for Computer Systems: A Programmer's Perspective, R. Bryant and D. O'Hallaron, Prentice Hall, 2003 Chapter

More information

Machine-level Programming (3)

Machine-level Programming (3) Machine-level Programming (3) Procedures A: call A call A return Two issues How to return to the correct position? How to pass arguments and return values between callee to caller? 2 Procedure Control

More information

Instruction Set Architecture

Instruction Set Architecture CISC 360 Instruction Set Architecture Michela Taufer October 9, 2008 Powerpoint Lecture Notes for Computer Systems: A Programmer's Perspective, R. Bryant and D. O'Hallaron, Prentice Hall, 2003 Chapter

More information