Docsity

Java Security - Lecture Slides - Program and Data Representation | CS 2150, Study notes of Computer Science

Toggle sidebar
bg1
1
CS216: Program and Data Represe ntation
University of Virginia Computer Science
Spring 2006 David Evans
Lecture 19:
Java Security
http://www.cs.virginia.edu/cs216
PS6 Submission:
Only to be eligible
for the “Byte Code
Wizard” awards. If
the web submission is
down, you can submit
(once) by email.
2
UVa CS216 Spring 2006 -Le cture 19: Java Security
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
.method public static main([Ljava/lang/String;)V
…
iconst_2
istore_0
aload_0
iconst_2
iconst_3
iadd
…
return
.end method
> java –noverify Simple
result: 5
3
UVa CS216 Spring 2006 -Le cture 19: Java Security
Running Mistyped Code
> java –noverify Simple
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION
(0xc0000005) occurred at PC=0x809DCEB
Function=JVM_FindSignal+0x1105F
Library=C:\j2sdk1.4.2\jre\bin\client\jvm.dll
Current Java thread:
at Simple.main(Simple.java:7)
…
#
# HotSpot Virtual Machine Error : EXCEPTION_ACCESS_VIOLATION
# Error ID : 4F530E43505002EF
# Please report this error at
# http://java.sun.com/cgi-bin/bugreport.cgi
#
# Java VM: Java HotSpot(TM) Client VM (1.4.2-b28 mixed mode)
.method public static main([Ljava/lang/String;)V
…
ldc 216
istore_0
aload_0
iconst_2
iconst_3
iadd
…
.end method
4
UVa CS216 Spring 2006 -Le cture 19: Java Security
Java Security Architecture
Java VM
Operating System
Protected Resource
ClassLoader
Security
exception
Verify
Exception
JAR
Class
Verifier
5
UVa CS216 Spring 2006 -Le cture 19: Java Security
JavaVM
• Interpreter for JVML programs
• Has complete access to host machine:
its just a C program running normally
• Bytecode verifier ensures some safety
properties, JavaVM must ensure rest:
– Type safety of run-time casts, array
assignments
– Memory safety: array bounds checking
–Resource use policy
6
UVa CS216 Spring 2006 -Le cture 19: Java Security
Reference Monitors
pf3
pf4
pf5

Partial preview of the text

Download Java Security - Lecture Slides - Program and Data Representation | CS 2150 and more Study notes Computer Science in PDF only on Docsity!

CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans

Lecture 19:

Java Security

http://www.cs.virginia.edu/cs

PS6 Submission: Only to be eligible for the “Byte Code Wizard” awards. If the web submission is down, you can submit (once) by email.

UVa CS216 Spring 2006 - Lecture 19: Java Security 2

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

.method public static main([Ljava/lang/String;)V … iconst_ istore_ aload_ iconst_ iconst_ iadd … return .end method

> java –noverify Simple result: 5

UVa CS216 Spring 2006 - Lecture 19: Java Security 3

Running Mistyped Code

> java –noverify Simple Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at PC=0x809DCEB Function=JVM_FindSignal+0x1105F Library=C:\j2sdk1.4.2\jre\bin\client\jvm.dll Current Java thread: at Simple.main(Simple.java:7) …

HotSpot Virtual Machine Error : EXCEPTION_ACCESS_VIOLATION

Error ID : 4F530E43505002EF

Please report this error at

http://java.sun.com/cgi-bin/bugreport.cgi

Java VM: Java HotSpot(TM) Client VM (1.4.2-b28 mixed mode)

.method public static main([Ljava/lang/String;)V … ldc 216 istore_ aload_ iconst_ iconst_ iadd … .end method

UVa CS216 Spring 2006 - Lecture 19: Java Security 4

Java Security Architecture

Java VM Operating System Protected Resource

ClassLoader

Security exception

Verify Exception

JAR

Class

Verifier

UVa CS216 Spring 2006 - Lecture 19: Java Security 5

JavaVM

  • Interpreter for JVML programs
  • Has complete access to host machine:

its just a C program running normally

  • Bytecode verifier ensures some safety

properties, JavaVM must ensure rest:

  • Type safety of run-time casts, array assignments
  • Memory safety: array bounds checking
  • Resource use policy

UVa CS216 Spring 2006 - Lecture 19: Java Security 6

Reference Monitors

UVa CS216 Spring 2006 - Lecture 19: Java Security 7

Program Execution

Monitor Program Speakers

SuperSoaker 2000 Disk (^) Memory

Network

UVa CS216 Spring 2006 - Lecture 19: Java Security 8

Program Execution

Monitor Program Speakers

SuperSoaker 2000 Disk (^) Memory

Network

Reference Monitor

UVa CS216 Spring 2006 - Lecture 19: Java Security 9

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...

UVa CS216 Spring 2006 - Lecture 19: Java Security 10

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

Real

most things

limited

UVa CS216 Spring 2006 - Lecture 19: Java Security 11

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

UVa CS216 Spring 2006 - Lecture 19: Java Security 12

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

UVa CS216 Spring 2006 - Lecture 19: Java Security 19

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

UVa CS216 Spring 2006 - Lecture 19: Java Security 20

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

UVa CS216 Spring 2006 - Lecture 19: Java Security 21

What can go wrong?

  • Java API doesn’t call right

SecurityManager checks (63 calls in

java.*)

  • Font loading bug, synchronization
  • ClassLoader is tricked into loading

external class as internal

  • Bug in Bytecode Verifier can be

exploited to circumvent SecurityManager

  • Policy is too weak (allows damaging

behavior)

UVa CS216 Spring 2006 - Lecture 19: Java Security 22

Example Vulnerability

  • Object Creation involves three steps: new – create new object reference dup – duplicate reference invokespecial <> – calls constructor

new #14 dup invokespecial #15

UVa CS216 Spring 2006 - Lecture 19: Java Security 23

Object Initialization Vulnerability [lsd-pl.net] class LSDbug extends SecurityClassLoader { public LSDbug() { try { LSDbug(5); } catch (SecurityException e) { this.loadClass(…); } } public LSDbug (int x) { super(); // throws Security Exception } }

this is used, but not property initialized! Bytecode verifier (old version) didn’t make correct checks

UVa CS216 Spring 2006 - Lecture 19: Java Security 24

Verifier (should be) Conservative

JVML programs

Safe programs

Verifiable programs

(Slide from Nate Paul’s ACSAC talk)

UVa CS216 Spring 2006 - Lecture 19: Java Security 25

Complexity Increases Risk

JVML programs

Safe programs

Verifiable programs

Bug (Slide from Nate Paul’s ACSAC talk) UVa CS216 Spring 2006 - Lecture 19: Java Security 26

Vulnerabilities in JavaVM

0

5

10

15

20

25

30

35

40

45

0 1 2 3 4 5 6 7 8 9

Vulnerabilities Reported

July 1996 Years Since First Release July 2005

UVa CS216 Spring 2006 - Lecture 19: Java Security 27

Where are They?

API bugs 10

DoS attacks (crash, consumption) 5

Configuration 4

Missing policy checks 3

Other or unknown 2

Class loading 8

Verification 12

several of these were because of jsr complexity UVa CS216 Spring 2006 - Lecture 19: Java Security 28

Summary:

Low-level vs. Policy Security

  • Low-level Code Safety:
    • Type safety, memory safety, control flow safety
    • Needed to prevent malcode from circumventing any policy mechanism
  • Policy Security:
    • Control access and use of resources (files, network, display, etc.)
    • Enforced by Java class
    • Hard part is deciding on a good policy

UVa CS216 Spring 2006 - Lecture 19: Java Security 29

Charge

  • PS6 due Monday
    • Questions 8-10 are open ended
    • Lots of improvements possible, but don’t need to find everything
    • Token prize for best solutions to #8 and #10 (and title of Byte Code Wizard!)
  • Next class:
    • How a hair dryer can break all this
    • Starting with x86 assembly