Current Techniques in Language-based Security David Walker COS 441 With slides stolen from: Steve Zdancewic University of Pennsylvania.

Slides:



Advertisements
Similar presentations
Towards Remote Policy Enforcement for Runtime Protection of Mobile Code Using Trusted Computing Xinwen Zhang Francesco Parisi-Presicce Ravi Sandhu
Advertisements

1 Copyright © 2005, Oracle. All rights reserved. Introducing the Java and Oracle Platforms.
© 2003 School of Computing, University of Leeds SY32 Secure Computing, Lecture 16 Secure Coding in Java and.NET Part 1: Fundamentals.
Mobile Code Security Yurii Kuzmin. What is Mobile Code? Term used to describe general-purpose executables that run in remote locations. Web browsers come.
Current Techniques in Language-based Security David Walker COS 597B With slides stolen from: Steve Zdancewic University of Pennsylvania.
Current Techniques in Language-based Security David Walker COS 597B With slides stolen from: Steve Zdancewic University of Pennsylvania.
Java security (in a nutshell)
Applet Security Gunjan Vohra. What is Applet Security? One of the most important features of Java is its security model. It allows untrusted code, such.
Java Security CS-328. JDK 1.0 Security Model Sandbox Java Virtual Machine Local Code Remote Code Local Host System Resources (File System, Sockets, Printers…)
Java Security. Overview Hermetically Sealed vs. Networked Executable Content (Web Pages & ) Java Security on the Browser Java Security in the Enterprise.
Mobile Code Security Aviel D. Rubin, Daniel E. Geer, Jr. MOBILE CODE SECURITY, IEEE Internet Computing, 1998 Minkyu Lee
An Introduction to Proof-Carrying Code David Walker Princeton University (slides kindly donated by George Necula; modified by David Walker)
The Design and Implementation of a Certifying Compiler [Necula, Lee] A Certifying Compiler for Java [Necula, Lee et al] David W. Hill CSCI
Attacking Malicious Code: A Report to the Infosec Research Council Kim Sung-Moo.
Java Security Model Lab#1 I. Omaima Al-Matrafi. Safety features built into the JVM Type-safe reference casting Structured memory access (no pointer arithmetic)
LAB#2 JAVA SECURITY OVERVIEW Prepared by: I.Raniah Alghamdi.
Current Techniques in Language- based Security Steve Zdancewic University of Pennsylvania.
1 Extensible Security Architectures for Java Authors: Dan S.Wallch, Dirk Balfanz Presented by Moonjoo Kim.
CSE331: Introduction to Networks and Security Lecture 28 Fall 2002.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
Applications of Programming Language Theory: Java Security David Walker COS 441 With slides stolen from: Steve Zdancewic University of Pennsylvania.
Information Flow, Security and Programming Languages Steve Steve Zdancewic.
Prepared By E.Musa Alyaman1 Chapter 2 The Java Overview.
Principles of Object-Oriented Software Development The language Java.
Static Enforcement of Security with Types Christian Skalka and Scott Smith Johns Hopkins University.
JVM-1 Introduction to Java Virtual Machine. JVM-2 Outline Java Language, Java Virtual Machine and Java Platform Organization of Java Virtual Machine Garbage.
OOP #10: Correctness Fritz Henglein. Wrap-up: Types A type is a collection of objects with common behavior (operations and properties). (Abstract) types.
A Type System for Expressive Security Policies David Walker Cornell University.
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
An Approach to Safe Object Sharing Ciaran Bryce & Chrislain Razafimahefa University of Geneva, Switzerland.
Describing Syntax and Semantics
6/4/98SIGMOD'98 -- Cornell Predator Project1 Secure and Portable Database Extensibility Tobias Mayr Michael Godfrey Praveen Seshadri Thorsten von Eicken.
1 Software Testing and Quality Assurance Lecture 31 – SWE 205 Course Objective: Basics of Programming Languages & Software Construction Techniques.
Java Security Updated May Topics Intro to the Java Sandbox Language Level Security Run Time Security Evolution of Security Sandbox Models The Security.
The Impact of Programming Language Theory on Computer Security Drew Dean Computer Science Laboratory SRI International.
Java Security. Topics Intro to the Java Sandbox Language Level Security Run Time Security Evolution of Security Sandbox Models The Security Manager.
Secure Virtual Architecture John Criswell, Arushi Aggarwal, Andrew Lenharth, Dinakar Dhurjati, and Vikram Adve University of Illinois at Urbana-Champaign.
Understanding the CORBA Model. What is CORBA?  The Common Object Request Broker Architecture (CORBA) allows distributed applications to interoperate.
CS Sept CACL: Efficient Fine­Grained Protection for Objects Richardson, Schwarz, Cabrera IBM Almaden OOPSLA’92.
Lecture 10 : Introduction to Java Virtual Machine
Java Security Pingping Ma Nov 2 nd, Overview Platform Security Cryptography Authentication and Access Control Public Key Infrastructure (PKI)
Announcements Assignment 3 due. Invite friends, co-workers to your presentations. Course evaluations on Friday.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Proof Carrying Code Zhiwei Lin. Outline Proof-Carrying Code The Design and Implementation of a Certifying Compiler A Proof – Carrying Code Architecture.
1 Comp 104: Operating Systems Concepts Java Development and Run-Time Store Organisation.
Basic Security: Java vs.NET Master Seminar Advanced Software Engineering Topics Prof. Jacques Pasquier-Rocha Software Engineering Group Department of Informatics.
Java Security Nathan Moore CS 665. Overview Survey of Java Inherent Security Properties Java Runtime Environment Java Virtual Machine Java Security Model.
Java 2 security model Valentina Casola. Components of Java the development environment –development lifecycle –Java language features –class files and.
Lecture 16 Page 1 Advanced Network Security Perimeter Defense in Networks: Virtual Private Networks Advanced Network Security Peter Reiher August, 2014.
COMPUTER SECURITY MIDTERM REVIEW CS161 University of California BerkeleyApril 4, 2012.
Chapter 1 Section 1.1 Introduction to Java Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information.
SAFKASI: A Security Mechanism for Language-based Systems Dan S. Wallach Rice University Andrew W. Appel and Edward W. Felten Princeton University Excerpt.
1 cs205: engineering software university of virginia fall 2006 Forgiveness and Permissions.
A Microkernel Virtual Machine: Building Security with Clear Interfaces Xiaoqi LuScott Smith The Johns Hopkins University.
Java Security Session 19. Java Security / 2 of 23 Objectives Discuss Java cryptography Explain the Java Security Model Discuss each of the components.
The Execution System1. 2 Introduction Managed code and managed data qualify code or data that executes in cooperation with the execution engine The execution.
ITP 109 Week 2 Trina Gregory Introduction to Java.
Java & The Android Stack: A Security Analysis Pragati Ogal Rai Mobile Technology Evangelist PayPal, eBay Java.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Types for Programs and Proofs
Java security (in a nutshell)
Topic: Java Security Models
State your reasons or how to keep proofs while optimizing code
Introduction to Operating Systems
Building Systems That Flexibly Control Downloaded Executable Content
COSC Assignment 3 - Part 1 Java Security Susan Kovacs 19 April 2019 COSC Assignment 3 - Part 1.
Chap 1. Getting Started Objectives
Plug-In Architecture Pattern
Presentation transcript:

