Cyclone: A safe dialect of C

Slides:



Advertisements
Similar presentations
The C ++ Language BY Shery khan. The C++ Language Bjarne Stroupstrup, the language’s creator C++ was designed to provide Simula’s facilities for program.
Advertisements

Dynamic Memory Management
The Interface Definition Language for Fail-Safe C Kohei Suenaga, Yutaka Oiwa, Eijiro Sumii, Akinori Yonezawa University of Tokyko.
Computer Security: Principles and Practice EECS710: Information Security Professor Hossein Saiedian Fall 2014 Chapter 10: Buffer Overflow.
Two alternatives of C: Cyclone and Vault Keami Hung February 01, 2007.
Various languages….  Could affect performance  Could affect reliability  Could affect language choice.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 1 “ Introduction to Java and OOP”
Run time vs. Compile time
CS 61C L03 C Arrays (1) A Carle, Summer 2005 © UCB inst.eecs.berkeley.edu/~cs61c/su05 CS61C : Machine Structures Lecture #3: C Pointers & Arrays
Arrays and Pointers in C Alan L. Cox
From C++ to C#. Web programming The course is on web programming using ASP.Net and C# The course is on web programming using ASP.Net and C# ASP.Net is.
Safety in the C programming Language Peter Wihl May 26 th, 2005 CS 297 Security and Programming Languages.
CENG 311 Machine Representation/Numbers
EECE 310: Software Engineering Lecture 2: Understanding Objects in Java and Types.
COP4020 Programming Languages
Java Introduction Lecture 1. Java Powerful, object-oriented language Free SDK and many resources at
Chapter 6 Buffer Overflow. Buffer Overflow occurs when the program overwrites data outside the bounds of allocated memory It was one of the first exploited.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
We will talking about story of JAVA language. By Kristsada Songpartom.
Combining Garbage Collection and Safe Manual Memory Management Michael Hicks University of Maryland, College Park Joint work with Greg Morrisett - Harvard,
Pointers in C Computer Organization I 1 August 2009 © McQuain, Feng & Ribbens Memory and Addresses Memory is just a sequence of byte-sized.
1 Lecture07: Memory Model 5/2/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
Embedding Assembly Code in C Programs תרגול 7 שילוב קוד אסמבלי בקוד C.
LECTURE 3 Compiler Phases. COMPILER PHASES Compilation of a program proceeds through a fixed series of phases.  Each phase uses an (intermediate) form.
VM: Chapter 7 Buffer Overflows. csci5233 computer security & integrity (VM: Ch. 7) 2 Outline Impact of buffer overflows What is a buffer overflow? Types.
Buffer Overflows: Attacks and Defenses for the Vulnerability of the Decade Crispin Cowan SANS 2000.
Language-Based Security: Overview of Types Deepak Garg Foundations of Security and Privacy October 27, 2009.
Design issues for Object-Oriented Languages
Memory-Related Perils and Pitfalls in C
Eighth Lecture Exception Handling in Java
Secure Coding Rules for C++ Copyright © 2016 Curt Hill
EECE 309: Software Engineering
Object Lifetime and Pointers
Shellcode COSC 480 Presentation Alison Buben.
Component 1.6.
Data Types In Text: Chapter 6.
CMSC 345 Defensive Programming Practices from Software Engineering 6th Edition by Ian Sommerville.
Bride of Buffer Overflow
Introduction to Compiler Construction
Types for Programs and Proofs
C Interview Questions Prepared By:.
Module 30 (Unix/Linux Security Issues II)
Introduction to Parsing (adapted from CS 164 at Berkeley)
Compiler Construction (CS-636)
CS 363 – Chapter 1 What is a programming language? Kinds of languages
Ik-Soon Kim December 18, 2010 Embedded Software Platform Team
Cyclone A Very Short Introduction Dan Grossman
Workshop in Nihzny Novgorod State University Activity Report
C Basics.
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
Secure Coding Rules for C++ Copyright © Curt Hill
Type Systems Terms to learn about types: Related concepts: Type
Pointers and References
High Coverage Detection of Input-Related Security Faults
Compiler Construction
CS 465 Buffer Overflow Slides by Kent Seamons and Tim van der Horst
7 Arrays.
Programming with Regions
CSE 351 Section 10 The END…Almost 3/7/12
Bride of Buffer Overflow
Memory Allocation CS 217.
Closure Representations in Higher-Order Programming Languages
Pointers C#, pointers can only be declared to hold the memory addresses of value types int i = 5; int *p; p = &i; *p = 10; // changes the value of i to.
Effective and Efficient memory Protection Using Dynamic Tainting
7 Arrays.
(Computer fundamental Lab)
Course Overview PART I: overview material PART II: inside a compiler
WJEC GCSE Computer Science
SPL – PS2 C++ Memory Handling.
Introduction to C CS 3410.
Presentation transcript:

Cyclone: A safe dialect of C Trevor Jim Greg Morrisett Dan Grossman Michael Hicks James Cheney Yanling Wang

Overview Introduction From C to Cyclone Implementation Design History Conclusion/Questions

