Verification of concurrent object-oriented programs

Slides:



Advertisements
Similar presentations
Advanced programming tools at Microsoft
Advertisements

Writing specifications for object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA, USA 21 Jan 2005 Invited talk, AIOOL 2005 Paris,
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
The Dafny program verifier
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA, USA 15 January 2009 Séminaire Digiteo Orsay, France.
© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Feature: Reprint Outstanding Transactions Report © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
Feature: Purchase Requisitions - Requester © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA, USA Invited talk Informatics Education in Europe (IEE III’08)
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA, USA 3 December 2008 U. Lugano Lugano, Switzerland.
MIX 09 4/15/ :14 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Feature: Payroll and HR Enhancements © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
Contracts, tools, verification K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Keynote, ASWEC 2010; Auckland, NZ;
K. Rustan M. Leino Microsoft Research, Redmond, WA, USA with Mike Barnett, Robert DeLine, Manuel Fahndrich, and Wolfram Schulte Toward enforceable contracts.
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Caltech Pasadena, CA 12 November 2009.
Windows 7 Training Microsoft Confidential. Windows ® 7 Compatibility Version Checking.
K. Rustan M. Leino RiSE, Microsoft Research, Redmond joint work with Peter Müller and Jan Smans Lecture 0 1 September 2009 FOSAD 2009, Bertinoro, Italy.
K. Rustan M. Leino RiSE, Joint work with: Peter Müller (ETH Zurich) Jan Smans (KU Leuven) Special thanks to Mike Barnett VMCAI, Madrid, Spain, 18 January.
Feature: Purchase Order Prepayments II © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
Feature: OLE Notes Migration Utility
Feature: Web Client Keyboard Shortcuts © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
Feature: SmartList Usability Enhancements © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
Session 1.
Built by Developers for Developers…. © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
Feature: Assign an Item to Multiple Sites © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
WinHEC /22/2017 © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Connect with life Connect with life
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Document Attachment –Replace OLE Notes © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
Feature: Customer Combiner and Modifier © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
Rustan Leino RiSE, Microsoft Research, Redmond MIT 5 June 2009 Joint work with: Peter Müller, ETH Zurich Jan Smans, KU Leuven.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
demo Instance AInstance B Read “7” Write “8”

customer.
K. Rustan M. Leino Microsoft Research, Redmond, WA, USA with Mike Barnett, Robert DeLine, Manuel Fahndrich, and Wolfram Schulte Spec# Writing and checking.
demo © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
Specifying and verifying programs in Spec# K. Rustan M. Leino Microsoft Research, Redmond, WA, USA Invited talk, PSI 2006 Novosibirsk, Russia 27 June 2006.
demo Demo.
demo QueryForeign KeyInstance /sm:body()/x:Order/x:Delivery/y:TrackingId1Z
Feature: Suggested Item Enhancements – Analysis and Assignment © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and.
projekt202 © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
K. Rustan M. Leino RiSE, Microsoft Research, Redmond joint work with Peter Müller and Jan Smans Lecture 1 2 September 2009 FOSAD 2009, Bertinoro, Italy.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks.
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
ESOP 2010, Paphos, Cyprus, 22 March 2010 K. Rustan M. Leino (RiSE group, Microsoft Research) Peter Müller (ETH Zurich) Jan Smans (KU Leuven)

IoCompleteRequest (Irp);... p = NULL; …f(p);
Dafny An automatic program verifier for functional correctness
Specification techniques for verifying object-oriented software
Возможности Excel 2010, о которых следует знать
Spec# Writing and checking contracts in a .NET language
Title of Presentation 11/22/2018 3:34 PM
Baseline: How Are We Doing Now?
Title of Presentation 12/2/2018 3:48 PM
Hoare-style program verification
Dafny An automatic program verifier for functional correctness
8/04/2019 9:13 PM © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
4/27/17, Bell #8 What amount of net pay has been earned this period?
Windows 8 Security Internals
Виктор Хаджийски Катедра “Металургия на желязото и металолеене”
Title of Presentation 5/12/ :53 PM
Шитманов Дархан Қаражанұлы Тарих пәнінің
Title of Presentation 5/24/2019 1:26 PM
日本初公開!? Vista の新機能を実演 とっちゃん わんくま同盟 7/23/2019 9:09 AM
Title of Presentation 7/24/2019 8:53 PM
Presentation transcript:

Verification of concurrent object-oriented programs K. Rustan M. Leino RiSE, Microsoft Research, Redmond Joint work with: Peter Müller, ETH Zurich Jan Smans, KU Leuven EPFL Lausanne, Switzerland 7 September 2009 © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Software engineering research Goal Better build, maintain, and understand programs How? Specifications Tools, tools, tools Program semantics Verification-condition generation, symbolic execution, model checking, abstract interpretation, fuzzing, test generation Satisfiability Modulo Theories (SMT)

