Class 20: Verifying Bytecodes Fall 2010 UVa David Evans cs2220: Engineering Software Image: Joseph Featherston.

Slides:



Advertisements
Similar presentations
Operating Systems Components of OS
Advertisements

Mobile Code Security Yurii Kuzmin. What is Mobile Code? Term used to describe general-purpose executables that run in remote locations. Web browsers come.
Chapter 16 Java Virtual Machine. To compile a java program in Simple.java, enter javac Simple.java javac outputs Simple.class, a file that contains bytecode.
Compilation 2007 Code Generation Michael I. Schwartzbach BRICS, University of Aarhus.
Cs2220: Engineering Software Class 4: Specifying Procedures Fall 2010 University of Virginia David Evans.
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.
1 1 Lecture 14 Java Virtual Machine Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
Mobile Code Security Aviel D. Rubin, Daniel E. Geer, Jr. MOBILE CODE SECURITY, IEEE Internet Computing, 1998 Minkyu Lee
Lab Information Security Using Java (Review) Lab#0 Omaima Al-Matrafi.
Lab#1 (14/3/1431h) Introduction To java programming cs425
Security: Lessons Learned and Missed from Java Nathanael Paul David Evans University of Virginia ACSAC 2004.
CSE331: Introduction to Networks and Security Lecture 28 Fall 2002.
JVM-1 Introduction to Java Virtual Machine. JVM-2 Outline Java Language, Java Virtual Machine and Java Platform Organization of Java Virtual Machine Garbage.
Chapter 16 Java Virtual Machine. To compile a java program in Simple.java, enter javac Simple.java javac outputs Simple.class, a file that contains bytecode.
29-Jun-15 Java Concurrency. Definitions Parallel processes—two or more Threads are running simultaneously, on different cores (processors), in the same.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
Session-02. Objective In this session you will learn : What is Class Loader ? What is Byte Code Verifier? JIT & JAVA API Features of Java Java Environment.
Lecture 1: Overview of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++ Designed.
Java Security Updated May Topics Intro to the Java Sandbox Language Level Security Run Time Security Evolution of Security Sandbox Models The Security.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 18: 0xCAFEBABE (Java Byte Codes)
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
Java Security. Topics Intro to the Java Sandbox Language Level Security Run Time Security Evolution of Security Sandbox Models The Security Manager.
CSC 8505 Compiler Construction IR Example: Java Bytecode (looking inside class files)
1 The Java Virtual Machine Yearly Programming Project.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 19: Security in Java Real or.
Java Introduction Lecture 1. Java Powerful, object-oriented language Free SDK and many resources at
Java Bytecode What is a.class file anyway? Dan Fleck George Mason University Fall 2007.
Announcements Assignment 3 due. Invite friends, co-workers to your presentations. Course evaluations on Friday.
1 Introduction to JVM Based on material produced by Bill Venners.
Roopa.T PESIT, Bangalore. Source and Credits Dalvik VM, Dan Bornstein Google IO 2008 The Dalvik virtual machine Architecture by David Ehringer.
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.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
1 cs205: engineering software university of virginia fall 2006 Forgiveness and Permissions.
Computer Programming 2 Why do we study Java….. Java is Simple It has none of the following: operator overloading, header files, pre- processor, pointer.
Comparing Java and.Net Security: Lessons Learned and Missed - Nathanael Paul, David Evans Presented by Dan Frohlich.
Legion - A Grid OS. Object Model Everything is object Core objects - processing resource– host object - stable storage - vault object - definition of.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Policy-Directed Code Safety David Evans April 1999 Software Devices and Systems MIT Lab for Computer Science.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 18: Code Safety and Virtual Machines
David Evans CS588: Security and Privacy University of Virginia Computer Science Lecture 18: Malcode Countermeasures.
1 cs205: engineering software university of virginia fall 2006 Image from GoldenBlue LLC. Hair-Dryer Attacks.
UNDER THE HOOD: THE JAVA VIRTUAL MACHINE II CS2110 Fall 200 Lecture 25 1.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 10: Programming Exceptionally.
David Evans CS588: Cryptography University of Virginia Computer Science Lecture 21: Countering Malicious Code.
Cs205: engineering software university of virginia fall 2006 Programming Exceptionally David Evans
Lecture 4 Page 1 CS 111 Online Modularity and Memory Clearly, programs must have access to memory We need abstractions that give them the required access.
RealTimeSystems Lab Jong-Koo, Lim
1 cs205: engineering software university of virginia fall 2006 Running Untrustworthy Code Project team requests: extended until 11pm tonight.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Lecture 1: Introduction to JAVA
CS216: Program and Data Representation
Java security (in a nutshell)
Introduction Enosis Learning.
Topic: Java Security Models
Modularity and Memory Clearly, programs must have access to memory
Introduction Enosis Learning.
CS216: Program and Data Representation
Lecture 18: Java™ Decaffeinated CS551: Security and Privacy
Java Byte Codes (0xCAFEBABE) cs205: engineering software
Security in Java Real or Decaf? cs205: engineering software
Lecture 19: 0xCAFEBABE (Java Byte Codes) CS201j: Engineering Software
Byte Code Verification
Units with – James tedder
Units with – James tedder
Lecture 17: Defeating Malcode (Shameless Self-Promotion) Background
COSC Assignment 3 - Part 1 Java Security Susan Kovacs 19 April 2019 COSC Assignment 3 - Part 1.
Class 16: Concurrency Rules
Java Concurrency 29-May-19.
Presentation transcript:

