Secure the Clones

Exchanging mutable data objects with untrusted code is a delicate matter because of the risk of creating a data space that is accessible by an attacker. Consequently, secure programming guidelines for Java stress the importance of using defensive copying before accepting or handing out references to an internal mutable object. However, implementation of a copy method (like clone()) is entirely left to the programmer. It may not provide a sufficiently deep copy of an object and is subject to overriding by a malicious sub-class. Currently no language-based mechanism supports secure object cloning. This paper proposes a type-based annotation system for defining modular copy policies for class-based object-oriented programs. A copy policy specifies the maximally allowed sharing between an object and its clone. We present a static enforcement mechanism that will guarantee that all classes fulfil their copy policy, even in the presence of overriding of copy methods, and establish the semantic correctness of the overall approach in Coq. The mechanism has been implemented and experimentally evaluated on clone methods from several Java libraries.


Introduction
Exchanging data objects with untrusted code is a delicate matter because of the risk of creating a data space that is accessible by an attacker.Consequently, secure programming guidelines for Java such as those proposed by Sun [17] and CERT [6] stress the importance of using defensive copying or cloning before accepting or handing out references to an internal mutable object.There are two aspects of the problem: (1) If the result of a method is a reference to an internal mutable object, then the receiving code may modify the internal state.Therefore, it is recommended to make copies of mutable objects that are returned as results, unless the intention is to share state.(2) If an argument to a method is a reference to an object coming from hostile code, a local copy of the object should be created.Otherwise, the hostile code may be able to modify the internal state of the object.
A common way for a class to provide facilities for copying objects is to implement a clone() method that overrides the cloning method provided by java.lang.Object.The following code snippet, taken from Sun's Secure Coding Guidelines for Java, demonstrates how a date object is cloned before being returned to a caller: However, relying on calling a polymorphic clone method to ensure secure copying of objects may prove insufficient, for two reasons.First, the implementation of the clone() method is entirely left to the programmer and there is no way to enforce that an untrusted implementation provides a sufficiently deep copy of the object.It is free to leave references to parts of the original object being copied in the new object.Second, even if the current clone() method works properly, sub-classes may override the clone() method and replace it with a method that does not create a sufficiently deep clone.For the above example to behave correctly, an additional class invariant is required, ensuring that the date field always contains an object that is of class Date and not one of its sub-classes.To quote from the CERT guidelines for secure Java programming: "Do not carry out defensive copying using the clone() method in constructors, when the (non-system) class can be subclassed by untrusted code.This will limit the malicious code from returning a crafted object when the object's clone() method is invoked."Clearly, we are faced with a situation where basic object-oriented software engineering principles (sub-classing and overriding) are at odds with security concerns.To reconcile these two aspects in a manner that provides semantically well-founded guarantees of the resulting code, this paper proposes a formalism for defining cloning policies by annotating classes and specific copy methods, and a static enforcement mechanism that will guarantee that all classes of an application adhere to the copy policy.Intuitively, policies impose non-sharing constraints between the structure referenced by a field of an object and the structure returned by the cloning method.Notice, that we do not enforce that a copy method will always return a target object that is functionally equivalent to its source.Nor does our method prevent a sub-class from making a copy of a structure using new fields that are not governed by the declared policy.For a more detailed example of these limitations, see Section 2.3.
1.1.Cloning of Objects.For objects in Java to be cloneable, their class must implement the empty interface Cloneable.A default clone method is provided by the class Object: when invoked on an object of a class, Object.clonewill create a new object of that class and copy the content of each field of the original object into the new object.The object and its clone share all sub-structures of the object; such a copy is called shallow.
It is common for cloneable classes to override the default clone method and provide their own implementation.For a generic List class, this could be done as follows: Notice that this cloning method performs a shallow copy of the list, duplicating the spine but sharing all the elements between the list and its clone.Because this amount of sharing may not be desirable (for the reasons mentioned above), the programmer is free to implement other versions of clone().For example, another way of cloning a list is by copying both the list spine and its elements 1 , creating what is known as a deep copy.
public List<V> deepClone() { return new List((V) value.clone(),(next==null ?null : next.deepClone()));} A general programming pattern for methods that clone objects works by first creating a shallow copy of the object by calling the super.clone()method, and then modifying certain fields to reference new copies of the original content.This is illustrated in the following snippet, taken from the class LinkedList in Fig. 8: There are two observations to be made about the analysis of such methods.First, an analysis that tracks the depth of the clone being returned will have to be flow-sensitive, as the method starts out with a shallow copy that is gradually being made deeper.This makes the analysis more costly.Second, there is no need to track precisely modifications made to parts of the memory that are not local to the clone method, as clone methods are primarily concerned with manipulating memory that they allocate themselves.This will have a strong impact on the design choices of our analysis.
1.2.Copy Policies.The first contribution of the paper is a proposal for a set of semantically well-defined program annotations, whose purpose is to enable the expression of policies for secure copying of objects.Introducing a copy policy language enables class developers to state explicitly the intended behaviour of copy methods.In the basic form of the copy policy formalism, fields of classes are annotated with @Shallow and @Deep.Intuitively, the annotation @Shallow indicates that the field is referencing an object, parts of which may be referenced from elsewhere.The annotation @Deep(X) on a field f means that a) upon return from clone(), the object referenced by this field f is not referenced from elsewhere, and b) the field f is copied according to the copy policy identified by X.Here, X is either the name of a specific policy or if omitted, it designates the default policy of the class of the field.For example, the following annotations: class List { @Shallow V value; @Deep List next; ...} specifies a default policy for the class List where the next field points to a list object that also respects the default copy policy for lists.Any method in the List class, labelled with the @Copy annotation, is meant to respect this default policy.
In addition it is possible to define other copy policies and annotate specific copy methods (identified by the annotation @Copy(...)) with the name of these policies.For example, the annotation 2 DL: { @Deep V value; @Deep(DL) List next;}; @Copy(DL) List<V> deepClone() { return new List((V) value.clone(),(next==null ?null : next.deepClone()));} can be used to specify a list-copying method that also ensures that the value fields of a list of objects are copied according to the copy policy of their class (which is a stronger policy than that imposed by the annotations of the class List).We give a formal definition of the policy annotation language in Section 2.
The annotations are meant to ensure a certain degree of non-sharing between the original object being copied and its clone.We want to state explicitly that the parts of the clone that can be accessed via fields marked @Deep are unreachable from any part of the heap that was accessible before the call to clone().To make this intention precise, we provide a formal semantics of a simple programming language extended with policy annotations and define what it means for a program to respect a policy (Section 2.2). 1.3.Enforcement.The second major contribution of this work is to make the developer's intent, expressed by copy policies, statically enforceable using a type system.We formalize this enforcement mechanism by giving an interpretation of the policy language in which annotations are translated into graph-shaped type structures.For example, the default annotations of the List class defined above will be translated into the graph that is depicted to the right in Fig. 1 (res is the name given to the result of the copy method).The left part shows the concrete heap structure.
Unlike general purpose shape analysis, we take into account the programming methodologies and practice for copy methods, and design a type system specifically tailored to the enforcement of copy policies.This means that the underlying analysis must be able to track precisely all modifications to objects that the copy method allocates itself (directly or indirectly) in a flow-sensitive manner.Conversely, as copy methods should not modify nonlocal objects, the analysis will be designed to be more approximate when tracking objects external to the method under analysis, and the type system will accordingly refuse methods that attempt such non-local modifications.As a further design choice, the annotations are required to be verifiable modularly on a class-by-class basis without having to perform an analysis of the entire code base, and at a reasonable cost.
As depicted in Fig. 1, concrete memory cells are either abstracted as a) out when they are not allocated in the copy method itself (or its callee); b) when they are just marked as maybe-shared ; and c) circle nodes of a deterministic graph when they are locally allocated and not shared.A single circle furthermore expresses a singleton concretization.In this 2 Our implementation uses a sightly different policy declaration syntax because of the limitations imposed by the Java annotation language.example, the abstract heap representation matches the graph interpretation of annotations, which means that the instruction set that produced this heap state satisfies the specified copy policy.
Technically, the intra-procedural component of our analysis corresponds to heap shape analysis with the particular type of graphs that we have defined.Operations involving nonlocal parts of the heap are rapidly discarded.Inter-procedural analysis uses the signatures of copy methods provided by the programmer.Inheritance is dealt with by stipulating that inherited fields retain their "shallow/deep" annotations.Redefinition of a method must respect the same copy policy and other copy methods can be added to a sub-class.The detailed definition of the analysis, presented as a set of type inference rules, is given in Section 3.
This article is an extended version of a paper presented at ESOP'11 [13].We have taken advantage of the extra space to provide improved and more detailed explanations, in particular of the inference mechanism and of what is exactly is being enforced by our copy policies.We have also added details of the proof of correctness of the enforcement mechanism.The formalism of copy policies and the correctness theorem for the core language defined in Section 2 have been implemented and verified mechanically in Coq [1].The added details about the proofs should especially facilitate the understanding of this Coq development

