CSCI 356 Fall 2017 : Practice Exam I DO NOT OPEN EXAM PACKET UNTIL INSTRUCTED TO DO SO YOU MAY FILL IN INFORMATION ON THE FRONT NOW

Similar documents
CSE351 Autumn 2012 Midterm Exam (5 Nov 2012)

CSE 351 Midterm - Winter 2015 Solutions

15-213/18-213, Fall 2011 Exam 1

CS , Fall 2007 Exam 1

CS / ECE , Spring 2010 Exam 1

CSE 351 Midterm - Winter 2015

15-213/18-243, Summer 2011 Exam 1 Tuesday, June 28, 2011

CSE351 Spring 2018, Midterm Exam April 27, 2018

CS356: Discussion #8 Buffer-Overflow Attacks. Marco Paolieri

Do not turn the page until 5:10.

15-213, Fall 2007 Midterm Exam

15-213/18-243, Fall 2010 Exam 1 - Version A

1 Number Representation(10 points)

CSE351 Autumn 2014 Midterm Exam (29 October 2014)

Download the tarball for this session. It will include the following files:

Do not turn the page until 11:30.

Question 1: Number Representation

CSE351 Autumn 2014 Midterm Exam (29 October 2014)

CSE 351 Midterm Exam Spring 2016 May 2, 2015

CS , Fall 2002 Exam 1

Download the tarball for this session. It will include the following files:

Assembly Language II: Addressing Modes & Control Flow

CS-220 Spring 2018 Test 2 Version Practice Apr. 23, Name:

Do not turn the page until 5:10.

Carnegie Mellon. Answer: 3

15-213/18-243, Spring 2011 Exam 1

Review addressing modes

CSE 351 Spring 2017 Midterm Exam (8 May 2017)

Computer Systems Organization V Fall 2009

CSE2421 FINAL EXAM SPRING Name KEY. Instructions: Signature

Computer Organization & Systems Exam I Example Questions

CSE 351 Midterm Exam

Do not turn the page until 5:10.

CS 3843 Final Exam Fall 2012

CS , Spring 2004 Exam 1

Time: 8:30-10:00 pm (Arrive at 8:15 pm) Location What to bring:

Winter 2017 CS107 Midterm #2 Examination (Practice #2) Problem Points Score Grader TOTAL 30

University of Washington Computer Science & Engineering Winter 2018 Instructor: Mark Wyse March 14, CSE 351 Final Exam. Last Name: First Name:

Midterm 1 topics (in one slide) Bits and bitwise operations. Outline. Unsigned and signed integers. Floating point numbers. Number representation

CS61 Section Solutions 3

CS356: Discussion #5 Debugging with GDB. Marco Paolieri

Areas for growth: I love feedback

Signed/Unsigned Integer Arithmetic in C. Vineel Kovvuri

Do not turn the page until 5:10.

Autumn 2018 CS107 Final Exam Practice Compilation

Winter 2017 March 2, 2017 CS107 2 nd Midterm Examination

CSE 351 Midterm - Winter 2017

16.317: Microprocessor Systems Design I Fall 2015

UW CSE 351, Winter 2013 Midterm Exam

CS , Fall 2004 Exam 1

Name: CMSC 313 Fall 2001 Computer Organization & Assembly Language Programming Exam 1. Question Points I. /34 II. /30 III.

CSCI 2021: x86-64 Control Flow

CS-220 Spring 2018 Final Exam Version Practice May 10, Name:

Computer Systems C S Cynthia Lee

CS 33. Machine Programming (2) CS33 Intro to Computer Systems XII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

Machine-Level Programming V: Advanced Topics

Representation of Information

Assembly II: Control Flow. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

University of Washington Computer Science & Engineering Winter 2018 Instructor: Mark Wyse March 14, CSE 351 Final Exam. Last Name: First Name:

CS 107 Lecture 10: Assembly Part I

Do not turn the page until 12:30.

CS , Fall 2001 Exam 1

Final Exam. 11 May 2018, 120 minutes, 26 questions, 100 points

Introduction to C. Why C? Difference between Python and C C compiler stages Basic syntax in C

Assembly II: Control Flow

Do not turn the page until 12:30.

last time Assembly part 2 / C part 1 condition codes reminder: quiz

Binghamton University. CS-220 Spring X86 Debug. Computer Systems Section 3.11

CSCI 2212: Intermediate Programming / C Chapter 15

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

The Hardware/Software Interface CSE351 Spring 2013

Question Points Score Total: 100

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

Problem 1 (Void * generics) (24 points) (suggested time: 30 minutes)

Do not turn the page until 12:30.

CPEG421/621 Tutorial

Processor state. Information about currently executing program. %rax, %rdi, ... %r14 %r15. %rsp. %rip CF ZF SF OF. Temporary data

CSC 8400: Computer Systems. Machine-Level Representation of Programs

Full Name: CISC 360, Fall 2008 Example of Exam

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