Some specification/verification tools at Microsoft Static Driver Verifier (SDV) Applied regularly to all Microsoft device drivers of the supported device models, ~300 bugs found Available to third parties in Windows DDK Sage Applied regularly 100s of people doing various kinds of fuzzing HAVOC Has been applied to 100s of KLOC ~40 bugs in resource leaks, lock usage, use-after-free PEX Test generation, uses Code Contracts Applied to various libraries components VCC Being applied to Microsoft Hypervisor …

Spec# programming system [Barnett, Fähndrich, Leino, Müller, Schulte, Venter, et al.] Research prototype Spec# language C# 2.0 + non-null types + contracts Checking: Static type checking Run-time checking Static verification

Spec# demo

Specifications: .NET today StringBuilder.Append Method (Char[ ], Int32, Int32) Appends the string representation of a specified subarray of Unicode characters to the end of this instance. public StringBuilder Append(char[] value, int startIndex, int charCount); Parameters value A character array. startIndex The starting position in value. charCount The number of characters append. Return Value A reference to this instance after the append operation has occurred. Exceptions Exception Type Condition ArgumentNullException value is a null reference, and startIndex and charCount are not zero. ArgumentOutOfRangeException charCount is less than zero. -or- startIndex is less than zero. startIndex + charCount is less than the length of value.

Specifications in Spec# public StringBuilder Append(char[] value, int startIndex, int charCount ); requires value == null ==> startIndex == 0 && charCount == 0; requires 0 <= startIndex; requires 0 <= charCount; requires value != null ==> startIndex + charCount <= value.Length; ensures result == this;