Language and Copy Policies
The formalism is developed for a small, imperative language extended with basic, classbased object-oriented features for object allocation, field access and assignment, and method invocation.A program is a collection of classes, organized into a tree-structured class hierarchy via the extends relation.A class consists of a series of copy method declarations with each its own policy X, its name m, its formal parameter x and commands c to execute.A sub-class inherits the copy methods of its super-class and can re-define a copy method defined in one of its super-classes.We only consider copy methods.Private methods (or static methods of the current class) are inlined by the type checker.Other method calls (to virtual methods) are modeled by a special instruction x :=?(y) that assigns an arbitrary value to x and possibly modifies all heap cells reachable from y (except itself).The other commands are standard.The copy method call x :=m cn:X (y) is a virtual call.The method to be called is the copy method of name m defined or inherited by the (dynamic) class of the  object stored in variable y.The subscript annotation cn:X is used as a static constraint.It is supposed that the type of y is guaranteed to be a sub-class of class cn and that cn defines a method m with a copy policy X.This is ensured by standard bytecode verification and method resolution.
We suppose given a set of policy identifiers Policy id , ranged over by X.A copy policy declaration has the form X : {τ } where X is the identifier of the policy signature and τ is a policy.The policy τ consists of a set of field annotations (X, f ) ; . . .where f is a deep field that should reference an object which can only be accessed via the returned pointer of the copy method and which respects the copy policy identified by X.The use of policy identifiers makes it possible to write recursive definitions of copy policies, necessary for describing copy properties of recursive structures.Any other field is implicitly shallow, meaning that no copy properties are guaranteed for the object referenced by the field.No further copy properties are given for the sub-structure starting at shallow fields.For instance, the default copy policy declaration of the class List presented in Sec.1.2 writes: List.default : {(List.default,next)}.
We assume that for a given program, all copy policies have been grouped together in a finite map Π p : Policy id → Policy.In the rest of the paper, we assume this map is complete, i.e. each policy name X that appears in an annotation is bound to a unique policy in the program p.
The semantic model of the language defined here is store-based: A program state consists of an environment ρ of local variables, a store h of locations mapping3 to objects in a heap and a set A of locally allocated locations, i.e., the locations for the heap h that is equal to h except that the f field of the object at location l now has value v. Similarly, ρ[x → v] is the environment ρ modified so that x now maps to v. The object o is the object satisfying o (f ) = for all field f , and ρ is the environment such that ρ (x) = for all variables x.We consider methods with only one parameter and name it p.lookup designates the dynamic lookup procedure that, given a class name cn and a method name m, find the first implementation of m in the class hierarchy starting from the class of name cn and scanning the hierarchy bottom-up.It returns the corresponding method declaration.ret is a specific local variable name that is used to store the result of each method.Reach h (l) (resp.Reach + h (l)) denotes the set of values that are reachable from any sequence (resp.any non-empty sequence) of fields in h. that have been allocated by the current method invocation or by one of its callees.This last component does not influence the semantic transitions: it is used to express the type system interpretation defined in Sec. 3, but is not used in the final soundness theorem.Each object is modeled in turn as a pair composed with its dynamic class and a finite function from field names to values (references or the specific reference for null values).We do not deal with base values such as integers because their immutable values are irrelevant here.
The operational semantics of the language is defined (Fig. 3) by the evaluation relation between configurations Comm × State and resulting states State.The set of locally allocated locations is updated by both the x := new cn and the x :=m cn:X (y) statements.The execution of an unknown method call x :=?(y) results in a new heap h that keeps all the previous objects that were not reachable from ρ(y).It assigns the variable x a reference that was either reachable from ρ(y) in h or that has been allocated during this call and hence not present in h.