Current Techniques in Language-based Security David Walker COS 441 With slides stolen from: Steve Zdancewic University of Pennsylvania

COS 4412 Mobile Code  Modern languages like Java and C# have been designed for Internet applications and extensible systems  PDAs, Cell Phones, Smart Cards, … operating system web browser applet

COS 4413 Applet Security Problems  Protect OS & other valuable resources.  Applets should not:  crash browser or OS  execute “rm –rf /”  be able to exhaust resources  Applets should:  be able to access some system resources (e.g. to display a picture)  be isolated from each other  Principles of least privileges and complete mediation apply

COS 4414 Java and C# Security  Static Type Systems  Memory safety and jump safety  Run-time checks for  Array index bounds  Downcasts  Access controls  Virtual Machine / JIT compilation  Bytecode verification  Enforces encapsulation boundaries (e.g. private field)  Garbage Collected  Eliminates memory management errors  Library support  Cryptography, authentication, … These lectures

COS 4415 Access Control for Applets  What level of granularity?  Applets can touch some parts of the file system but not others  Applets can make network connections to some locations but not others  Different code has different levels of trustworthiness  vs.  Trusted code can call untrusted code  e.g. to ask an applet to repaint its window  Untrusted code can call trusted code  e.g. the paint routine may load a font  How is the access control policy specified?

