Laurent Hubert and David Pichardie INRIA Rennes, France
FMCO 2010
COST Action IC0701 Session
30 November 2010
ANALYZING JAVA WITH THE SAWJA FRAMEWORK
FROM RESEARCH SPECIFICATIONS TO REALISTIC TOOLS
1 Tuesday, November 30, 2010
ANALYZING JAVA WITH THE SAWJA FRAMEWORK F ROM RESEARCH - - PowerPoint PPT Presentation
ANALYZING JAVA WITH THE SAWJA FRAMEWORK F ROM RESEARCH SPECIFICATIONS TO REALISTIC TOOLS Laurent Hubert and David Pichardie INRIA Rennes, France FMCO 2010 COST Action IC0701 Session 30 November 2010 Tuesday, November 30, 2010 1 Static
COST Action IC0701 Session
1 Tuesday, November 30, 2010
2 Tuesday, November 30, 2010
3 Tuesday, November 30, 2010
class Point{ _x,_y; Point( x, y){ _x = x; _y = y; } equal( p){...} }
3 Tuesday, November 30, 2010
class Point{ _x,_y; Point( x, y){ _x = x; _y = y; } equal( p){...} } Float int int Point boolean
3 Tuesday, November 30, 2010
class Point{ _x,_y; Point( x, y){ _x = x; _y = y; } equal( p){...} } Float int int Point
boolean
3 Tuesday, November 30, 2010
class Point{ _x,_y; Point( x, y){ _x = x; _y = y; } equal( p){...} } Float int int Point
boolean
3 Tuesday, November 30, 2010
class Point{ _x,_y; Point( x, y){ _x = x; _y = y; } equal( p){...} } @NonNull Float int int @overrides Point
boolean
3 Tuesday, November 30, 2010
class Point{ _x,_y; Point( x, y){ _x = x; _y = y; } equal( p){...} } @NonNull Float int int @overrides Point
!"#$"% &'()*+$&,
boolean
$"'$1%#0%,
3 Tuesday, November 30, 2010
4 Tuesday, November 30, 2010
4 Tuesday, November 30, 2010
4 Tuesday, November 30, 2010
Exceptions Lazy class loading Interfaces ...
4 Tuesday, November 30, 2010
Formal specification and proof Prototype
Exceptions Lazy class loading Interfaces ...
4 Tuesday, November 30, 2010
Prototype
Exceptions Lazy class loading Interfaces ...
4 Tuesday, November 30, 2010
5 Tuesday, November 30, 2010
Did you ever look at the method resolution specification ?
6 Tuesday, November 30, 2010
7 Tuesday, November 30, 2010
type opcode = | OpNop | OpAConstNull | OpIConst of int32 | OpLConst of int64 | OpFConst of float | OpDConst of float | OpBIPush of int | OpSIPush of int | OpLdc1 of int | OpLdc1w of int | OpLdc2w of int | OpLoad of jvm_basic_type * int | OpALoad of int | OpArrayLoad of [ `Double | `Float | `Int | `Long ] | OpAALoad | OpBALoad | OpCALoad | OpSALoad | OpStore of jvm_basic_type * int | OpAStore of int | OpArrayStore of [ `Double | `Float | `Int | `Long ] | OpAAStore | OpBAStore | OpCAStore | OpSAStore | OpPop | OpPop2 | OpDup | OpDupX1 | OpDupX2 | OpDup2 | OpDup2X1 | OpDup2X2 | OpSwap | OpAdd of jvm_basic_type | OpSub of jvm_basic_type | OpMult of jvm_basic_type | OpDiv of jvm_basic_type | OpRem of jvm_basic_type | OpNeg of jvm_basic_type | OpIShl | OpLShl | OpIShr | OpLShr | OpIUShr | OpLUShr | OpIAnd | OpLAnd | OpIOr | OpLOr | OpIXor | OpLXor | OpIInc of int * int | OpI2L | OpI2F | OpI2D | OpL2I | OpL2F | OpL2D | OpF2I | OpF2L | OpF2D | OpD2I | OpD2L | OpD2F | OpI2B | OpI2C | OpI2S | OpLCmp | OpFCmpL | OpFCmpG | OpDCmpL | OpDCmpG | OpIfEq of int | OpIfNe of int | OpIfLt of int | OpIfGe of int | OpIfGt of int | OpIfLe of int | OpICmpEq of int | OpICmpNe of int | OpICmpLt of int | OpICmpGe of int | OpICmpGt of int | OpICmpLe of int | OpACmpEq of int | OpACmpNe of int | OpGoto of int | OpJsr of int | OpRet of int | OpTableSwitch of int * int32 * int32 * int array | OpLookupSwitch of int * (int32 * int) list | OpReturn of jvm_basic_type | OpAReturn | OpReturnVoid | OpGetStatic of int | OpPutStatic of int | OpGetField of int | OpPutField of int | OpInvokeVirtual of int | OpInvokeNonVirtual of int | OpInvokeStatic of int | OpInvokeInterface of int * int | OpNew of int | OpNewArray of java_basic_type | OpANewArray of int | OpArrayLength | OpThrow | OpCheckCast of int | OpInstanceOf of int | OpMonitorEnter | OpMonitorExit | OpAMultiNewArray of int * int | OpIfNull of int | OpIfNonNull of int | OpGotoW of int | OpJsrW of int | OpBreakpoint | OpInvalid
type jopcode = | OpLoad of jvm_type * int | OpStore of jvm_type * int | OpIInc of int * int | OpPop | OpPop2 | OpDup | OpDupX1 | OpDupX2 | OpDup2 | OpDup2X1 | OpDup2X2 | OpSwap | OpConst of [ `ANull | `Byte of int | `Class of object_type | `Double of float | `Float of float | `Int of int32 | `Long of int64 | `Short of int | `String of string ] | OpAdd of jvm_basic_type | OpSub of jvm_basic_type | OpMult of jvm_basic_type | OpDiv of jvm_basic_type | OpRem of jvm_basic_type | OpNeg of jvm_basic_type | OpIShl | OpLShl | OpIShr | OpLShr | OpIUShr | OpLUShr | OpIAnd | OpLAnd | OpIOr | OpLOr | OpIXor | OpLXor | OpI2L | OpI2F | OpI2D | OpL2I | OpL2F | OpL2D | OpF2I | OpF2L | OpF2D | OpD2I | OpD2L | OpD2F | OpI2B | OpI2C | OpI2S | OpCmp of [ `DG | `DL | `FG | `FL | `L ] | OpIf of [ `Eq | `Ge | `Gt | `Le | `Lt | `Ne | `NonNull | `Null ] * int | OpIfCmp of [ `AEq | `ANe | `IEq | `IGe | `IGt | `ILe | `ILt | `INe ] * int | OpGoto of int | OpJsr of int | OpRet of int | OpTableSwitch of int * int32 * int32 * int array | OpLookupSwitch of int * (int32 * int) list | OpNew of class_name | OpNewArray of value_type | OpAMultiNewArray of object_type * int | OpCheckCast of object_type | OpInstanceOf of object_type | OpGetStatic of class_name * field_signature | OpPutStatic of class_name * field_signature | OpGetField of class_name * field_signature | OpPutField of class_name * field_signature | OpArrayLength | OpArrayLoad of jvm_array_type | OpArrayStore of jvm_array_type | OpInvoke of [ `Interface of class_name | `Special of class_name | `Static of class_name | `Virtual of object_type ] * method_signature | OpReturn of jvm_return_type | OpThrow | OpMonitorEnter | OpMonitorExit | OpNop | OpBreakpoint | OpInvalid
type instr = | Nop | AffectVar of var * expr | AffectArray of expr * expr * expr | AffectField of expr * class_name * field_signature * expr | AffectStaticField of class_name * field_signature * expr | Goto of int | Ifd of ([ `Eq | `Ge | `Gt | `Le | `Lt | `Ne ] * expr * expr) * int | Throw of expr | Return of expr option | New of var * class_name * value_type list * expr list | NewArray of var * value_type * expr list | InvokeStatic of var option * class_name * method_signature * expr list | InvokeVirtual of var option * expr * virtual_call_kind * method_signature * expr list | InvokeNonVirtual of var option * expr * class_name * method_signature * expr list | MonitorEnter of expr | MonitorExit of expr | MayInit of class_name | Check of check
8 Tuesday, November 30, 2010
.class
(IR, CFG computation, etc.)
9 Tuesday, November 30, 2010
.class
(IR, CFG computation, etc.)
[FMOODS'08], [PASTE'08]
9 Tuesday, November 30, 2010
.class
(IR, CFG computation, etc.)
[ESORICS'10]
[FMOODS'08], [PASTE'08]
9 Tuesday, November 30, 2010
keep
10 Tuesday, November 30, 2010
keep
10 Tuesday, November 30, 2010
keep
10 Tuesday, November 30, 2010
Object Foo Bar
An instance of Bar
keep
11 Tuesday, November 30, 2010
Object Foo Bar
allocation of an instance of Bar
An instance of Bar
keep
11 Tuesday, November 30, 2010
Object Foo Bar
call to the constructor of Bar allocation of an instance of Bar
An instance of Bar
keep
11 Tuesday, November 30, 2010
Object Foo Bar
call to the constructor of Bar call to the super constructor (Foo) allocation of an instance of Bar
An instance of Bar
keep
11 Tuesday, November 30, 2010
Object Foo Bar
call to the constructor of Bar call to the super constructor (Foo) call to the super constructor (Object) allocation of an instance of Bar
An instance of Bar
keep
11 Tuesday, November 30, 2010
Object Foo Bar
call to the constructor of Bar call to the super constructor (Foo) call to the super constructor (Object) initialization of Object allocation of an instance of Bar
An instance of Bar
keep
11 Tuesday, November 30, 2010
Object Foo Bar
call to the constructor of Bar call to the super constructor (Foo) call to the super constructor (Object) initialization of Object initialization of Foo allocation of an instance of Bar
An instance of Bar
keep
11 Tuesday, November 30, 2010
Object Foo Bar
call to the constructor of Bar call to the super constructor (Foo) call to the super constructor (Object) initialization of Object initialization of Foo initialization of Bar allocation of an instance of Bar
An instance of Bar
keep
11 Tuesday, November 30, 2010
Object Foo Bar
call to the constructor of Bar call to the super constructor (Foo) call to the super constructor (Object) initialization of Object initialization of Foo initialization of Bar allocation of an instance of Bar fully initialized
An instance of Bar
keep
11 Tuesday, November 30, 2010
An instance of Bar
call to the constructor of Bar call to the super constructor (Foo) call to the super constructor (Object) initialization of Object initialization of Foo initialization of Bar allocation of an instance of Bar fully initialized
Object Foo Bar
keep
12 Tuesday, November 30, 2010
13 Tuesday, November 30, 2010
Example of a class hierarchy Corresponding type lattice structure A B Object Init Raw Raw(A) Raw(B) Raw(Object)
Object B Raw(Object)
uninitialized partially initialized fully initialized
14 Tuesday, November 30, 2010
java.security and javax.security
15 Tuesday, November 30, 2010
java.security and javax.security
15 Tuesday, November 30, 2010
val eval_expr : LDom.t -> JBir.expr -> EDom.t
16 Tuesday, November 30, 2010
⊢ ←
val eval_expr : LDom.t -> JBir.expr -> EDom.t val cst_from_instr: JBir.instr -> LDom.t -> LDom.t
16 Tuesday, November 30, 2010
L ⊢ e.f : (p.fields f) L ⊢ x : L(x) L ⊢ null : Init
17 Tuesday, November 30, 2010
L ⊢ e.f : (p.fields f) L ⊢ x : L(x) L ⊢ null : Init
let rec eval_expr (l:LDom.t) : JBir.expr -> EDom.t = function | Field (_,cn,fs) | StaticField (cn,fs) -> let cl = PProgram.resolve_field (PProgram.Name (prog,cn)) fs in Annotations.get_field_annotation koc cl fs
17 Tuesday, November 30, 2010
L ⊢ e.f : (p.fields f) L ⊢ x : L(x) L ⊢ null : Init
let rec eval_expr (l:LDom.t) : JBir.expr -> EDom.t = function | Field (_,cn,fs) | StaticField (cn,fs) -> let cl = PProgram.resolve_field (PProgram.Name (prog,cn)) fs in Annotations.get_field_annotation koc cl fs | Var (_,x) -> LDom.get_var (JBir.index x) l
17 Tuesday, November 30, 2010
L ⊢ e.f : (p.fields f) L ⊢ x : L(x) L ⊢ null : Init
let rec eval_expr (l:LDom.t) : JBir.expr -> EDom.t = function | Field (_,cn,fs) | StaticField (cn,fs) -> let cl = PProgram.resolve_field (PProgram.Name (prog,cn)) fs in Annotations.get_field_annotation koc cl fs | Var (_,x) -> LDom.get_var (JBir.index x) l | Const `ANull -> EDom.Init
17 Tuesday, November 30, 2010
L ⊢ e.f : (p.fields f) L ⊢ x : L(x) L ⊢ null : Init
let rec eval_expr (l:LDom.t) : JBir.expr -> EDom.t = function | Field (_,cn,fs) | StaticField (cn,fs) -> let cl = PProgram.resolve_field (PProgram.Name (prog,cn)) fs in Annotations.get_field_annotation koc cl fs | Var (_,x) -> LDom.get_var (JBir.index x) l | Const `ANull -> EDom.Init | Unop (Cast _, e) -> eval_expr l e | Binop (ArrayLoad _ , e1, e2) -> array_annot | _ -> EDom.bot
17 Tuesday, November 30, 2010
Instruction typing L ⊢ e : τ x = this m ⊢ x ← e : L → L[x → τ]
18 Tuesday, November 30, 2010
Instruction typing L ⊢ e : τ x = this m ⊢ x ← e : L → L[x → τ]
| AffectVar (var,expr) -> let this_var = snd (List.hd implem.params) in if (not m.cm_static) && (JBir.var_equal var this_var) then failwith "The receiver should not be overwritten" else (fun l -> let val_expr = eval_expr l expr in LDom.set_var (JBir.index var) val_expr l)
18 Tuesday, November 30, 2010
19 Tuesday, November 30, 2010
20 Tuesday, November 30, 2010
21 Tuesday, November 30, 2010
22 Tuesday, November 30, 2010
copies
the spirit of the static checker of Microsoft Code Contracts)
autre: il y a encore des morceaux qui pourrait être simplifier sur l'appel au solver et la creation de l'état initial, les annotations comme annotation de type, annotation in the body of methods
23 Tuesday, November 30, 2010
24 Tuesday, November 30, 2010