Class 20: Verifying Bytecodes Fall 2010 UVa David Evans cs2220: Engineering Software Image: Joseph Featherston

Plan for Today Project Ideas Low-level security: “Type Safety” Trusted Computing Base (Voting) High-level security: Policy Project Teams James Blanton, Sam Herder, Michael Kalish Jeremy Brown, Klaus Dollhopf, Joseph Featherston, Charles Hern, John Marion Joseph Borja, Erik Lopez, Brian Noh, Jonathan DiLorenzo Jiamin Chen, Elisabeth Sparkman, Yixin Sun Michael Dewey-Vogt Hanna Oh Alex Wallace

Recap: Java Platform javac Compiler malcode.java Java Source Code malcode.class JVML Object Code JavaVM Alice User Bytecode Verifier if OK

JVML Instruction Set pushing constants20getstatic, putstatic2 loads, stores66 newarray, anewarray, multianewarray,arraylength 4 pop, dup, swap, etc.9invoke methods, throw5 arithmetic37new1 conversion (e.g., i2l)15getfield, putfield2 comparisons (lcmp)5checkcast1 goto, jsr, goto_w, jsr_w, ret5instanceof1 tableswitch, lookupswitch2monitorenter, monitorexit2 returns (e.g., ireturn)6wide1 conditional jumps (ifeq, ifnull, ifnonnull) 16 nop, breakpoint, unused, implementation dependent 5 (205 out of 256 possible opcodes used)

Why so many loads and stores? Instructions are typed aload load Object from variable index iload load int from variable index fload load float from variable index dload load double from variable index Minimizing class file size aload_0, aload_1, aload_2, aload_3 same for other types and stores Array loads and stores Even more types (char, boolean, short)

Bytecode Verifier Checks class file is formatted correctly Checks JVML code satisfies safety properties Simulates program execution to know types are correct, but doesn’t need to examine any instruction more than once This is what we win by having static typing!