COS 4416 Outline  Java Security Model (C# similar)  Stack inspection  Concrete examples  To discuss: what security principles does the Java security model obey or not obey?  Semantics from a PL perspective  Formalizing stack inspection  how exactly does it work?  Reasoning about programs that use stack inspection

COS 4417 Java Security Model a.class b.class c.class d.class e.class Domain A Domain B Permissions Security PolicyVM Runtime Classloader SecurityManager

COS 4418 Kinds of Permissions  java.security.Permission Class perm = new java.io.FilePermission("/tmp/abc","read"); java.security.AllPermission java.security.SecurityPermission java.security.UnresolvedPermission java.awt.AWTPermission java.io.FilePermission java.io.SerializablePermission java.lang.reflect.ReflectPermission java.lang.RuntimePermission java.net.NetPermission java.net.SocketPermission …

COS 4419 Code Trustworthiness  How does one decide what protection domain the code is in?  Source (e.g. local or applet)  Digital signatures  C# calls this “evidence based”  How does one decide what permissions a protection domain has?  Configurable – administrator file or command line  Enforced by the classloader

COS Classloaders  In order to pull new code into the virtual machine, we use an object from the ClassLoader class  A class loader will look in the file system, or across the network for a class file, or possibly dynamically generate the class  When loading the first class of an application, a new instance of the URLClassLoader is used.  When loading the first class of an applet, a new instance of the AppletClassLoader is used.  Class loaders are responsible for placing classes into their security domains  AppletClassLoader places classes in domains depending on where they are from  Other ClassLoaders places classes in domains based on digital signatures, or origin (such as local file system)

COS Classloader Hierarchy ClassLoader SecureClassLoaderURLClassLoader AppletClassLoader Primordial ClassLoader

COS Associating Privileges with Domains grant codeBase “ { permission java.io.FilePermission(“/tmp/*”, “read,write”); } grant codeBase “file://$JAVA_HOME/lib/ext/*” { permission java.security.AllPermission; } grant signedBy “trusted-company.com” { permission java.net.SocketPermission(…); permission java.io.FilePermission(“/tmp/*”, “read,write”); … } Policy information stored in: $JAVA_HOME/lib/security/java.policy $USER_HOME/.java.policy (or passed on command line)

COS Example Trusted Code void fileWrite(String filename, String s) { SecurityManager sm = System.getSecurityManager(); if (sm != null) { FilePermission fp = new FilePermission(filename,“write”); sm.checkPermission(fp); /* … write s to file filename (native code) … */ } else { throw new SecurityException(); } public static void main(…) { SecurityManager sm = System.getSecurityManager(); FilePermission fp = new FilePermission(“/tmp/*”,“write,…”); sm.enablePrivilege(fp); UntrustedApplet.run(); } Code in the System protection domain

COS Example Client class UntrustedApplet { void run() {... s.FileWrite(“/tmp/foo.txt”, “Hello!”);... s.FileWrite(“/home/dpw/grades.txt”, “Ginsburg: A+”);... } Applet code obtained from

COS Stack Inspection  Stack frames are annotated with their protection domains and any enabled privileges.  During inspection, stack frames are searched from most to least recent:  fail if a frame belonging to someone not authorized for privilege is encountered  succeed if activated privilege is found in frame

COS Stack Inspection Example main(…){ fp = new FilePermission(“/tmp/*”,“write,…”); sm.enablePrivilege(fp); UntrustedApplet.run(); } Policy Database

COS Stack Inspection Example main(…){ fp = new FilePermission(“/tmp/*”,“write,…”); sm.enablePrivilege(fp); UntrustedApplet.run(); } fp Policy Database

COS Stack Inspection Example main(…){ fp = new FilePermission(“/tmp/*”,“write,…”); sm.enablePrivilege(fp); UntrustedApplet.run(); } void run() { … s.FileWrite(“/tmp/foo.txt”, “Hello!”); … } fp Policy Database

COS Stack Inspection Example main(…){ fp = new FilePermission(“/tmp/*”,“write,…”); sm.enablePrivilege(fp); UntrustedApplet.run(); } void run() { … s.FileWrite(“/tmp/foo.txt”, “Hello!”); … } void fileWrite(“/tmp/foo.txt”, “Hello!”) { fp = new FilePermission(“/tmp/foo.txt”,“write”) sm.checkPermission(fp); /* … write s to file filename … */ fp Policy Database

COS Stack Inspection Example main(…){ fp = new FilePermission(“/tmp/*”,“write,…”); sm.enablePrivilege(fp); UntrustedApplet.run(); } void run() { … s.FileWrite(“/tmp/foo.txt”, “Hello!”); … } void fileWrite(“/tmp/foo.txt”, “Hello!”) { fp = new FilePermission(“/tmp/foo.txt”,“write”) sm.checkPermission(fp); /* … write s to file filename … */ fp Policy Database Succeed!

COS Stack Inspection Example main(…){ fp = new FilePermission(“/tmp/*”,“write,…”); sm.enablePrivilege(fp); UntrustedApplet.run(); } void run() { … s.FileWrite(“/home/dpw/grades.txt”, “Ginsburg: A+”); } fp Policy Database

COS Stack Inspection Example main(…){ fp = new FilePermission(“/tmp/*”,“write,…”); sm.enablePrivilege(fp); UntrustedApplet.run(); } void fileWrite(“…/important.txt”, “kwijibo”) { fp = new FilePermission(“important.txt”, “write”); sm.checkPermission(fp); fp Policy Database void run() { … s.FileWrite(“/home/dpw/grades.txt”, “Ginsburg: A+”); } Fail

COS Other Possibilities  The fileWrite method could enable the write permission itself  Potentially dangerous, should not base the file to write on data from the applet  … but no enforcement in Java  A trusted piece of code could disable a previously granted permission  Terminate the stack inspection early

COS Stack Inspection Algorithm checkPermission(T) { // loop newest to oldest stack frame foreach stackFrame { if (local policy forbids access to T by class executing in stack frame) throw ForbiddenException; if (stackFrame has enabled privilege for T) return; // allow access if (stackFrame has disabled privilege for T) throw ForbiddenException; } // end of stack if (Netscape || …) throw ForbiddenException; if (MS IE4.0 || JDK 1.2 || …) return; }

COS Two Implementations  On demand –  On a checkPermission invocation, actually crawl down the stack, checking on the way  Used in practice  Eagerly –  Keep track of the current set of available permissions during execution (security-passing style Wallach & Felten) + more apparent (could print current perms.) -more expensive (checkPermission occurs infrequently)

COS Stack Inspection  Stack inspection seems appealing:  Fine grained, flexible, configurable policies  Distinguishes between code of varying degrees of trust  But…  How do we understand what the policy is?  Semantics tied to the operational behavior of the program (defined in terms of stacks!)  How do we compare implementations  Changing the program (e.g. optimizing it) may change the security policy  Policy is distributed throughout the software, and is not apparent from the program interfaces.  Is it any good?

COS Stack Inspection Literature  Stack Inspection: Theory and Variants Cédric Fournet and Andrew D. Gordon  Use operational semantics like in class  Understanding Java Stack Inspection Dan S. Wallach and Edward W. Felten  Formalize Java Stack Inspection using a special logic of authentication

Formalizing Stack Inspection

COS Abstract Stack Inspection  Abstract permissions  p,q Permissions (left abstract in the theory)  R,S Principals (sets of permissions)  Hide the details of classloading, etc.  Examples: System = {fileWrite(“f1”), fileWrite(“f2”),…} Applet = {fileWrite(“f1”)}

COS sec Syntax  Language syntax: e ::= expressions xvariable x.efunction e1 e2application R{e}framed expr enable p in eenable test p then e1 else e2check perm. fail failure v ::= x | x.evalues o ::= v | failoutcome

COS Framing a Term  Models the Classloader that marks the (unframed) code with its protection domain: Load(R,x) = x Load(R, x.e)= x. R{ Load(R,e) } Load(R,e1 e2)= Load(R,e1) Load(R,e2) Load(R,enable p in e) = enable p in Load(R,e) Load(R,test p then e2 else e2) = test p then Load(R,e1) else Load(R,e2) Load(R,fail) = fail

COS Example readFile = fileName.System{ test fileWrite(fileName) then … // primitive file IO (native code) else fail } Applet{readFile “f2”} -->* fail System{readFile “f2”} -->*

COS sec Operational Semantics  Evaluation contexts: E ::= [] Hole E e Eval function v E Eval arg enable p in E Tag on stack frame R{E} Stack frame  E models the control stack

COS sec Operational Semantics E[(lx.e) v]--> E[e{v/x}] E[enable p in v]--> E[v] E[R{v}] --> E[v] E[fail] --> fail E[test p then e else f] --> E[e] if Stack(E) |-- p E[test p then e else f] --> E[f] if  (Stack(E) |-- p)

COS Example Evaluation Context Applet{readFile “f2”} E = Applet{[]} r = readfile “f2”

COS Example Evaluation Context E = Applet{[]} r = ( fileName.System{ test fileWrite(fileName) then … // primitive file IO (native code) else fail } ) “f2” Applet{readFile “f2”}

COS Example Evaluation Context Applet{readFile “f2”} E = Applet{[]} r = System{ test fileWrite(“f2”) then … // primitive file IO (native code) else fail }

COS Example Evaluation Context Applet{System{ test fileWrite(“f2”) then … // primitive file IO (native code) else fail }}

COS Example Evaluation Context Applet{System{ test fileWrite(“f2”) then … // primitive file IO (native code) else fail }} E’ = Applet{System{[]}} r’ = test fileWrite(“f2”) then … // primitive file IO (native code) else fail

COS Formal Stack Inspection E’ = Applet{System{[]}} r’ = test fileWrite(“f2”) then … // primitive file IO (native code) else fail When does stack E’ allow permission fileWrite(“f2”)? Stack(E’) |-- fileWrite(“f2”)

COS Formal Stack Inspection Structure of Stacks: s ::=. (Empty Stack) | s.R (Stack for code of principal R) | s.enable(p)(Privelege p enabled)

COS Stack of an Eval. Context Stack([]) =. Stack(E e) = Stack(E) Stack(v E) = Stack(E) Stack(enable p in E) = enable(p).Stack(E) Stack(R{E}) = R.Stack(E) Stack(E’) = Stack(Applet{System{[]}}) = Applet.Stack(System{[]}) = Applet.System.Stack([]) = Applet.System.

COS Abstract Stack Inspection. |-- p empty stack axiom s |-- p p  R s.R |-- p s |-- p s.enable(q) |-- p protection domain check p  q irrelevant enable s |= p s.enable(p) |-- p check enable

COS Abstract Stack Inspection. |= p empty stack enables all p  R x.R |= p enable succeeds x |= p x.enable(q) |= p irrelevant enable

COS Equational Reasoning e  iff there exists o such that e -->* o Let C[] be an arbitrary program context. Say that e = e’ iff for all C[], if C[e] and C[e’] are closed then C[e]  iff C[e’] .

COS Example Inequality ok = x.x loop = ( x.x x)( x.x x) (note: loop  ) f = x. let z = x ok in _.z g = x. let z = x ok in _.(x ok) Claim: f ≠ g Proof: Let C[] =  {[ ] _.test p then loop else ok} ok

COS Example Continued C[f]=  {f _.test p then loop else ok} ok   {let z = ( _.test p then loop else ok) ok in _.z} ok   {let z = test p then loop else ok in _.z} ok   {let z = ok in _.z} ok   { _.ok} ok  ( _.ok) ok  ok stack(  { [ ] }) =.. ..  |-- p is not valid

COS Example Continued C[g]=  {g _.test p then loop else ok} ok   {let z = ( _.test p then loop else ok) ok in _.(( _.test p then loop else ok) ok)} ok   {let z = test p then loop else ok in _. (( _.test p then loop else ok) ok)} ok   {let z = ok in _. (( _.test p then loop else ok) ok)} ok   { _. (( _.test p then loop else ok) ok)} ok  ( _. (( _.test p then loop else ok) ok)) ok  ( _.test p then loop else ok) ok  test p then loop else ok  loop  loop  loop  … stack([ ] ) =.. |-- p is valid! return from function ==> pop frame

COS Example Applications Eliminate redundant annotations: x.R{ y.R{e}} = x. y.R{e} Decrease stack inspection costs: e = test p then (enable p in e) else e Formal reasoning about the semantics of stack inspection makes it possible to perform safe optimizations:

COS Axiomatic Equivalence Can give a sound set of equations  that characterize =. Example axioms: ( x.e) v  e{v/x} (beta equivalence) x  fv(v)  x.v  v enable p in o  o enable p in (enable q in e)  enable q in (enable p in e) R  S  R{S{e}}  S{e} R{S{enable p in e}}  R  {p}{S{enable p in e}} … many, many more  Implies =

COS Example: Higher-order Code main = System [ h.(h ok ok)] fileHandler = System[ s. c. _.c (readFile s)] leak = Applet[ s.output s] main( _.Applet{fileHandler “f2” leak})

COS Example: Higher-order Code main( _.Applet{fileHandler “f2” leak})  *System{Applet{fileHandler “f2” leak} okS}  *System{Applet{System{System{ _.System{leak (readFile “f2”)}}}} okS}  *System{ _.System{leak (readFile “f2”)} okS}  * System{System{leak }}  * System{System{Applet{output }}}  * System{System{Applet{ok}}}  * ok

COS Other Problems  Applets returning closures can circumvent stack inspection.  Possible solution:  Values of the form: R{v} (i.e. keep track of the protection domain of the source)  Similarly, one could have closures capture their current security context  Integrity analysis (i.e. where data comes from)  Fournet & Gordon prove some properties of strengthened versions of stack inspection.

COS Conclusions  What security properties does the Java security model guarantee?  What optimizations are legal?  Formal semantics helps us find the answers & suggests improvements