Introduction “Common errors that cause vulnerabilities — buffer overflows, poor handling of unexpected types and amounts of data — are well understood. Unfortunately, features still seem to be valued more highly among manufacturers than reliability.” When dealing with security it is common to see this quote . The quote leads us to believe violations can be prevented by changing priorities But many reasons safety violations occur so often in C is more than poor training it is due to the roots to the design of C itself We learn about buffer overflows in all programming classes yet this is still a huge issue. There are fundamental reasons for this that have to do with the design of C. The next slide will name a few common practices that can cause vulnerabilities.

Introduction Safety violations that occur in C Buffer overflows in C can be caused by bad pointer arithmetic C uses Null-terminating strings Out-of-bounds pointers are commonplace in C An off by one error can cause a buffer overflow and its hard to train people to completely eliminate off by one errors Null terminating strings are important for efficiency, but the null terminator can be overwritten and this could cause a buffer overflow Out of bound pointers occur quite frequently when working with arrays We determine the end of an array by placing the pointer right past the end. Since this is common it is expected that occasionally it will be dereferenced or assigned.

Introduction Cyclone allows for safety while retaining C’s syntax and semantics Has been in development for 2 years Designed from the ground up for: Prevention of buffer overflows Format string attacks Memory management errors 110,000 lines 35,000 for the compiler 15,000 for supporting libraries Looking at safety violations enabled by C and how Cyclone avoids them Cyclone allows for safety without giving up C’s control of data representation and memory management It allows for developers to not have to switch to a high level language Developing cyclone to have the safety guarantee of Java while keeping C’s syntax, semantics, and idioms intact. Cyclone is freely available. The compiler and accompanying tools are licensed under GNU Now we will look at how Cyclone was developed

From C to Cyclone Similarities Differences It uses C processor Follows C’s lexical convention and grammar Same data representation as C Differences Cyclone performs a static analysis on code Inserts run-time checks Rejects some programs that C might compile Similarities arrays, pointers, enumerations, unions, structures Differences the run time checks into the compiled output at places where the analysis can’t determine that an operation is safe some safe programs will be rejected during this process

From C to Cyclone Restrictions Null checks are inserted to prevent segmentation faults Pointer arithmetic is restricted Dangling pointers are prevented through region analysis and limitations on free Only “safe casts’ and unions are allowed Setjmp and longjmp are not supported Switch labels in different scopes are disallowed These are just some of the restrictions that are imposed to c to preserve safety. The best results are to use more than one technique. Other projects have also tried applying add-ons to C so they are seldom used in production. Cyclone makes safety the default.

From C to Cyclone Extensions Never-Null pointers do not require Null checks Tagged unions support type-varying arguments Injections help automate the use of tagged unions for programmers Polymorphism replaces some use of void * Exceptions replace some uses of setjmp and longjmp These are some of the extensions that are imposed in Cyclone to make C safer

From C to Cyclone The free function in C can create dangling pointers The following is a code example Region h { int *x = rmalloc(h.sizeof(int)); int ?y = rnew(h) {1, 2, 3}; char ?z = rprintf(h, “hello”); } The article gives multiple examples, but we will just go over Free To prevent this Cyclone uses growable regions the following code is an example of how the regions are created Also this way cyclone can deallocate the entire region at one time when exiting The regions are also growable that way the memory doesn’t run out In the example x is initiallized as a pointer to an int size of memory Rnew creates an array y in the region x Rprintf creates buffer pointed to by z to store information

From C to Cyclone Rmalloc – works like malloc but allocates into a region of the handle Rnew – allocates and initializes a single step Rprintf – creates a buffer then prints formatted information to that buffer Handles can be passes to library functions Cyclone is one of the few programming languages that has safe memory management without using a garbage collector

Implementation Cyclone compiler implemented 35,000 lines of Cyclone Consists of a parser Static analysis phase And a simple translator Uses gcc as a backend Have built in utilities Memory profiler Another tool that was built in also includes documentation generation

Implementation Benchmarks Ease of Porting Table shows that much of a significant difference between C and Cyclone Ease of Porting Created cyclone so existing C code can be easily ported Fewer than 10% of the lines needed to be changed to port the benchmarks

Implementation Performance Safety Non-web benchmarks Mean and median same Standard deviation was at most 2% of the mean Near zero over-head for I/O bound applications Factor of three slower than C for computationally-intensive benchmarks Safety Found array bound violations in three benchmarks when C was ported to Cyclone Also have seen a slow down of a factor of six for operations involving pointer arithmetic

Design History Began as an offshoot of TAL Designed Popcorn to use with it Cyclone a rework of Popcorn From learning’s made some notable mistakes and changes Supported arrays with a type array<t> not a fat pointer Didn’t understand the importance of Null-terminated strings TAL- Typed Assembly Language ensured safety at the machine code level. Popcorn was a C like language that was used as the front end and built a compiler to translate it. They did this with an two agendas to further understand low-level safety and to gain outside adopters Converting C code to use array<t> was painful, so abandoned it and started using fat pointers. This made it easier to port C code requiring only a few changes. Came to understand how important Nul is to efficiency (memory reuse). So changed string library to match C’s

Conclusion Questions ? Cyclone a dialect of C that provides safety Cyclone uses static analysis and run-time checks to prevent safety violations Tries to accommodate C’s style of low-level programming Questions ?