2.1.
Policies and Inheritance.We impose restrictions on the way that inheritance can interact with copy policies.A method being re-defined in a sub-class can impose further constraints on how fields of the objects returned as result should be copied.A field already annotated deep with policy X must have the same annotation in the policy governing the re-defined method but a field annotated as shallow can be annotated deep for a re-defined method.
Definition 2.1 (Overriding Copy Policies).A program p is well-formed with respect to overriding copy policies if and only if for any method declaration Copy(X ) m(x ):= . . .that overrides (i.e. is declared with this signature in a subclass of a class cl ) another method declaration Copy(X) m(x ):= . . . declared in cl , we have Intuitively, this definition imposes that the overriding copy policy is stronger than the policy that it overrides.Lemma 2.4 below states this formally.
Example 2.2.The java.lang.Object class provides a clone() method of policy {} (because its native clone() method is shallow on all fields).A class A declaring two fields f and g can hence override the clone() method and give it a policy {(X, g)}.If a class B extends A and overrides clone(), it must assign it a policy of the form {(X, g); . . .} and could declare the field f as deep.In our implementation, we let the programmer leave the policy part that concerns fields declared in superclasses implicit, as it is systematically inherited.

Semantics of Copy Policies. The informal semantics of the copy policy annotation of a method is:
A copy method satisfies a copy policy X if and only if no memory cell that is reachable from the result of this method following only fields with deep annotations in X, is reachable from another local variable of the caller.We formalize this by giving, in Fig. 4, a semantics to copy policies based on access paths.An access path consists of a variable x followed by a sequence of field names f i separated by a dot.An access path π can be evaluated to a value v in a context ρ, h with a judgement ρ, h π ⇓ v.Each path π has a root variable ↓π ∈ Var .A judgement π : τ holds when a path π follows only deep fields in the policy τ .The rule defining the semantics of copy policies can be paraphrased as follows: For any path π starting in x and leading to location l only following deep fields in policy τ , there cannot be another path leading to the same location l which does not start in x.

Definition 2.3 (Secure Copy Method).
A method m is said secure wrt. a copy signature Copy(X){τ } if and only if for all heaps h 1 , h 2 ∈ Heap, local environments ρ 1 , ρ 2 ∈ Env , locally allocated locations A 1 , A 2 ∈ P(Loc), and variables x, y ∈ Var , Note that because of virtual dispatch, the method executed by such a call may not be the method found in cn but an overridden version of it.The security policy requires that all overriding implementations still satisfy the policy τ .

Access path satisfying a policy
We suppose given Πp : Policy id → Policy the set of copy policies of the considered program p.
Thanks to this lemma, it is sufficient to prove that each method is secure wrt.its own copy signature to ensure that all potential overridings will be also secure wrt.that copy signature.

Limitations of Copy
Policies.The enforcement of our copy policies will ensure that certain sharing constraints are satisfied between fields of an object and its clone.However, in the current formalism we restrict the policy to talk about fields that are actually present in a class.The policy does not ensure properties about fields that are added in sub-classes.This means that an attacker could copy e.g., a list by using a new field to build the list, as in the following example.The enforcement mechanism described in this article will determine that the clone() method of class EvilList respects the copy policy declared for the List class in Section 1.2 because this policy only speaks about the next field which is set to null.It will fail to discover that the class EvilList creates a shallow copy of lists through the evilNext field.In order to prevent this attack, the policy language must be extended, e.g., by adding a facility for specifying that all fields except certain, specifically named fields must be copied deeply.The enforcement of such policies will likely be able to reuse the analysis technique described below.

Type and Effect System
The annotations defined in the previous section are convenient for expressing a copy policy but are not sufficiently expressive for reasoning about the data structures being copied.The static enforcement of a copy policy hence relies on a translation of policies into a graph-based structure (that we shall call types) describing parts of the environment of local variables and the heap manipulated by a program.In particular, the types can express useful alias information between variables and heap cells.In this section, we define the set of types, an approximation (sub-typing) relation on types, and an inference system for assigning types to each statement and to the final result of a method.
The set of types is defined using the following symbols: We assume given a set N of nodes.A value can be given a base type t in N + {⊥, out , }.
A node n means the value has been locally allocated and is not shared.The symbol ⊥ means that the value is equal to the null reference .The symbol out means that the value contains a location that cannot reach a locally allocated object.The symbol is the specific "no-information" base type.As is standard in analysis of memory structures, we distinguish between nodes that represent exactly one memory cell and nodes that may represent several cells.If a node representing only one cell has an edge to another node, then this edge can be forgotten and replaced when we assign a new value to the node-this is called a strong update.If the node represents several cells, then the assignment may not concern all these cells and edges cannot be forgotten.We can only add extra out-going edges to the node-this is termed a weak update.In the graphical representations of types, we use singly-circled nodes to designate "weak" nodes and doubly-circled nodes to represent "strong" nodes.
A type is a triplet T = (Γ, ∆, Θ) ∈ T where Γ: is a typing environment that maps (local) variables to base types.∆: is a graph whose nodes are elements of N .The edges of the graphs are labeled with field names.The successors of a node is a base type.Edges over-approximate the concrete points-to relation.Θ: is a set of nodes that represents necessarily only one concrete cell each.Nodes in Θ are eligible to strong update while others (weak nodes) can only be weakly updated.
Example 3.1.The default List policy of Sec.1.2 translates into the type As mentioned in Sec 1.3, this type enjoys a graphic representation corresponding to the right-hand side of Fig. 1.
In order to link types to the heap structures they represent, we will need to state reachability predicates in the abstract domain.Therefore, the path evaluation relation is extended to types using the following inference rules: Notice both out and are considered as sink nodes for path evaluation purposes4 .

3.1.
From Annotation to Type.The set of all copy policies Π p ⊆ PolicyDecl can be translated into a graph ∆ p as described hereafter.We assume a naming process that associates to each policy name X ∈ Policy id of a program a unique node n X ∈ N .
Note that we unfold the possibly cyclic graph ∆ p with an extra node n τ in order to be able to catch an alias information between this node and the result of a method, and hence declare n τ as strong.Take for instance the type in Fig. 1: were it not for this unfolding step, the type would have consisted only in a weak node and a node, with the variable res mapping directly to the former.Note also that it is not necessary to keep (and even to build) the full graph ∆ p in Φ(τ ) but only the part that is reachable from n τ .
3.2.Type Interpretation.The semantic interpretation of types is given in Fig. 5, in the form of a relation ρ, h, A ∼ (Γ, ∆, Θ) that states when a local allocation history A, a heap h and an environment ρ are coherent with a type (Γ, ∆, Θ).The interpretation judgement amounts to checking that (i) for every path π that leads to a value v in the concrete memory and to a base type t in the graph, t is a correct description of v, as formalized by the auxiliary type interpretation ρ, h, A , (Γ, ∆) v ∼ t; (ii) every strong node in Θ represents a uniquely reachable value in the concrete memory.The auxiliary judgement ρ, h, A , (Γ, ∆) v ∼ t is defined by case on t.The null value is represented by any type.The symbol represents any value and out those values that do not allow to reach a locally allocated location.A node n represents a locally allocated memory location l such that every concrete path π that leads to l in ρ, h leads to node n in (Γ, ∆).
We now establish a semantic link between policy semantics and type interpretation.We show that if the final state of a copy method can be given a type of the form Φ(τ ) then this is a secure method wrt. the policy τ .
Proof.[See Coq proof InterpAnnot.soundannotation to type [1]] We consider two paths π and x.π such that ↓π = x, ρ, h π ⇓ l, x.π : τ , ρ, h x.π ⇓ l and look for a contradiction.Since x.π : τ and Γ (res) = n τ , there exists a node n ∈ ∆ τ such that (Γ , ∆ τ ) res.π ⇓ n.Furthermore ρ , h res.π ⇓ l so we can deduce that l ∈ A. Thus we obtain a contradiction with ρ, h π ⇓ l because any path that starts from a variable other than x cannot reach the elements in A.

