CSC2108: Automated Verification Assignment 3. Due: November 14, classtime.

Similar documents
CS 267: Automated Verification. Lecture 13: Bounded Model Checking. Instructor: Tevfik Bultan

Introduction to CBMC. Software Engineering Institute Carnegie Mellon University Pittsburgh, PA Arie Gurfinkel December 5, 2011

Seminar in Software Engineering Presented by Dima Pavlov, November 2010

Introduction to CBMC: Part 1

Bounded Model Checking Of C Programs: CBMC Tool Overview

C Bounded Model Checker

BITCOIN MINING IN A SAT FRAMEWORK

Application of Propositional Logic II - How to Test/Verify my C program? Moonzoo Kim

Software Model Checking. Xiangyu Zhang

Automated Test Generation using CBMC

Handling Loops in Bounded Model Checking of C Programs via k-induction

: A Bounded Model Checking Tool to Verify Qt Applications

Student Name: University of California at Berkeley College of Engineering Department of Electrical Engineering and Computer Science

Automatic Software Verification

Software Model Checking with Abstraction Refinement

So far, we've seen situations in which locking can improve reliability of access to critical sections.

Bug Finding with Under-approximating Static Analyses. Daniel Kroening, Matt Lewis, Georg Weissenbacher

CS 450 Exam 2 Mon. 11/7/2016

Quantifying Information Leaks in Software

The deadlock problem

Problem Set 4 Solutions

Model Checking Embedded C Software using k-induction and Invariants

Thread-Local. Lecture 27: Concurrency 3. Dealing with the Rest. Immutable. Whenever possible, don t share resources

1. (6 points) Control Hijacking Indicate whether the statement is always valid. Indicate true or false, and give a one sentence explanation.

Hybrid Verification in SPARK 2014: Combining Formal Methods with Testing

More on Verification and Model Checking

typedef void (*type_fp)(void); int a(char *s) { type_fp hf = (type_fp)(&happy_function); char buf[16]; strncpy(buf, s, 18); (*hf)(); return 0; }

On Search Strategies for Constraint-Based Bounded Model Checking. Michel RUEHER

Lecture 3 Notes Arrays

A Non-Blocking Concurrent Queue Algorithm

CS16 Exam #1 7/17/ Minutes 100 Points total

Week 6. Data structures

Implementing Locks. Nima Honarmand (Based on slides by Prof. Andrea Arpaci-Dusseau)

Exercise 1 ( = 22 points)

Data Structure Advanced

COMP 300E Operating Systems Fall Semester 2011 Midterm Examination SAMPLE. Name: Student ID:

Contracts. Dr. C. Constantinides. June 5, Department of Computer Science and Software Engineering Concordia University Montreal, Canada 1/71

System Correctness. EEC 421/521: Software Engineering. System Correctness. The Problem at Hand. A system is correct when it meets its requirements

Dept. of CSE, York Univ. 1

CSL373: Lecture 5 Deadlocks (no process runnable) + Scheduling (> 1 process runnable)

CS 510/13. Predicate Abstraction

CMSC421: Principles of Operating Systems

MC 302 GRAPH THEORY 10/1/13 Solutions to HW #2 50 points + 6 XC points

Concurrent Objects and Linearizability

Name: CIS 341 Final Examination 10 December 2008

U.C. Berkeley CS170 : Algorithms, Fall 2013 Midterm 1 Professor: Satish Rao October 10, Midterm 1 Solutions

Linear Time Unit Propagation, Horn-SAT and 2-SAT

Formal Verification of Embedded Software in Medical Devices Considering Stringent Hardware Constraints

Bounded Model Checking. Mooly Sagiv Slides from Arie Gurfinkel & Sagar Chaki, Daniel Jackson, Shahar Maoz

Concurrency Control Serializable Schedules and Locking Protocols

Model Checking and Its Applications

Logistics. Templates. Plan for today. Logistics. A quick intro to Templates. A quick intro to Templates. Project. Questions? Introduction to Templates

EECS 482 Midterm (Fall 1998)

Deadlocks. Deadlock in Resource Sharing Environment. CIT 595 Spring Recap Example. Representing Deadlock

Solutions for Assignment 5