Running Mistyped Code > java Simple Exception in thread "main" java.lang.VerifyError: (class: Simple, method: main signature: ([Ljava/lang/String;)V) Register 0 contains wrong type

Verifying Safety Properties Type safe Stack and variable slots must store and load as same type Memory safe Must not attempt to pop more values from stack than are on it Doesn’t access private fields and methods outside class implementation Control flow safe Jumps must be to valid addresses within function, or call/return

Wait a sec… from Class 6:

Making Verification Easier Class files include lots of extra information to make verification easier > javac Simple.java > javap -verbose -c Simple public class Simple extends java.lang.Object { public Simple(); /* Stack=1, Locals=1, Args_size=1 */ public static int add(int, int); /* Stack=2, Locals=2, Args_size=2 */ } Method Simple() 0 aload_0 1 invokespecial #1 4 return Method int add(int, int) 0 iload_0 1 iload_1 2 iadd 3 ireturn > javac Simple.java > javap -verbose -c Simple public class Simple extends java.lang.Object { public Simple(); /* Stack=1, Locals=1, Args_size=1 */ public static int add(int, int); /* Stack=2, Locals=2, Args_size=2 */ } Method Simple() 0 aload_0 1 invokespecial #1 4 return Method int add(int, int) 0 iload_0 1 iload_1 2 iadd 3 ireturn public class Simple { static public int add (int a, int b) { return a + b; } public class Simple { static public int add (int a, int b) { return a + b; } Even with this help there are many “correct” JVML programs that would not pass the verifier! (but every program produced by Java compiler should pass)

Trusted Computing Base javac Compiler malcode.java Java Source Code malcode.class JVML Object Code JavaVM Alice User Bytecode Verifier if OK

Project Ideas Project Teams James Blanton, Sam Herder, Michael Kalish Jeremy Brown, Klaus Dollhopf, Joseph Featherston, Charles Hern, John Marion Joseph Borja, Erik Lopez, Brian Noh, Jonathan DiLorenzo Jiamin Chen, Elisabeth Sparkman, Yixin Sun Michael Dewey-Vogt Hanna Oh Alex Wallace

Voting

What is the Trusted Computing Base for an election? “We do have people complain and say they don’t get it, I completely understand what they’re saying, but it’s not something I can control.” Sheri Iachetta, Charlottesville general registrar (on 2006 problems with voting machines displaying “James H. ‘Jim’”)

How do I know my voting equipment is accurate? Under the Code of Virginia, the State Board of Elections must approve any mechanical or electronic voting system or equipment before it can be used by any locality. Each system must successfully complete three distinct levels of testing: 1.Qualification testing (testing of hardware and software that may be conducted by Independent Testing Authority); 2.Certification testing (to ensure it meets all applicable requirements of the Code of Virginia); and, 3.Acceptance testing (conducted by the locality to assure it meets their needs and is identical to the certified system). How do I know my voting equipment is accurate? Under the Code of Virginia, the State Board of Elections must approve any mechanical or electronic voting system or equipment before it can be used by any locality. Each system must successfully complete three distinct levels of testing: 1.Qualification testing (testing of hardware and software that may be conducted by Independent Testing Authority); 2.Certification testing (to ensure it meets all applicable requirements of the Code of Virginia); and, 3.Acceptance testing (conducted by the locality to assure it meets their needs and is identical to the certified system).

“Independent” Testing Done by ITAs paid by vendors No vulnerability analysis No source code analysis “Program testing can be used to show the presence of bugs, but never to show their absence!” Edsger W. Dijkstra

How could we design elections with smaller Trusted Computing Base? Optical Scan ballots Can be recounted by humans

Project Ideas Project Teams James Blanton, Sam Herder, Michael Kalish Jeremy Brown, Klaus Dollhopf, Joseph Featherston, Charles Hern, John Marion Joseph Borja, Erik Lopez, Brian Noh, Jonathan DiLorenzo Jiamin Chen, Elisabeth Sparkman, Yixin Sun Michael Dewey-Vogt Hanna Oh Alex Wallace

Java Applet Security

Program Execution Program Monitor Speakers SuperSoaker 2000 Disk Memory Network

Program Execution Program Monitor Speakers SuperSoaker 2000 Disk Memory Network Reference Monitor

Ideal Reference Monitor 1.Sees everything a program is about to do before it does it 2.Can instantly and completely stop program execution (or prevent action) 3.Has no other effect on the program or system Can we build this? Probably not unless we can build a time machine...

Ideal Reference Monitor 1.Sees everything a program is about to do before it does it 2.Can instantly and completely stop program execution (or prevent action) 3.Has no other effect on the program or system

Operating Systems Provide reference monitors for most security- critical resources – When a program opens a file in Unix or Windows, the OS checks that the principal running the program can open that file Doesn’t allow different policies for different programs No flexibility over what is monitored – OS decides for everyone – Hence, can’t monitor inexpensive operations

Java Security Manager (Non-Ideal) Reference monitor – Limits how Java executions can manipulate system resources User/host application creates a subclass of SecurityManager to define a policy

JavaVM Policy Enforcment From java.io.File: public boolean delete() { SecurityManager security = System.getSecurityManager(); if (security != null) { security.checkDelete(path); } if (isDirectory()) return rmdir0(); else return delete0(); } [JDK 1.0 – JDK 1.1] What could go seriously wrong with this?! checkDelete throws a SecurityExecption if the delete would violate the policy (re- thrown by delete)

HotJava’s Policy (JDK 1.1.7) public class AppletSecurity extends SecurityManager {... public synchronized void checkDelete(String file) throws Security Exception { checkWrite(file); }

AppletSecurity.checkWrite (some exception handling code removed) public synchronized void checkWrite(String file) { if (inApplet()) { if (!initACL) initializeACLs(); String realPath = (new File(file)).getCanonicalPath(); for (int i = writeACL.length ; i-- > 0 ;) { if (realPath.startsWith(writeACL[i])) return; } throw new AppletSecurityException ("checkwrite", file, realPath); } Note: no checking if not inApplet! Very important this does the right thing.

inApplet boolean inApplet() { return inClassLoader(); } Inherited from java.lang.SecurityManager: protected boolean inClassLoader() { return currentClassLoader() != null; }

currentClassLoader /** Returns an object describing the most recent class loader executing on the stack. Returns the class loader of the most recent occurrence on the stack of a method from a class defined using a class loader; returns null if there is no occurrence on the stack of a method from a class defined using a class loader. */ protected native ClassLoader currentClassLoader();

Recap java.io.File.delete calls SecurityManager.checkDelete before deleting HotJava overrides SecurityManager with AppletSecurity to set policy AppletSecurity.checkDelete calls AppletSecurity.checkWrite AppletSecurity.checkWrite checks if any method on stack has a ClassLoader If not, no checks; if it does, checks ACL list

JDK 1.0 Trust Model When JavaVM loads a class from the CLASSPATH, it has no associated ClassLoader (can do anything) When JavaVM loads a class from elsewhere (e.g., the web), it has an associated ClassLoader

JDK Evolution JDK 1.1: Signed classes from elsewhere and have no associated ClassLoader JDK 1.2: – Different classes can have different policies based on ClassLoader – Explict enable/disable/check privileges – SecurityManager is now AccessController

Policy and Mechanism AccessController provides a mechanisms for enforcing a security policy – Can insert checking code before certain operations are allowed A security policy determines what the checking code allows

Android Permissions

Charge Only ask for the Brick permission if you really need it! Only grant the Brick permission to code that you really trust! “It’s better to beg forgiveness than ask permission.” Grace Hopper (Applies to most things, but not Java applets.)