Specifications with Code Contracts (.NET 4.0) public StringBuilder Append(char[] value, int startIndex, int charCount ) { Contract.Requires(value != null || (startIndex == 0 && charCount == 0)); Contract.Requires(0 <= startIndex); Contract.Requires(0 <= charCount); Contract.Requires(value == null || startIndex + charCount <= value.Length); Contract.Ensures(Contracts.Result<StringBuilder>() == this); // method implementation... } Note that postcondition is declared at top of method body, which is not where it should be executed. A rewriter tool moves these.

Chalice Experimental language with focus on: Key features Shared-memory concurrency Static verification Key features Memory access governed by a model of permissions Sharing via locks with monitor invariants Deadlock checking, dynamic lock re-ordering Channels Other features Classes; Mutual exclusion and readers/writers locks; Fractional permissions;Two-state monitor invariants; Asynchronous method calls; Memory leak checking; Logic predicates and functions; Ghost and prophecy variables

Dealing with memory (the heap) Access to a memory location requires permission Permissions are held by activation records Syntax for talking about permission to y: acc(y)

11/12/2018 2:32 AM demo Inc © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Transfer of permissions acc(c.y) method Main() { var c := new Counter; call c.Inc(); } method Inc() requires acc(y) ensures acc(y) { y := y + 1; }

The two halves of a call call == fork + join is semantically like … but is compiled to more efficient code call x,y := o.M(E, F); fork tk := o.M(E, F); join x,y := tk;

Well-formed specifications A specification expression can mention a memory location only if it also entails some permission to that location Example: acc(y) && y < 20 Without any permission to y, other threads may change y, and then y and “y < 20” would not be stable

Read permissions acc(y) write permission to y rd(y) read permission to y At any one time, at most one thread can have write permission to a location

Fractional permissions acc(y) 100% permission to y acc(y, p) p% permission to y rd(y) read permission to y Write access requires 100% Read access requires >0% = +  acc(y) acc(y,69) acc(y,31) rd(y) acc(y,)

Passing permissions to threads class Fib { var x: int; var y: int; var z: int; method Main() { var c := new Fib; fork c.A(); fork c.B(); } method A() requires rd(x) && acc(y) { y := x + 21; } method B() requires rd(x) && acc(z) { z := x + 34; }

Shared state What if two threads want write access to the same location? method A() … { y := y + 21; } class Fib { var y: int; method Main() { var c := new Fib; fork c.A(); fork c.B(); } ? acc(c.y) method B() … { y := y + 34; }

Monitors method A() … class Fib { { var y: int; invariant acc(y); acquire this; y := y + 21; release this; } class Fib { var y: int; invariant acc(y); method Main() { var c := new Fib; share c; fork c.A(); fork c.B(); } acc(c.y) method B() … { acquire this; y := y + 34; release this; } acc(y)

Monitor invariants Like other specifications, can hold both permissions and conditions Example: invariant acc(y) && 0 <= y acc(y)

demo Shared Counter 11/12/2018 2:32 AM © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Locks and permissions The concepts are orthogonal to one another holding a lock, and having permissions are orthogonal to one another In particular: Holding a lock does not imply any right to read or modify shared variables Their connection is: Acquiring a lock obtains some permissions Releasing a lock gives up some permissions

Preventing deadlocks A deadlock is the situation where a nonempty set (cycle) of threads each waits for a resource (e.g., lock) that is held by another thread in the set Deadlocks are prevented by making sure no such cycle can ever occur The program partially order locks The program is checked to acquire locks in strict ascending order

Wait order Wait order is a dense partial order (Mu, <<) with a bottom element  << is the strict version of << The wait level of an object o is stored in a mutable ghost field o.mu Accessing o.mu requires appropriate permissions, as for other fields

Example: Avoiding deadlocks method M() { acquire a; acquire b; … } method N() { acquire b; acquire a; … } With these preconditions, both methods verify The conjunction of the preconditions is false, so the methods can never be invoked at the same time requires rd(a.mu) requires rd(b.mu) requires rd(a.mu) requires rd(b.mu) requires maxlock << a.mu requires a.mu << b.mu requires maxlock << b.mu requires b.mu << a.mu

Setting the wait order Recall, the wait level of an object o is stored in the ghost field o.mu Initially, the .mu field is  The .mu field is set by the share statement: picks some wait level strictly between L and H, and sets o.mu to that level Provided L << H and neither denotes an extreme element, such a wait level exists, since the order is dense share o between L and H;

demo Dining Philosophers 11/12/2018 2:32 AM © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Changing the wait order When is: allowed? When o.mu is writable! … and the thread holds o Note, means (lHeld  l.mu << X), so uttering maxlock has the effect of reading many .mu fields We either need rd(maxlock), or reorder o between L and H; maxlock << X

Verified Software Initiative 11/12/2018 2:32 AM Verified Software Initiative Hoare, Joshi, Leavens, Misra, Naumann, Shankar, Woodcock, et al. “We envision a world in which computer programs are always the most reliable component of any system or device that contains them” [Hoare & Misra] © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Boogie – a verification tool bus [Barnett, Jacobs, Leino, Moskal, Rümmer, et al.] Spec# C with HAVOC specifications C with VCC specifications Dafny Chalice Your language here Boogie-to-Boogie transformations: Inference engines Program transformations Logic optimizers Boogie Your prover here Simplify Z3 SMT Lib Isabelle/HOL

Chalice summary Permissions guide what memory locations are allowed to be accessed Activation records and monitors can hold permissions Permissions can be transferred between activation records and monitors Locks grant mutually exclusive access to monitors

Try it for yourself Chalice (and Boogie) available as open source: http://boogie.codeplex.com Spec# and VCC also available as open source under academic license: http://specsharp.codeplex.com http://vcc.codeplex.com

11/12/2018 2:32 AM extra slides © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

demo Hand over hand locking :List current 11/12/2018 2:32 AM :Node tail head :Node :Node :Node :Node © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Hand-over-hand locking: the idea :Node :Node :Node :Node method Update(p: Node) requires acc(p.data,40) … ensures acc(p.data,40) … { acquire p; while (p.next != null) … { var nx := p.next; acquire nx; nx.data := nx.data + 1; release p; p := nx; } 40% 100% 40% p tail invariant acc(data,60) && … && (next != null ==> acc(next.data,40) && data <= next.data);

Hand-over-hand locking: the idea :Node :Node :Node :Node method Update(p: Node) requires acc(p.data,40) … ensures acc(p.data,40) … { acquire p; while (p.next != null) … { var nx := p.next; acquire nx; nx.data := nx.data + 1; release p; p := nx; } 100% 40% 100% 40% p nx tail invariant acc(data,60) && … && (next != null ==> acc(next.data,40) && data <= next.data);

Hand-over-hand locking: the idea :Node :Node :Node :Node method Update(p: Node) requires acc(p.data,40) … ensures acc(p.data,40) … { acquire p; while (p.next != null) … { var nx := p.next; acquire nx; nx.data := nx.data + 1; release p; p := nx; } 100% 40% 60% 100% 40% p nx tail invariant acc(data,60) && … && (next != null ==> acc(next.data,40) && data <= next.data);

Hand-over-hand locking: the idea :Node :Node :Node :Node method Update(p: Node) requires acc(p.data,40) … ensures acc(p.data,40) … { acquire p; while (p.next != null) … { var nx := p.next; acquire nx; nx.data := nx.data + 1; release p; p := nx; } 40% 60% 40% p nx tail invariant acc(data,60) && … && (next != null ==> acc(next.data,40) && data <= next.data);

Hand-over-hand locking: the idea :Node :Node :Node :Node 60% 40% method Update(p: Node) requires acc(p.data,40) … ensures acc(p.data,40) … { acquire p; while (p.next != null) … { var nx := p.next; acquire nx; nx.data := nx.data + 1; release p; p := nx; } 40% p tail invariant acc(data,60) && … && (next != null ==> acc(next.data,40) && data <= next.data);

Hand-over-hand locking: the idea :Node :Node :Node :Node 60% 40% method Update(p: Node) requires acc(p.data,40) … ensures acc(p.data,40) … { acquire p; while (p.next != null) … { var nx := p.next; acquire nx; nx.data := nx.data + 1; release p; p := nx; } 40% p tail invariant acc(data,60) && … && (next != null ==> acc(next.data,40) && data <= next.data);

Hand-over-hand locking: the idea :Node :Node :Node :Node 60% method Update(p: Node) requires acc(p.data,40) … ensures acc(p.data,40) … { acquire p; while (p.next != null) … { var nx := p.next; acquire nx; nx.data := nx.data + 1; release p; p := nx; } 40% p tail invariant acc(data,60) && … && (next != null ==> acc(next.data,40) && data <= next.data);