Outline. x86 Architecture

Computer Systems C S Cynthia Lee

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

ASSEMBLY II: CONTROL FLOW. Jo, Heeseung

Machine Language CS 3330 Samira Khan

Assembly II: Control Flow. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Page 1. Condition Codes CISC 360. Machine-Level Programming II: Control Flow Sep 17, Setting Condition Codes (cont.)

Machine-Level Programming V: Unions and Memory layout

Systems I. Machine-Level Programming I: Introduction

CS , Fall 2009 Exam 1

X86 Addressing Modes Chapter 3" Review: Instructions to Recognize"

Question F5: Caching [10 pts]

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers

Machine-Level Programming V: Buffer overflow

CS429: Computer Organization and Architecture

x86-64 Programming II

CISC 360. Machine-Level Programming II: Control Flow Sep 17, class06

X86 Assembly Language and C Fundamentals. Chapter 5. Data Transfer Instructions. X86 Code Figures

Machine/Assembler Language Putting It All Together

IA-32 & AMD64. Crash Dump Analysis 2015/2016. CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics.

Transcription:

CSCI 356 Fall 2017 : Practice Exam I DO NOT OPEN EXAM PACKET UNTIL INSTRUCTED TO DO SO YOU MAY FILL IN INFORMATION ON THE FRONT NOW PLEASE TURN OFF ALL ELECTRONIC DEVICES ID#: Name: This exam is closed book. You are allowed one (1) 8.5 x 11 handwritten note sheet You will have eighty (80) minutes to complete this exam. Answer the questions only in the spaces provided on the question sheets. If you give multiple solutions to a problem without indicating which one you want graded, the grader may select one to grade. Your answers do not need to be complete, grammatically correct sentences. Problem Points Possible 1 8 2 4 3 4 4 6 5 4 6 8 7 6 8 7 Total 47