Sub-typing.
To manage control flow merge points we rely on a sub-typing relation described in Fig. 6.A sub-type relation (Γ ) holds if and only if (ST 1 ) there exists a fusion function σ from dom(∆ 1 ) to dom(∆ 2 )+{ }. σ is a mapping that merges nodes and edges in ∆ 1 such that (ST 2 ) every element t 1 of ∆ 1 accessible from a path π is mapped to an element t 2 of ∆ 2 accessible from the same path, such that t 1 ≤ σ t 2 .In particular, this means that all successors of t 1 are mapped to successors of t 2 .Incidentally, because acts as a sink on paths, if t 1 is mapped to , then all its successors are mapped to too.Finally, when a strong node in ∆ 1 maps to a strong node in ∆ 2 , this image node cannot be the image of any other node in ∆ 1 -in other terms, σ is injective on strong nodes (ST 3 ).
Intuitively, it is possible to go up in the type partial order either by merging, or by forgetting nodes in the initial graph.The following example shows three ordered types and their corresponding fusion functions.On the left, we forget the node pointed to by y and hence forget all of its successors (see (ST 2 )).On the right we fusion two strong nodes to obtain a weak node.
The logical soundness of this sub-typing relation is formally proved with two intermediate lemmas.The first one states that paths are preserved between subtypes, and that they evaluate into basetypes that are related by the subtyping function.
Lemma 3.3 (Pathing in subtypes).Assume ρ, h, A ∼ (T 1 ), and let σ be the fusion map defined by the assertion T 1 T 2 .For any π, r such that ρ, h π ⇓ r, for any Proof.[See Coq proof Misc.Access Path Eval subtyp [1]] The proof follows directly from the definition of type interpretation and subtyping.
The second lemma gives a local view on logical soundness of subtyping.

Lemma 3.4 (Local logical soundness of subtyping). Assume
and let v be a value and t 1 , t 2 some types.
Proof.[See Coq proof Misc.Interp monotone [1]] We make a case for each rules of Then subtyping hypothesis ST 2 gives us a base type t 2 such that n σ t 2 and (Γ 2 , ∆ 2 ) π ⇓ t 2 .But necessarily t 2 = t 2 so we are done.
The logical soundness of this sub-typing relation is then formally proved with the following theorem.Theorem 3.5.For any type T 1 , T 2 ∈ T and ρ, h, A ∈ State, T 1 T 2 and ρ, h, A ∼ (T 1 ) imply ρ, h, A ∼ (T 2 ).

3.4.
Type and Effect System.The type system verifies, statically and class by class, that a program respects the copy policy annotations relative to a declared copy policy.The core of the type system concerns the typability of commands, which is defined through the following judgment: Γ, ∆, Θ c : Γ , ∆ , Θ .The judgment is valid if the execution of command c in a state satisfying type (Γ, ∆, Θ) will result in a state satisfying (Γ , ∆ , Θ ) or will diverge.
Typing rules are given in Fig. 7.We explain a selection of rules below.The rules for if ( * ) then else fi , while ( * ) do done, sequential composition and most of the assignment rules are standard for flow-sensitive type systems.The rule for x := new "allocates" a fresh node n with no edges in the graph ∆ and let Γ(x) references this node.
There are two rules concerning the instruction x .f:=y for assigning values to fields.Assume that the variable x is represented by node n (i.e., Γ(x) = n).In the first case (strong update), the node is strong and we update destructively (or add) the edge in the graph ∆ from node n labeled f to point to the value of Γ(y).The previous edge (if any) is lost because n ∈ Θ ensures that all concrete cells represented by n are affected by this field update.In the second case (weak update), the node is weak.In order to be conservative, we must merge the previous shape with its updated version since the content of x.f is updated but an other cell mays exist and be represented by n without being affected by this field update.
As for method calls m(y), two cases arise depending on whether the method m is copyannotated or not.In each case, we also reason differently depending on the type of the argument y.If a method is associated with a copy policy τ , we compute the corresponding type (n τ , ∆ τ ) and type the result of x :=m cn:X (y) starting in (Γ, ∆, Θ) with the result type consisting of the environment Γ where x now points to n τ , the heap described by the disjoint union of ∆ and ∆ τ .In addition, the set of strong nodes is augmented with n τ since a copy method is guaranteed to return a freshly allocated node.The method call may potentially modify the memory referenced by its argument y, but the analysis has no means of tracking this.Accordingly, if y is a locally allocated memory location of type n, we must remove all nodes reachable from n, and set all the successors of n to .The other case to consider is when the method is not associated with a copy policy (written x :=?(y)).If the parameter y is null or not locally allocated, then there is no way for the method call to access locally allocated memory and we know that x points to a non-locally allocated object.Otherwise, y is a locally allocated memory location of type n, and we must kill all its successors in the abstract heap.Finally, the rule for method definition verifies the coherence of the result of analysing the body of a method m with its copy annotation Φ(τ ).Type checking extends trivially to all methods of the program.