Cover sheet for Assignment 3

Synchronising Threads

Priority Queues. 1 Introduction. 2 Naïve Implementations. CSci 335 Software Design and Analysis III Chapter 6 Priority Queues. Prof.

Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Last Class. Last Class. Faloutsos/Pavlo CMU /615

Multiple choice questions. Answer on Scantron Form. 4 points each (100 points) Which is NOT a reasonable conclusion to this sentence:

For more Articles Go To: Whatisdbms.com CONCURRENCY CONTROL PROTOCOL

Queues. CITS2200 Data Structures and Algorithms. Topic 5

Software Security: Vulnerability Analysis

CSC 1052 Algorithms & Data Structures II: Linked Queues

University of Waterloo CS240 Winter 2018 Assignment 2. Due Date: Wednesday, Jan. 31st (Part 1) resp. Feb. 7th (Part 2), at 5pm

Today s Class. Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Formal Properties of Schedules. Conflicting Operations

Threads Tuesday, September 28, :37 AM

CISC 7310X. C10: Deadlocks. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 4/12/2018 CUNY Brooklyn College

CSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Synchronization Exercise

re-exam Concurrent Programming tda383/dit390 Date: Time: 14:00 18:00 Place: Maskinhuset (M)

More on Synchronization and Deadlock

SCOOP A contract-based concurrent object-oriented programming model

Queues. A queue is a special type of structure that can be used to maintain data in an organized way.

The Java Memory Model

Conflict Serializability, Locking, Lock Modes. CS157B Chris Pollett Apr.27, 2005.

Formal modelling and verification in UPPAAL

CS171 Midterm Exam. October 29, Name:

System Model. Types of resources Reusable Resources Consumable Resources

Research Collection. Formal background and algorithms. Other Conference Item. ETH Library. Author(s): Biere, Armin. Publication Date: 2001

Mid-term Roll no: Scheduler Activations: Effective Kernel Support for the User-Level Management of Parallelism

2015 The MathWorks, Inc. 1

Intro to Proving Absence of Errors in C/C++ Code

CS 33. Intro to Storage Allocation. CS33 Intro to Computer Systems XXVI 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

Applications of Logic in Software Engineering. CS402, Spring 2016 Shin Yoo

Review. Review. Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Lecture #21: Concurrency Control (R&G ch.

Lecture 5: Synchronization w/locks

Verifying Safety Property of Lustre Programs: Temporal Induction

arxiv: v2 [cs.pl] 3 Apr 2018

Stanford University Computer Science Department CS 295 midterm. May 14, (45 points) (30 points) total

CS510 Operating System Foundations. Jonathan Walpole

Midterm I Exam Principles of Imperative Computation Frank Pfenning. February 17, 2011

Topics in Reliable Distributed Systems

CS 6400 Lecture 11 Name:

Recall from deadlock lecture. Tuesday, October 18, 2011

What is the Race Condition? And what is its solution? What is a critical section? And what is the critical section problem?

OS Structure. User mode/ kernel mode (Dual-Mode) Memory protection, privileged instructions. Definition, examples, how it works?

Static Analysis in C/C++ code with Polyspace

CS 506, Sect 002 Homework 5 Dr. David Nassimi Foundations of CS Due: Week 11, Mon. Apr. 7 Spring 2014

Concurrency Control Algorithms

ArdOS The Arduino Operating System Reference Guide Contents

Transcription:

CSC2108: Automated Verification Assignment 3. Due: November 14, classtime. 1. Recall the notion of alternation depth in µ-calculus formulas. An alternation depth of a formula is one if results of a least fixpoint are not used by the greatest fixpoint, or vice versa. (a) Consider the CTL formula Translate it into µ-calculus. AG(p AF(q AGr)) (b) What is the alternation depth of the above formula? (c) Prove that this is an upper bound for the alternation depth for an arbitrary CTL formula expressed in µ-calculus. Hint: prove this by induction on the structure of the formula. (d) Now consider the following formula expressed in fair CTL: EGf = νz.f n EXE[f U (Z P k )] k=1 What is the alternation depth of this formula, when expressed in µ-calculus? (e) What is the alternation depth of every fair CTL property, when translated into µ-calculus? 2. Using CBMC. For this problem we will use the CBMC program analysis tool. You can run it using the following command: cmbc --unwind 5 --function foo program.c For this problem, you will use the following C functions: /** GLOBALS */ int buf[4]; int hi = 0; int lo = 0; int size = 4; /** FUNCTION enqueue */ void enqueue (int x) buf [hi] = x; 1

