Two alternatives of C: Cyclone and Vault Keami Hung February 01, 2007.

Slides:



Advertisements
Similar presentations
Dynamic Memory Management
Advertisements

Introduction to Memory Management. 2 General Structure of Run-Time Memory.
Programming Languages and Paradigms
Names and Bindings.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Various languages….  Could affect performance  Could affect reliability  Could affect language choice.
Kernighan/Ritchie: Kelley/Pohl:
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
CS414 C Programming Tutorial Ben Atkin
Type-Safe Programming in C George Necula EECS Department University of California, Berkeley.
3/17/2008Prof. Hilfinger CS 164 Lecture 231 Run-time organization Lecture 23.
ISBN Chapter 5 Names, Bindings, Type Checking, and Scopes Names Variables The Concept of Binding Type Checking Strong Typing Type Compatibility.
The Concept of Variables
The environment of the computation Declarations introduce names that denote entities. At execution-time, entities are bound to values or to locations:
1 CSE 303 Lecture 11 Heap memory allocation ( malloc, free ) reading: Programming in C Ch. 11, 17 slides created by Marty Stepp
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
Names and Bindings Introduction Names Variables The concept of binding Chapter 5-a.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Peter Juszczyk CS 492/493 - ISGS. // Is this C# or Java? class TestApp { static void Main() { int counter = 0; counter++; } } The answer is C# - In C#
Language Evaluation Criteria
Safety in the C programming Language Peter Wihl May 26 th, 2005 CS 297 Security and Programming Languages.
Java Security. Topics Intro to the Java Sandbox Language Level Security Run Time Security Evolution of Security Sandbox Models The Security Manager.
Programming Languages and Paradigms Object-Oriented Programming.
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
C++ Programming. Table of Contents History What is C++? Development of C++ Standardized C++ What are the features of C++? What is Object Orientation?
Security Exploiting Overflows. Introduction r See the following link for more info: operating-systems-and-applications-in-
EE4E. C++ Programming Lecture 1 From C to C++. Contents Introduction Introduction Variables Variables Pointers and references Pointers and references.
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
5-1 Chapter 5: Names, Bindings, Type Checking, and Scopes Variables The Concept of Binding Type Checking Strong Typing Type Compatibility Scope and Lifetime.
Algorithm Programming Bar-Ilan University תשס"ח by Moshe Fresko.
University of Houston-Clear Lake Proprietary© 1997 Evolution of Programming Languages Basic cycle of improvement –Experience software difficulties –Theory.
Dynamic Memory Allocation Conventional array and other data declarations An incorrect attempt to size memory dynamically Requirement for dynamic allocation.
Computer Science Detecting Memory Access Errors via Illegal Write Monitoring Ongoing Research by Emre Can Sezer.
Computer Science and Software Engineering University of Wisconsin - Platteville 2. Pointer Yan Shi CS/SE2630 Lecture Notes.
Basic Semantics Associating meaning with language entities.
C Programming in Linux Jacob Chan. C/C++ and Java  Portable  Code written in one system and works in another  But in C, there are some libraries that.
1 Records Record aggregate of data elements –Possibly heterogeneous –Elements/slots are identified by names –Elements in same fixed order in all records.
CS 2130 Lecture 5 Storage Classes Scope. C Programming C is not just another programming language C was designed for systems programming like writing.
1 Dynamic Memory Allocation –The need –malloc/free –Memory Leaks –Dangling Pointers and Garbage Collection Today’s Material.
Prachi A. Joshi Assistant Professor in CSE DIEMS,Aurangabad Unit 1 : Basic Concepts Pointers and dynamic memory allocation, Algorithm Specification, Data.
Buffer Overflow Proofing of Code Binaries By Ramya Reguramalingam Graduate Student, Computer Science Advisor: Dr. Gopal Gupta.
Buffer Overflow Attack Proofing of Code Binary Gopal Gupta, Parag Doshi, R. Reghuramalingam, Doug Harris The University of Texas at Dallas.
1 Splint: A Static Memory Leakage tool Presented By: Krishna Balasubramanian.
Pointers in C Computer Organization I 1 August 2009 © McQuain, Feng & Ribbens Memory and Addresses Memory is just a sequence of byte-sized.
Names, Bindings, and Scope Session 3 Course : T Programming Language Concept Year : February 2011.
Object-Oriented Programming Chapter Chapter
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 12 Lecturer: Dr. Emad Nabil 1-1.
1 Lecture07: Memory Model 5/2/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
1 Structure of Compilers Lexical Analyzer (scanner) Modified Source Program Parser Tokens Semantic Analysis Syntactic Structure Optimizer Code Generator.
CS 330 Programming Languages 10 / 23 / 2007 Instructor: Michael Eckmann.
Overview: Lecture 6: Dolores Zage. What is a program? n Operations that are to be applied to certain data in a certain sequence (definition holds for.
Chapter 10 Chapter 10 Implementing Subprograms. Implementing Subprograms  The subprogram call and return operations are together called subprogram linkage.
ISBN Chapter 12 Support for Object-Oriented Programming.
Lec. Waleed Bin Shahid.  You might have noticed a lot of issues related to software implementation.  The ultimate requirement of developer(s) is to.
Records type city is record -- Ada Name: String (1..10); Country : String (1..20); Population: integer; Capital : Boolean; end record; struct city { --
Language-Based Security: Overview of Types Deepak Garg Foundations of Security and Privacy October 27, 2009.
Object Lifetime and Pointers
Data Types In Text: Chapter 6.
CMSC 345 Defensive Programming Practices from Software Engineering 6th Edition by Ian Sommerville.
Module 30 (Unix/Linux Security Issues II)
Ik-Soon Kim December 18, 2010 Embedded Software Platform Team
Memory Allocation CS 217.
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.
Cyclone: A safe dialect of C
Programming Languages
Dynamic Memory.
Presentation transcript:

Two alternatives of C: Cyclone and Vault Keami Hung February 01, 2007

Cited Sources T.Jim, G.Morrisett, D.Grossman, M.Hicks, J.Cheney and Y.Wang. “Cyclone: A Safe Dialect of C”. Usenix Annual Technical Conference, pages , Monterey, CA, June R.DeLine and M.Fahnrich. “Vault: A Programming Language for Reliable Systems”. T.Jim, G.Morrisett, D.Grossman, M.Hicks, J.Cheney and Y.Wang. “Cyclone”.. Wikipedia. “C Programming Language”.. Wikipedia. “Northeast Blackout of Causes”..

C Programming Language Since its first appearance 1972, C has become one of the most widely used programming languages in the world. More lines has been written in C than in any other languages, perhaps except Fortran. (and maybe Java in the next years?) Influenced languages like C++, C#, Java and D.

C Programming Language Low-level imperative language, with simple and elegant coding and syntax. Give programmers maximum control of hardware, memory management, and data layout over stack and heap. Highly efficient. Low-overhead runtime. Critical in computer infrastructure like OS, servers, networking software, database and distributed systems.

C Programming Language Pointer  the most fundamental feature which helps data layout and dynamic memory allocation  the most vulnerable feature from which many security hazards emerge Dangling references Null-pointer dereferences Illegal data type accesses Memory leaks......

C Programming Language From these vulnerabilities in language structure and syntax, security loopholes are exploited for malicious purpose.  Out-of-bound access --> buffer/stack/array overflow  Illegal memory addressing and access  Weak typing --> illegal type assignment  Format Strings Attack ......

An Example Remember the massive-scale blackout throughout northeast US and eastern Canada in August 2003? The ultimate cause of the whole accident is a race condition bug in one of the control centers’ Unix-based OS in the GE Energy XA/21 system, which stalls the electricity alarming system.

Is Java a good alternative? Java eliminates most of the vulnerabilities as well as the features essential for low-level programming (e.g. pointers). Programmer has no direct control over data layout and memory allocation. Everything is handled by the JVM. Java program is interpreted and run on JVM, making it comparatively inefficient to C, especially in OS and networking infrastructures.

Goal To create a safe and secure programming language while maintaining the syntax, semantics, features and low-level accessibility of C, if possible.

Checkers / Dialects of C D SCC (Safe C Compiler) Fail-Safe C CCured Cyclone Vault LINT LCLint SLAM Metal

Cyclone A safe dialect of C “A design from the ground up to prevent buffer overflows, format string attacks, memory management errors that are common in C programs, while retaining C’s syntax and semantics.” Safety is guaranteed and default rather than additive. When control is required, it will be given as needed.

Cyclone Structure Parser Static Analyzer Translator to ANSI C GNU gcc MS Visual C++ Cyclone code exe

Cyclone Pointers To prevent buffer overflow vulnerability, null-pointer and pointer arithmetic are restricted. Three types of pointers:  * : typical pointer Pointer arithmetic is prohibited NULL checks enabled : Never-NULL pointer Pointer arithmetic is prohibited NULL checks disabled (since guaranteed to be initialized)  ? : Bound Check pointer Pointer arithmetic allowed A “fat pointer” which can determine the size of array / data.

Cyclone Region Analysis To prevent dangling pointers and illegal data access from pointer variables, Cyclone’s analyzer performs region analysis to detect dereference of a pointer to a region of data that is already deallocated. A region is a segment of memory that is deallocated together. (e.g. local variables in a function) If violation is detected, a compile-time error is reported. With this, functions like strcpy, strcat can no longer be overwritten to create buffer overflows.

Cyclone Growable Regions In C, free is a function that does the opposite of malloc – deallocate the variable and free up the memory space currently pointed by the stack pointer. free is too dangerous as an operation, since it can create dangling references, segmentation fault and even root compromises (if it’s accidentally used to free up the same block of memory twice). In Cyclone, free is a no-op. Then how can we reclaim heap-allocated data?

Cyclone Growable Regions A growable region is used to keep track of the variables declared and allocated within it. Each variable declared within the region is given a handle of the region to keep track of which region it points to. Upon exit of the region, the variables will be deallocated altogether and memory space freed. A safe version of arena-style memory management.

Cyclone Tagged Unions To prevent format string attack, a tagged union feature is used to ensure the correct type and format of input data to a function (like printf). A C union is a structure that multiple data types of variable share the same memory space. For convenience, automatic tag injection is provided for common C functions like printf, scanf, fcntl, ioctl, signal, bind, connect …… etc.

Cyclone’s Other Special Features To prevent dangling references, a goto function that jumps to a scope other than its own will be detected and reported as compile-time error Other features include:  Restrictions of void * return type  Restrictions of bad casting  Restrictions of improper unions  Compulsory return statements  Exceptions in place of setjmp and longjmp

Cyclone Performance In general, Cyclone gives a decent performance compared to C, given its highly improved safety and occasional, but not frequency, overheads. The benchmark test show that the difference of lines of code between C and Cyclone is little. Cyclone has very slighly more codes than C. During the compilation, even some safety violations are discovered among three benchmarks that are widely used in system programming, and subsequently fixed.

Cyclone Performance Even with garbage collector option and bound check option enabled, in general, Cyclone did not incur much runtime overhead on benchmarks. In most benchmarks, the Cyclone program shows slightly slower result than those in C. The greatest slowdown is a factor of 3. The slowest benchmarks are those with computationally- intensive operations involving frequent bound checks and ? (the “fat”) pointers.

Example 1 void func (char *str) { char buffer[16]; strcpy (buffer, str); // ERROR! } void main() { char large_string[256]; int i; for (i=0; i < 255; i++) large_string[i] = 'A'; func (large_string); }

Example 2 void func (int a, int b, int c) { char buffer1[5]; char buffer2[10]; int *ret; // Get the address of the word containing the return address. ret = buffer1 + 12; // Make it skip an entire instruction. (*ret) += 8;// ERROR! } void main() { int x; x = 0; func (1,2,3); x = 1; // This will be skipped. printf ("%d\n", x); // Prints 0 }

Vault “A safe version of the C programming language, being developed at Microsoft Research, which provides the same level of safety as languages like C#, but allows a programmer to retain control over data layout and lifetime.”

Vault Features Unlike Cyclone, which target on certain features that cause the common security attacks, Vault modified a wide range of features. Most of the modifications are higher level, concerning functions, constructs, variants and aggregate types. Vault also brought in some concepts of object oriented programming, like modules and generics.

Vault Features Every variable must be initialized when declared. Compared to C, Vault is a type-safe language, and prohibit casts between arbitrary types.

Vault Aggregation Tuple (bool, int, string) mytuple = (false, 3, "hello"); Inner struct, outer struct, and flat struct inner { int i; float f; } struct outer { char c; flat inner s; }

Vault Module and Interface The most important and frequent feature in Vault. A collection of type, variable, and function definitions. Declaration of inner and outer modules like structs. Resemble a simple class object. Encapsulation by using the static keyword when declaring variables or functions inside the module.

Vault Interface Provides encapsulation and information hiding, like what a C header file does. Acts as a contract between a module implementation and a module client. A module can than claim (or adopt) an interface and implement the details.

Advantages of Cyclone Improved Security Easy to learn, port and use Fast and efficient in general Translatable back to C code Fewer modifications over all language features

Disadvantages of Cyclone Pointer operation, involving three pointers, can be very confusing and difficult to master. Considerable slowdown on some computationally- intensive programs. Some common practices for C programmers, like pointer arithmetic, are much restricted. (But usually other ways are available)

Advantages of Vault Improved Security. Modularization  Helpful to large scale programming / Software development. Take advantage of object oriented programming paradigm thru generics, modules and interfaces.

Disadvantages of Vault Less focused on prevailing security issues. Less focused on low-level programming. Much more complicated than Cyclone, with lots of new features and keywords.

The End