Command typing rules
Note the absence of a rule for typing an instruction x .f:=y when Γ(x ) = or out .In a first attempt, a sound rule would have been Because x may point to any part of the local shape we must conservatively forget all knowledge about the field f .Moreover we should also warn the caller of the current method that a field f of his own local shape may have been updated.We choose to simply reject  copy methods with such patterns.Such a policy is strong but has the merit to be easily understandable to the programmer: a copy method should only modify locally allocated objects to be typable in our type system.For similar reasons, we reject methods that attempt to make a method call on a reference of type because we can not track side effect modifications of such methods without losing the modularity of the verification mechanism.
Example 3.6 (Case Study: java.util.LinkedList).In this example, we demonstrate the use of the type system on a challenging example taken from the standard Java library.The companion web page provides a more detailed explanation of this example [1].The class java.util.LinkedList provides an implementation of doubly-linked lists.A list is composed of a first cell that points through a field header to a collection of doubly-linked cells.Each cell has a link to the previous and the next cell and also to an element of (parameterized) type E. The clone method provided in java.langlibrary implements a "semi-shallow" copy where only cells of type E may be shared between the source and the result of the copy.In Fig. 8 we present a modified version of the original source code: we have inlined all method calls, except those to copy methods and removed exception handling that leads to an abnormal return from the method 5 .Note that there was one method call in the original code that was virtual and hence prevented inlining.It has been necessary to make a private version of this method.This makes sense because such a virtual call actually constitutes a potentially dangerous hook in a cloning method, as a re-defined implementation could be called when cloning a subclass of Linkedlist.
In Fig. 8 we provide several intermediate types that are necessary for typing this method (T i is the type before executing the instruction at line i).The call to super.clone at line 12 creates a shallow copy of the header cell of the list, which contains a reference to the original list.The original list is thus shared, a fact which is represented by an edge to out in type T 13 .
The copy method then progressively constructs a deep copy of the list, by allocating a new node (see type T 14 ) and setting all paths clone.header,clone.header.next and clone.header.previous to point to this node.This is reflected in the analysis by a strong update to the node representing path clone.header to obtain the type T 16 that precisely models the alias between the three paths clone.header,clone.header.next and clone.header.previous(the Java syntax used here hides the temporary variable that is introduced to be assigned the value of clone.headerand then be updated).
This type T 17 is the loop invariant necessary for type checking the whole loop.It is a super-type of T 16 (updated with e → out ) and of T 24 which represents the memory at the end of the loop body.The body of the loop allocates a new list cell (pointed to by variable n) (see type T 19 ) and inserts it into the doubly-linked list.The assignment in line 22 updates the weak node pointed to by path n.previous and hence merges the strong node pointed to by n with the weak node pointed to by clone.header,representing the spine of the list.The assignment at line 23 does not modify the type T 23 .
Notice that the types used in this example show that a flow-insensitive version of the analysis could not have found this information.A flow-insensitive analysis would force the merge of the types at all program points, and the call to super.clonereturn a type that is less precise than the types needed for the analysis of the rest of the method.
3.5.Type soundness.The rest of this section is devoted to the soundness proof of the type system.We consider the types T = (Γ, ∆, Θ), Assignments that modify the heap space can also modify the reachability properties of locations.This following lemma indicates how to reconstruct a path to l f in the initial heap from a path π to a given location l f in the assigned heap.Lemma 3.7 (Path decomposition on assigned states).Assume given a path π, field f , and locations l, l such that ρ, h π ⇓ l .and assume that for any path π and a location l f we have ρ, h[l, f → l ] π ⇓ l f .Then, either ρ, h π ⇓ l f or ∃π z , π 1 , . . ., π n , π f such that: The second case of the conclusion of this lemma is illustrated in Fig. 9.
(a) in ρ, h Proof.[See Coq proof Misc.Access Path Eval putfield case [1]] The proof is done by induction on π.
We extend the previous lemma to paths in both the concrete heap and the graph types.
[See Coq proof Misc.strong subst prop [1]] The non-trivial part of the lemma concerns the situation when t = and v = ).In that case, the proof relies on Lemma 3.7.
The two parts of the disjunction in Lemma 3.7 are used to prove one of the two first statements.If the first part of the disjunction holds, we can assume that ρ, h π ⇓ v.Then, since ρ, h, A ∼ (Γ, ∆, Θ), we also have (Γ, ∆) π ⇓ t.This implies the first main statement.If the second part of the disjunction holds, then, by observing that ρ, h y ⇓ l y , we can derive the sub-statement ∃π f , ρ, h y.π f ⇓ v.As previously, by assumption we also have (Γ, ∆) y.π f ⇓ t, which implies our second main statement.
We first establish a standard subject reduction theorem and then prove type soundness.We assume that all methods of the considered program are well-typed.Theorem 3.9 (Subject Reduction).Assume T 1 c : Proof.[See Coq proof Soundness.subjectreduction [1]] The proof proceeds by structural induction on the instruction c.For each reduction rule concerning c (Fig. 3), we prove that the resulting state is in relation to the type T 2 , as defined by the main type interpretation rule in Fig. 5.This amounts to verifying that the two premises of the type interpretation rule are satisfied.One premise checks that all access paths lead to related (value,node) pairs.The other checks that all nodes that are designated as "strong" in the type interpretation indeed only represent unique locations.We here present the most intricate part of the proof, which concerns graph nodes different from , ⊥, or out , and focus here on variable and field assignment.The entire proof has been checked using the Coq proof management system.
, we know that y.π will lead to a value v (formally, ρ 1 , h 1 y.π ⇓ v) and a node n (formally, (Γ The two paths being identical save for their prefix, this property also holds for x.π (formally, x.π ⇓ n).Paths not beginning with x are not affected by the assignment, and so we can conclude that the first premise is satisfied.
For the second premise, let n ∈ Θ 2 and assume that n can be reached by two paths π and π in ∆ 2 .If none or both of the paths begin with x then, by assumption, the two paths will lead to the same location in h 2 = h 1 .Otherwise, suppose that, say, π begins with x and π with a different variable z and that they lead to l and l respectively.Since Γ 2 (x) = Γ 1 (y) and ∆ 2 = ∆ 1 , then by assumption there is a path π in (ρ 1 , h 1 , ∆ 1 , Γ 1 ) that starts with y, and such that ρ 1 , h 1 π ⇓ l.As z is not affected by the assignment, we also have that Two cases arise, depending on whether n = Γ(x) is a strong or a weak node.
If c ≡ x .f:=y and n = Γ(x) ∈ Θ the node n represents a unique concrete cell in h.To check the first premise, we make use of Lemma 3.8 on a given path π, a node n and a location l such that (Γ 2 , ∆ 2 ) π ⇓ n and ρ 2 , h 2 π ⇓ l.This yields one of two main hypotheses.In the first case π is not modified by the f -redirection (formally, ρ 1 , h 1 π ⇓ l ∧ (Γ 1 , ∆ 1 ) π ⇓ n), and by assumption ρ 1 , h 1 , A 1 , (Γ 1 , ∆ 1 ) l ∼ n.Now consider any path π 0 such that ρ 2 , h 2 π 0 ⇓ l: there is a node n 0 such that (ρ 2 , h 2 ) π 0 ⇓ n 0 , and we can reapply Lemma 3.8 to find that ρ 1 , h 1 , A 1 , (Γ 1 , ∆ 1 ) l ∼ n 0 .Hence n 0 = n, and since nodes in ∆ 1 and ∆ 2 are untouched by the field assignment typing rule, we can conclude that the first premise is satisfied.In the second case (π is modified by the f -redirection) there is a path π in (ρ 1 , h 1 , Γ 1 , ∆ 1 ) such that y.π leads respectively to l and n (formally As in the previous case, for any path π 0 such that ρ 2 , h 2 π 0 ⇓ l and (ρ 2 , h 2 ) π 0 ⇓ n 0 , we have ρ 1 , h 1 , A 1 , (Γ 1 , ∆ 1 ) l ∼ n 0 , which implies that n = n 0 , and thus we can conclude that π 0 leads to the same node as π, as required.
For the second premise, let n ∈ Θ 2 and assume that n can be reached by two paths π and π in ∆ 2 .The application of Lemma 3.8 to both of these paths yields the following combination of cases: neither path is modified by the f -redirection: formally, By assumption, l = l .one of the paths is modified by the f -redirection: without loss of generality, assume and there is a path π in (ρ 1 , h 1 , Γ 1 , ∆ 1 ) such that y.π leads to l in the heap, and n in the graph (formally, ρ 1 , h 1 y.π ⇓ l ∧ (Γ 1 , ∆ 1 ) y.π ⇓ n).By assumption, l = l .both paths are modified by the f -redirection: we can find two paths π and π such that y.π leads to l in the heap and n in the graph, and y.π leads to l in the heap and n in the graph (formally, By assumption, l = l .In all combinations, l = l in h 1 .Since the rule for field assignment in the operational semantics preserves the locations, then l = l in h 2 .
Hence in ∆ 2 , n x points to n y by f , thanks to the monotonicity of σ 2 .This concludes the proof of (Γ 2 , ∆ 2 ) π 0 ⇓ n 0 .The cases when n x and n y do not exist are easily dismissed; we refer the reader to the Coq development for more details.
We are now left with the second premise, stating the unicity of strong node representation.Assume n ∈ Θ 2 can be reached by two paths π and π in ρ 2 , h 2 , Γ 2 , ∆ 2 , we use Lemma 3.7 to decompose both paths.The following cases arise: neither path is modified by the f -redirection: formally, one of the paths is modified by the f -redirection: without loss of generality, assume ρ 1 , h 1 π ⇓ l, and π = π 0 .f.π 1 .f. . . ..f.π n .f.π f with ρ 1 , h 1 y.π f ⇓ l .From the first concrete path expression, Lemma 3.3 ensures that there is n such that n = σ 1 (n ), and (Γ 1 , ∆ 1 ) π ⇓ n .Moreover, by assumption there exists a strong node n in ∆ 1 that y.π f leads to, and that is mapped to n by σ 1 (formally, n = σ 1 (n ) and (Γ 1 , ∆ 1 ) y.π f ⇓ n ).Clause (ST 3 ) of the definition of subtyping states the uniqueness of strong source nodes: thus n = n , and we conclude by assumption that l = l .both paths are modified by the f -redirection: Lemma 3.7 provides two paths π f and π f such that y.π f leads to l, and y.π f leads to l in the heap (formally, As in the previous case, we use the assumption and clause (ST 3 ) of main sub-typing definition to exhibit the common node n in ∆ 1 that is pointed to by both paths.By assumption, l = l .This concludes the demonstration of the second premise, and of the c ≡ x .f:=y case in our global induction.Theorem 3.10 (Type soundness).If p then all methods m declared in the program p are secure, i.e., respect their copy policy.

Inference
In order to type-check a method with the previous type system, it is necessary to infer intermediate types at each loop header, conditional junction points and weak field assignment point.A standard approach consists in turning the previous typing problem into a fixpoint problem in a suitable sup-semi-lattice structure.This section presents the lattice that we put on (T , ).Proofs are generally omitted by lack of space but can be found in the companion report.Typability is then checked by computing a suitable least-fixpoint in this lattice.We end this section by proposing a widening operator that is necessary to prevent infinite iterations.Proof.The relation is reflexive because for all type T ∈ T , T id T .The relation is transitive because if there exists types T 1 , T 2 , T 3 ∈ T such that T 1 σ 1 T 2 and T 2 σ 2 T 3 for some fusion maps σ 1 and σ 2 then T 1 σ 3 T 3 for the fusion map σ 3 define by We write ≡ for the equivalence relation defined by T 1 ≡ T 2 if and only if T 1 T 2 and T 2 T 1 .Although this entails that is a partial order structure on top of (T , ≡), equality and order testing remains difficult using only this definition.Instead of considering the quotient of T with ≡, we define a notion of well-formed types on which is antisymmetric.To do this, we assume that the set of nodes, variable names and field names are countable sets and we write n i (resp.x i and f i ) for the ith node (resp.variable and field).A type (Γ, ∆, Θ) is well-formed if every node in ∆ is reachable from a node in Γ and the nodes in ∆ follow a canonical numbering based on a breadth-first traversal of the graph.Any type can be garbage-collected into a canonical well-formed type by removing all unreachable nodes from variables and renaming all remaining nodes using a fixed strategy based on a total ordering on variable names and field names and a breadth-first traversal.We call  10.Join Algorithm this transformation gc.The following example shows the effect of gc using a canonical numbering.
Since by definition, only deals with reachable nodes, the gc function is a ≡-morphism and respects type interpretation.This means that an inference engine can at any time replace a type by a garbage-collected version.This is useful to perform an equivalence test in order to check whether a fixpoint iteration has ended.Lemma 4.2.For all well-formed types Definition 4.3.Let be an operator that merges two types according to the algorithm in Fig. 10.
(1) It first makes the disjunct union of ∆ 1 and ∆ 2 into a non-deterministic graph (ndg) α, where nodes are labelled by sets of elements in t.This operation is performed by the lift function, that maps nodes to singleton nodes, and fields to transitions.(2) It joins together the nodes in α referenced by Γ i using the fusion algorithm6 .(3) Then it scans the ndg and merges all nondeterministic successors of nodes.
(4) Finally it uses the ground function to recreate a graph ∆ from the now-deterministic graph α.This function operates by pushing a node set to a node labelled by the ≤ σ -sup of the set.The result environment Γ is derived from Γ i and α before the ∆-reconstruction.All state fusions are recorded in a map σ which binds nodes in ∆ 1 ∪ ∆ 2 to nodes in ∆. Figure 11 contains the auxiliary functions used in the above procedure.Figure 12 unfolds the algorithm on a small example.Proof.First note that σ 1 and σ 2 , the functions associated with the two respective sub-typing relations, can easily be reconstructed from σ. Upper bound: Let (T, σ) = T 1 T 2 : we prove that T 1 T and T 2 T .Hypothesis (ST 2 ) is discharged by case analysis, on t 1 and on t 2 .The general argument used is that the join algorithm does not delete any edges, thus preserving all paths in the initial graphs.Least of the upper bounds: Let (T, σ) = T 1 T 2 .Assume there exists T such that T 1 T and T 2 T .Then we prove that T T .The proof consists in checking that the join algorithm produces, at each step, an intermediary pseudo-type T such that T T .The concrete nature of the algorithm drives the following, more detailed decomposition.
(1) Given a function σ, define a state mapping function ≤ τ , and a σ -like relation τ on non-deterministic graphs.The aim with this relation is to emulate the properties of σ , lifting the partial order ≤ σ on nodes to sets of nodes (cells).Lift T into an ndg α .(2) Using the subtyping relations between T 1 , T 2 , and T , establish that the disjunct union and join steps produce an intermediary ndg β such that β τ α .(3) Ensure that the fusions operated by the join algorithm in β produce an ndg γ such that γ τ α .This is done by case analysis, and depending on whether the fusion takes place during the first entry point processing phase, or if it occurs later.(4) Using the t-lattice, show that the ground operation on the ndg γ produces a type T that is a sub-type of T .
The poset structure does have infinite ascending chains, as shown by the following example.Fixpoint iterations may potentially result in such an infinite chain so we have then to rely on a widening [9] operator to enforce termination of fixpoint computations.Here we follow a pragmatic approach and define a widening operator ∇ ∈ T × T → T that takes the result of and that collapses together (with the operator fusion defined above) any node n and its predecessors such that the minimal path reaching n and starting from a local variable is of length at least 2. This is illustrated by the following example.
This ensures the termination of the fixpoint iteration because the number of nodes is then bounded by 2N with N the number of local variables in the program.

Experiments
The policy language and its enforcement mechanism have been implemented in the form of a security tool for Java bytecode.Standard Java @interface declarations are used to specify native annotations, which enable development environments such as Eclipse to parse, identify and auto-complete @Shallow, @Deep, and @Copy tags.Source code annotations are being made accessible to bytecode analysis frameworks.Both the policy extraction and enforcement components are implemented using the Javalib/Sawja static analysis libraries 7to derive annotations and intermediate code representations, and to facilitate the creation of an experimental Eclipse plugin.
In its standard mode, the tool performs a modular verification of annotated classes.We have run experiments on several classes of the standard library (specially in the package java.util)and have successfully checked realistic copy signatures for them.These experiments have also confirmed that the policy enforcement mechanism facilitates re-engineering into more compact implementations of cloning methods in classes with complex dependencies, such as those forming the gnu.xml.transformpackage.For example, in the Stylesheet class an inlined implementation of multiple deep copy methods for half a dozen fields can be rewritten dispatch these functionalities to the relevant classes, while retaining the expected copy policy.This is made possible by the modularity of our enforcement mechanism, which validates calls to external cloning methods as long as their respective policies have been verified.As expected, some cloning methods are beyond the reach of the analysis.We have identified one such method in GNU Classpath's TreeMap class, where the merging of information at control flow merge points destroys too much of the inferred type graph.A disjunctive form of abstraction seems necessary to verify a deep copy annotation on such programs.
The analysis is also capable of processing un-annotated methods, albeit with less precision than when copy policies are available-this is because it cannot rely on annotations to infer external copy method types.Nevertheless, this capability was used to test the tool on two large code bases.The 17000 classes in Sun's rt.jar and the 7000 others in the GNU Classpath have passed our scanner un-annotated.Among the 459 clone() methods we found in these classes, only 15 have been rejected because of an assignment or method call on non-local memory, as explained in Section 3.4.Assignment on non-local memory means here that the copying method is updating fields of other objects than the result of the copy itself.For such examples, our shape analysis seems too coarse to track the dependencies between sources and copy targets.For 78 methods we were unable to infer the minimal, shallow signature {} (the same signature as java.lang.Object.clone()).In some cases, for instance in the DomAttr class, this will happen when the copy method returns the result of another, unannotated method call, and can be mitigated with additional copy annotations.In other cases, merges between abstract values result in precision losses: this is, for instance, the case for the clone method of the TreeMap class, as explained above.
Our prototype confirms the efficiency of the enforcement technique: these verifications took about 25s to run on stock hardware.The prototype, the Coq formalization and proofs, as well as examples of annotated classes can be found at http://www.irisa.fr/celtique/ext/clones.

Related Work
Several proposals for programmer-oriented annotations of Java programs have been published following Bloch's initial proposal of an annotation framework for the Java language [5].These proposals define the syntax of the annotations but often leave their exact semantics unspecified.A notable exception is the set of annotations concerning non-null annotations [11] for which a precise semantic characterization has emerged [12].Concerning security, GlassFish environment in Java offers program annotations of members of a class (such as @DenyAll or @RolesAllowed) for implementing role-based access control to methods.
To the best of our knowledge, the current paper is the first to propose a formal, semantically founded framework for secure cloning through program annotation and static enforcement.The closest work in this area is that of Anderson et al. [3] who have designed an annotation system for C data structures in order to control sharing between threads.Annotation policies are enforced by a mix of static and run-time verification.On the runtime verification side, their approach requires an operator that can dynamically "cast" a cell to an unshared structure.In contrast, our approach offers a completely static mechanism with statically guaranteed alias properties.
Aiken et al. proposes an analysis for checking and inferring local non-aliasing of data [2].They propose to annotate C function parameters with the keyword restrict to ensure that no other aliases to the data referenced by the parameter are used during the execution of the method.A type and effect system is defined for enforcing this discipline statically.This analysis differs from ours in that it allows aliases to exist as long as they are not used whereas we aim at providing guarantees that certain parts of memory are without aliases.The properties tracked by our type system are close to escape analysis [4,7] but the analyses differ in their purpose.While escape analysis tracks locally allocated objects and tries to detect those that do not escape after the end of a method execution, we are specifically interested in tracking locally allocated objects that escape from the result of a method, as well as analyse their dependencies with respect to parameters.
Our static enforcement technique falls within the large area of static verification of heap properties.A substantial amount of research has been conducted here, the most prominent being region calculus [18], separation logic [15] and shape analysis [16].Of these three approaches, shape analysis comes closest in its use of shape graphs.Shape analysis is a large framework that allows to infer complex properties on heap allocated data-structures like absence of dangling pointers in C or non-cyclicity invariants.In this approach, heap cells are abstracted by shape graphs with flexible object abstractions.Graph nodes can either represent a single cell, hence allowing strong updates, or several cells (summary nodes).Materialization allows to split a summary node during cell access in order to obtain a node pointing to a single cell.The shape graphs that we use are not intended to do full shape analysis but are rather specialized for tracking sharing in locally allocated objects.We use a different naming strategy for graph nodes and discard all information concerning nonlocally allocated references.This leads to an analysis which is more scalable than full shape analysis, yet still powerful enough for verifying complex copy policies as demonstrated in the concrete case study java.util.LinkedList.
Noble et al. [14] propose a prescriptive technique for characterizing the aliasing, and more generally, the topology of the object heap in object-oriented programs.This technique is based on alias modes which have evolved into the notion of ownership types [8].In this setting, the annotation @Repr is used to specify that an object is owned by a specific object.It is called a representation of its owner.After such a declaration, the programmer must manipulate the representation in order to ensure that any access path to this object should pass trough its owner.Such a property ensures that a @Repr field must be a @Deep field in any copying method.Still, a @Deep field is not necessarily a @Repr field since a copying method may want to deeply clone this field without further interest in the global alias around it.Cloning seems not to have been studied further in the ownership community and ownership type checking is generally not adapted to flow-sensitive verification, as required by the programming pattern exhibited in existing code.In this example, if we annotate the field next and previous with @Repr, the clone local variable will not be able to keep the same ownership type at line 12 and at line 26.Such a an example would require ownership type systems to track the update of a reference in order to catch that any path to a representation has been erased in the final result of the method.
We have aimed at annotations that together with static analysis allows to verify existing cloning methods.Complementary to our approach, Drossopoulou and Noble [10] propose a system that generate cloning methods from annotation inpired by ownership types.

Conclusions and Perspectives
Cloning of objects is an important aspect of exchanging data with untrusted code.Current language technology for cloning does not provide adequate means for defining and enforcing a secure copy policy statically; a task which is made more difficult by important object-oriented features such as inheritance and re-definition of cloning methods.We have presented a flow-sensitive type system for statically enforcing copy policies defined by the software developer through simple program annotations.The annotation formalism deals with dynamic method dispatch and addresses some of the problems posed by redefinition of cloning methods in inheritance-based object oriented programming language (but see Section 2.3 for a discussion of current limitations).The verification technique is designed to enable modular verification of individual classes.By specifically targeting the verification of copy methods, we consider a problem for which it is possible to deploy a localized version of shape analysis that avoids the complexity of a full shape analysis framework.This means that our method can form part of an extended, security-enhancing Java byte code verifier which of course would have to address, in addition to secure cloning, a wealth of other security policies and security guidelines as e.g., listed on the CERT web site for secure Java programming [6].
The present paper constitutes the formal foundations for a secure cloning framework.All theorems except those of Section 4 have been mechanized in the Coq proof assistant.Mechanization was particularly challenging because of the storeless nature of our type interpretation but in the end proved to be of great help to get the soundness arguments right.
Several issues merit further investigations in order to develop a full-fledged software security verification tool.The extension of the policy language to be able to impose policies on fields defined in sub-classes should be developed (cf.discussion in Section 2.3).We believe that the analysis defined in this article can be used to enforce such policies but their precise semantics remains to be defined.In the current approach, virtual methods without copy policy annotations are considered as black boxes that may modify any object reachable from its arguments.An extension of our copy annotations to virtual calls should be worked out if we want to enhance our enforcement technique and accept more secure copying methods.More advanced verifications will be possible if we develop a richer form of type signatures for methods where the formal parameters may occur in copy policies, in order to express a relation between copy properties of returning objects and parameter fields.The challenge here is to provide sufficiently expressive signatures which at the same time remain humanly readable software contracts.The current formalisation has been developed for a sequential model of Java.We conjecture that the extension to interleaving multi-threading semantics is feasible and that it can be done without making major changes to the type system because we only manipulate thread-local pointers.
An other line of work could be to consider the correctness of equals() methods with respect to copying methods, since we generally expect x.clone().equals(x)to be true.The annotation system is already in good shape for such a work but a static enforcement may require a major improvement of our specifically tailored shape analysis.

Acknowledgement
We wish to thank the ESOP11 and LMCS anonymous reviewers for their helpful comments on this article.We specially thank the anonymous reviewer who suggested the EvilList example presented in Section 2.3.

Figure 1 .
Figure 1.A linked structure (left part) and its abstraction (right part).

Figure 4 .
Figure 4. Copy Policy Semantics Copy(X) m(x ):=c Program typing rule ∀cl ∈ p, ∀md ∈ cl, md p Notations: We write ∆[(n, ) → ⊥] for the update of ∆ with a new node n for which all successors are equal to ⊥.We write KillSuccn for the function that removes all nodes reachable from n (with at least one step) and sets all its successors equal to .

Figure 9 .
Figure 9.An Illustration of Path Decomposition on Assigned States.

Lemma 4 . 1 .
The binary relation is a preorder on T .

Theorem 4 . 4 .
The operator defines a sup-semi-lattice on types.

public class EvilList<V> extends List<V>
{ @Shallow public List<V> evilNext; public EvilList(V val, List<V> next) { super(val,null); this.evilNext = next; } public List<V> clone() { return new EvilList(value,evilNext); } // r e d e f i n i t i o n o f a l l o t h e r methods t o u s e t h e e v i l N e x t f i e l d // i n s t e a d o f next } there exists, by Lemma 3.3, a base type t 1 such that (Γ 1 , ∆ 1 ) π ⇓ t 1 and t 1 σ t 2 .Since ρ, h, A ∼ (T 1 ) holds we can argue that ρ, h, A , (Γ 1 , ∆ 1 ) v ∼ t 1 holds too and conclude with Lemma 3.4.Second, given a strong node n 2 ∈ Θ 2 , two paths π and π and two locations l and l such that = ground(Γ 1 ,Γ 2 ,α)// S i s a s e t o f t ∈ t .// S denotes a node l a b e l l e d by S .