hi = (hi + 1); /** FUNCTION dequeue */ int dequeue () int res = buf [lo]; lo = (lo + 1); return res; /** FUNCTION queue_test */ void queue_test (void) while (nondet_int ()) if (nondet_int ()) int x = nondet_int (); enqueue (x); else dequeue (); /** FUNCTION BINSEARCH */ int binsearch (int x) int a[16]; signed low = 0, high = 16; while (low < high) signed middle = low + ((high - low) >> 1); if (a[middle]<x) high = middle; else if (a [middle] > x) low = middle + 1; else /* a [middle] == x! */ return middle; return -1; 2

(a) Use CBMC to show that the function queue test can cause a buffer overflow. Show the execution that causes an overflow. What was the smallest unwinding bound required for finding this counterexample? (Hint: you will want to disable unwinding assertions (--no-unwinding-assertions for this example). (b) Fix the buffer overflows in the previous example. Use CBMC to verify that there is no overflow after the loop is unrolled 40 times. Can this result be used to conclude that the program has no buffer overflows? (c) Use CBMC to check whether the function binsearch accesses the array a outside of its bounds in 5 steps or less (i.e., use unwind bound of 5). What can we learn from the result? Is the function safe, unsafe, or nothing is known? (d) Repeat part (c) with unwinding bound of 10. What can you conclude from the result? 3. From Programs to Constraints. For this problem, you will need to convert a program into a set of constraints. The constraints should be such that every satisfying assignment corresponds to an execution of the program that violates an assertion. The program is given below: void main (void) int i; char * buf; char last; if (buf [i] == \0 ) int start = 0; while (start < i) buf [start] = f ; start++; last = buf [start - 1]; (a) Show the result of unrolling the loop twice (2) and adding an unwinding assertion. (b) Convert the loop-free program (with assertion) from part (a) into Single Static Assignment (SSA) form. 3

(c) Generate a constraint system C from the SSA program in part (a) such that C is satisfiable if and only if the unwinding assertion can be violated. (d) Is the constraint system C from part (c) satisfiable? If yes, show a satisfying assignment. 4. Checking Custom Properties. Locks are commonly used to grant exclusive access to resources. Assume that we have a locking API consisting of two functions: lock, and unlock. The function lock acquires a lock, and the function unlock releases it. Furthermore, a proper use of the API must conform to a locking discipline: a lock cannot be acquired (released) twice in a row without a corresponding unlock (lock) in between. For example, a sequence of calls is legal, and the sequence is not. lock (); unlock (); lock (); unlock (); lock (); lock (); unlock (); unlock (); In this problem you will need to use CBMC to check whether the following two functions conform to the locking discipline or not. /** prototypes */ int nondet_int (); void lock (void); void unlock (void); int read_input (void) return nondet_int (); /** FUNCTION LOCK1 */ void lock1 (void) int in_irq; int buf[10]; int i; if (in_irq) lock (); for (i = 0; i < 5; i++) buf [i] = read_input (); if (in_irq) lock (); 4

/** FUNCTION LOCK2 */ void lock2 (void) int request, old, total; request = 0; do lock (); old = total; request = read_input (); if (request) unlock (); total = total + 1; while (total!= old); unlock (); (a) Instrument the two functions above with asserts to check that a lock is never acquired or released twice in a row. (b) Use CBMC to check whether the function lock1 satisfies the locking discipline. Is the function correct? If not, show an erroneous execution. (c) Use CBMC to check whether the function lock2 incorrectly acquires or releases a lock twice in a row within 20 executions of the loop. What can you conclude from the result of the analysis? Can the program be considered safe? Will increasing the unwinding bound be useful? (d) Use CBMC to check that if the lock is not held before execution of the body of the loop in lock2, then the lock is held after execution of the body of the loop if and only if total == old. Does the result indicate that the program is correct or not? Explain your answer. 5