1. Solve the following project one style problem. /* * isasciidigit - return 1 if 0x30 <= x <= 0x39 (ASCII codes for characters '0' to '9') * Example: isasciidigit(0x35) = 1. * isasciidigit(0x3a) = 0. * isasciidigit(0x05) = 0. * Legal ops:! ~ & ^ + << >> * Max ops: 15 */ int isasciidigit(int x) { int neg_0x30 = ~(0x30) + 1; int x_minus_0x30 = x + neg_0x30; int neg_0x3a = ~(0x3a) + 1; int x_minus_0x3a = x + neg_0x3a; int lower_bound_mask =!(x_minus_0x30 >> 31); //0 if x >= 0x30, 1 if x < 0x30 int upper_bound_mask =!!(x_minus_0x3a >> 31); //0 if x > 0x3a, 1 if x <= 0x39 return lower_bound_mask & upper_bound_mask; //TOTAL OPS: 12 }

2. Write the following base-10 integers in eight-bit two s complement. Express your answer in both binary and hex (base-16). a. 53 53 = 32 + 16 + 4 + 1 53 = 0011 0101 0011 -> 3 0101 -> 5 53 = 0x35 b. -75-75 = -128 + 32 + 16 + 4 + 1-75 = 1011 0101 1011 -> 11 -->b 0101 -> 5-75 = 0xb5 3. Interpret the following as hex representations of two s complement integers (eight bits each). Write them both in binary and in base-10. a. 0xCF c 12 1100 f 15 1111 0xCF = 1100 1111 0xCF = -128 + 64 + 8 + 4 + 2 + 1 = -49 b. 0x49 4 0100 9 1001 0x49 = 0100 1001 0x49 = 64 + 8 + 1 = 73

4. Consider the eight-bit floating point format. In eight-bit floating point, there is one sign bit, three exponent bits, and four fractional bits. The exponent bias is 3. a. What number is 0110 1100 in base 10? e = 110 = 6 f = 0.1100 = 0.75 E = e - bias = 6-3 = 3 M = 1 + f = 1 + 0.75 = 1.75 sign bit = 0 positive 1.75 2 3 = 1.1100 2 3 = 1110.0 = 14 b. How would 3.3125 (= 3 + 5/16) be represented in eight-bit floating point? 3.3125 = 11.0101 = 1.10101 2 1 M = 1.10101 f = 0. 10101 E = 1 e = 1 + 3 = 4 = 100 S = positive = 0 3.3125 = 0100 1010 1 5. Give a value that makes each following expressions false, and explain why it makes the expression false. If there is no value for x and y that would make the expression false, indicate that. In each case, x and y are of type int. a. ( (x^y) < 0 ) If x is 0x0, y is 0x0 b. ( (x >> 31) + 1 ) >= 0 This is always true. There s two cases: x >= 0 or x < 0. If x >= 0, x >> 31 is 0x0. 0x0 + 1 = 0x00000001. That s greater than 0. If x < 0, x >> 31 is 0x11111111. 0xffffffff + 1 = 0. That s equal to 0.

6. I have a C function with the following signature: int practice_exam_problem(int a, int b); Here is the assembly code for it: <+0>:cmp %esi,%edi <+2>: jle 0x4005be <practice_exam_problem+12> <+4>: lea 0x5(%rsi,%rsi,1),%eax <+8>: cmp %eax,%edi <+10>: je 0x4005d4 <practice_exam_problem+34> <+12>:cmp %esi,%edi <+14>:jge 0x4005ca <practice_exam_problem+24> <+16>:lea 0x4(%rdi,%rdi,2),%eax <+20>: cmp %eax,%esi <+22>: je 0x4005da <practice_exam_problem+40> <+24>: cmp %esi,%edi <+26>: jne 0x4005e0 <practice_exam_problem+46> <+28>: $0x4,%eax <+33>: retq <+34>: $0x3,%eax <+39>: retq <+40>: $0xa,%eax <+45>: retq <+46>: $0x2,%eax <+51>:retq a. Give a value for parameters to make it return 2. To return 2, we jump from <+26>, which triggers if %esi!= %edi. A good way to get to <+26> is from <+14>, which jumps to <+24> iff %edi >= %esi. But we want to NOT trigger the jump on <+10> checking if %edi == %eax, where %eax is 2 * %rsi + 5. Careful not to trigger the jumps on <+10> and <+2>! For the path to work, these conditions must hold: a < b b!= 3a + 4 OR a > b a!= 2b + 5

b. Give a value for parameters to make it return 3. The line that returns 3 is on <+34>. We jump to that from <+10>. That only happens when %eax == %edi. %eax is 2 * %rsi + 0x5. So this returns three when 2* %rsi + 0x5 == %edi. So a == 2b + 5. c. Give a value for parameters to make it return 4. Nothing jumps to <+28>, but <+14> jumps to <+24>, which is right before it. To get there, we need to jump from <+2>, the compare instruction behind <+14> So to make the jump to <+14> b <= a. To make the jump to <+24> a <= b. We want to avoid the jump to <+46>, so we want a == b. For all three conditions to hold true, we can just set a == b. d. Give a value for parameters to make it return 10. In order to return 10, we need to take the jump at <+22>, which happens when %eax == %esi. Before the comparison, %eax is set to 3 * %rdi + 4, which is 3a + 4; so we want b == 3a + 4. We also want %edi < %esi so we don t jump at <+14>. Finally, we load 2 * %rsi + 5 into %eax and compare that to %edi; we don t want to take the jump, so we need a!= 2b + 5. Final restrictions: b == 3a + 4 a!= 2b + 5 a < b

7. Consider the following struct on an x86-64 Linux machine: struct my_struct { char a; long b; short c; float *d[2]; unsigned char e[3]; float f; }; 0x0 0x1 0x8 0x10 0x12 a b c 0x18 0x20 0x28 d[0] d[1] 0x29 0x2b 0x30 e[0] e[1] e[2] f 0x2a 0x2c a. How many bytes will the struct occupy if our compiler optimizes for access time? 48 bytes b. How many bytes will the struct occupy if our compiler optimizes for space? 34 bytes

8. Draw the stack frames of test and getbuf, given that the Instruction Pointer is currently at 0x004017c7 and the stack pointer is at 0x5561dcac at the start of test. Indicate where the stack pointer is and the addresses and the content of the stack frames (variable names are ok). C code: void test() { int val; val = getbuf(); printf("no exploit. Getbuf returned 0x%x\n", val); } unsigned getbuf() { char buf[buffer_size]; gets(buf); return 1; } Assembly Code: Stack Address Contents test: 0x00401984 0x00401988 0x0040198d 0x00401992 0x00401994 0x00401999 0x0040199e 0x004019a3 0x004019a8 0x004019ac getbuf: sub callq callq add retq $0x8,%rsp $0x0,%eax 4017c3<getbuf> %eax,%edx $0x4031d8,%esi $0x1,%edi $0x0,%eax 400e00< printf_chk@plt> $0x8,%rsp test stack frame getbuf stack frame 0x5561dcac 0x5561dca4 0x5561dc9c 0x5561dc94 0x5561dc8c 0x5561dc84 0x5561dc7c 0x5561dc74 0x401992 0x004017c3 0x004017c7 0x004017ca 0x004017cf 0x004017d4 0x004017d8 sub callq add retq $0x28,%rsp %rsp,%rdi 401a4d <Gets> $0x1,%eax $0x28,%rsp Instruction Pointer 0x004017c7 Stack Pointer 0x5561dc74

/* * anyoddbit - return 1 if any odd-numbered bit in word set to 1 * Examples anyoddbit(0x5) = 0, anyoddbit(0x7) = 1 * Legal ops:! ~ & ^ + << >> * Max ops: 12 * Rating: 2 */ int anyoddbit(int x) { int m8 = 0xAA; int m16 = m8 m8 << 8; int m32 = m16 m16 <<16; int oddx = x & m32; return!!oddx; }