Skip to content

Commit

Permalink
extension point to add additional class visitors. fix some reflection…
Browse files Browse the repository at this point in the history
… issues
  • Loading branch information
jon-bell committed Oct 20, 2015
1 parent 7864975 commit 91f0a94
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 23 deletions.
8 changes: 7 additions & 1 deletion Phosphor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@
<execution>
<id>integration-test-int-tags</id>
<configuration>
<skipTests>${skipIntTagTests}</skipTests>
<jvm>${project.build.directory}/jre-inst-int/bin/java</jvm>
<includes>
<include>**/*IntTagITCase.java</include>
</includes>
<reuseForks>false</reuseForks>
<argLine>-Xbootclasspath/p:${project.build.directory}/${project.build.finalName}.jar
-javaagent:${project.build.directory}/${project.build.finalName}.jar=enum,acmpeq,cacheDir=${project.build.directory}/cached-int</argLine>
</configuration>
Expand All @@ -92,10 +94,12 @@
<execution>
<id>integration-test-obj-tags</id>
<configuration>
<skipTests>${skipObjTagTests}</skipTests>
<jvm>${project.build.directory}/jre-inst-obj/bin/java</jvm>
<includes>
<include>**/*ObjTagITCase.java</include>
</includes>
<reuseForks>false</reuseForks>
<argLine>-Xbootclasspath/p:${project.build.directory}/${project.build.finalName}.jar
-javaagent:${project.build.directory}/${project.build.finalName}.jar=enum,acmpeq,cacheDir=${project.build.directory}/cached-obj</argLine>
</configuration>
Expand All @@ -107,10 +111,12 @@
<execution>
<id>integration-test-implicit-tracking</id>
<configuration>
<skipTests>${skipImplicitTests}</skipTests>
<jvm>${project.build.directory}/jre-inst-implicit/bin/java</jvm>
<includes>
<include>**/*ImplicitITCase.java</include>
</includes>
<reuseForks>false</reuseForks>
<argLine>-Xbootclasspath/p:${project.build.directory}/${project.build.finalName}.jar
-javaagent:${project.build.directory}/${project.build.finalName}.jar=enum,acmpeq,cacheDir=${project.build.directory}/cached-implicit</argLine>
</configuration>
Expand Down Expand Up @@ -157,7 +163,7 @@
<goal>exec</goal>
</goals>
<configuration>
<skip>${dacapo.skip}</skip>
<skip>${dacapo.skip}</skip>
<executable>${basedir}/runDacapo.sh</executable>
</configuration>
</execution>
Expand Down
7 changes: 7 additions & 0 deletions Phosphor/src/edu/columbia/cs/psl/phosphor/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
import edu.columbia.cs.psl.phosphor.instrumenter.DataAndControlFlowTagFactory;
import edu.columbia.cs.psl.phosphor.instrumenter.TaintAdapter;
import edu.columbia.cs.psl.phosphor.instrumenter.TaintTrackingClassVisitor;

import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Opcodes;

import edu.columbia.cs.psl.phosphor.runtime.DerivedTaintListener;
import edu.columbia.cs.psl.phosphor.runtime.Taint;

Expand Down Expand Up @@ -47,6 +50,8 @@ public class Configuration {
public static Class TAINT_TAG_OBJ_ARRAY_CLASS = (Taint[].class);

public static Class<? extends TaintAdapter> extensionMethodVisitor;
public static Class<? extends ClassVisitor> extensionClassVisitor;

public static TaintTagFactory taintTagFactory = new DataAndControlFlowTagFactory();
public static DerivedTaintListener derivedTaintListener;
public static String CACHE_DIR = null;
Expand Down Expand Up @@ -79,6 +84,8 @@ public static void init() {
props.load(r.openStream());
if (props.containsKey("extraMV"))
extensionMethodVisitor = (Class<? extends TaintAdapter>) Class.forName(props.getProperty("extraMV"));
if (props.containsKey("extraCV"))
extensionClassVisitor = (Class<? extends ClassVisitor>) Class.forName(props.getProperty("extraCV"));
if (props.containsKey("taintTagFactory"))
taintTagFactory = (TaintTagFactory) Class.forName(props.getProperty("taintTagFactory")).newInstance();
if (props.containsKey("derivedTaintListener"))
Expand Down
27 changes: 20 additions & 7 deletions Phosphor/src/edu/columbia/cs/psl/phosphor/PreMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
import java.lang.instrument.Instrumentation;
import java.lang.reflect.Constructor;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.MessageDigest;
import java.security.ProtectionDomain;
import java.util.List;

import edu.columbia.cs.psl.phosphor.instrumenter.TaintTrackingClassVisitor;

import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
Expand All @@ -30,6 +32,7 @@
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.util.CheckClassAdapter;
import org.objectweb.asm.util.TraceClassVisitor;

import edu.columbia.cs.psl.phosphor.runtime.Taint;
import edu.columbia.cs.psl.phosphor.runtime.TaintInstrumented;
import edu.columbia.cs.psl.phosphor.struct.ControlTaintTagStack;
Expand Down Expand Up @@ -226,10 +229,15 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si
try {

ClassWriter cw = new HackyClassWriter(cr, ClassWriter.COMPUTE_MAXS);

ClassVisitor _cv = new SerialVersionUIDAdder(new TaintTrackingClassVisitor(cw, skipFrames, fields));
if(Configuration.extensionClassVisitor != null)
{
Constructor<? extends ClassVisitor> extra = Configuration.extensionClassVisitor.getConstructor(ClassVisitor.class);
_cv = extra.newInstance(_cv);
}
cr.accept(
// new CheckClassAdapter(
new SerialVersionUIDAdder(new TaintTrackingClassVisitor(cw, skipFrames, fields))
_cv
// )
, ClassReader.EXPAND_FRAMES);

Expand Down Expand Up @@ -300,11 +308,13 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si
ex.printStackTrace();
cv= new TraceClassVisitor(null,null);
try{
cr.accept(
// new CheckClassAdapter(
new SerialVersionUIDAdder(new TaintTrackingClassVisitor(cv,skipFrames, fields))
// )
, ClassReader.EXPAND_FRAMES);
ClassVisitor _cv = new SerialVersionUIDAdder(new TaintTrackingClassVisitor(cv, skipFrames, fields));
if(Configuration.extensionClassVisitor != null)
{
Constructor<? extends ClassVisitor> extra = Configuration.extensionClassVisitor.getConstructor(ClassVisitor.class);
_cv = extra.newInstance(_cv);
}
cr.accept(_cv, ClassReader.EXPAND_FRAMES);
}
catch(Throwable ex2)
{ }
Expand Down Expand Up @@ -371,4 +381,7 @@ else if(s.startsWith("cacheDir="))
inst.addTransformer(transformer);

}
public static Instrumentation getInstrumentation() {
return instrumentation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ else if(args.length == 2)
|| name.equals("getDouble$$PHOSPHORTAGGED") || name.equals("getByte$$PHOSPHORTAGGED") || name.equals("getFloat$$PHOSPHORTAGGED") || name.equals("getLong$$PHOSPHORTAGGED")
|| name.equals("getShort$$PHOSPHORTAGGED") || name.equals("setAccessible$$PHOSPHORTAGGED") || name.equals("set") || name.equals("setInt$$PHOSPHORTAGGED")
|| name.equals("setBoolean$$PHOSPHORTAGGED") || name.equals("setChar$$PHOSPHORTAGGED") || name.equals("setDouble$$PHOSPHORTAGGED") || name.equals("setByte$$PHOSPHORTAGGED")
|| name.equals("setFloa$$PHOSPHORTAGGEDt") || name.equals("setLong$$PHOSPHORTAGGED") || name.equals("setShort$$PHOSPHORTAGGED") || name.equals("getType"))) {
|| name.equals("setFloat$$PHOSPHORTAGGED") || name.equals("setLong$$PHOSPHORTAGGED") || name.equals("setShort$$PHOSPHORTAGGED") || name.equals("getType") || name.equals("getType$$PHOSPHORTAGGED"))) {
owner = Type.getInternalName(RuntimeReflectionPropogator.class);
opcode = Opcodes.INVOKESTATIC;
desc = "(Ljava/lang/reflect/Field;" + desc.substring(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ public static Class<?> getType(Field f)
e.printStackTrace();
}
}
else if(MultiDTaintedArrayWithObjTag.class.isAssignableFrom(component))
{
Type t = Type.getType(ret);
String newType = "[";
for(int i = 0; i < t.getDimensions(); i++)
newType += "[";
newType += MultiDTaintedArrayWithObjTag.getPrimitiveTypeForWrapper(component);
try {
ret = Class.forName(newType);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return ret;
}
public static Object get$$PHOSPHORTAGGED(Field f, Object obj, ControlTaintTagStack ctrl) throws IllegalArgumentException, IllegalAccessException {
Expand Down Expand Up @@ -516,7 +530,7 @@ else if(f.getType() == Short.TYPE)

public static TaintedDoubleWithObjTag getDouble$$PHOSPHORTAGGED(Field f, Object obj, TaintedDoubleWithObjTag ret) throws IllegalArgumentException, IllegalAccessException {
f.setAccessible(true);
ret.val = f.getInt(obj);
ret.val = f.getDouble(obj);
try {
Field taintField;
if (fieldToField.containsKey(f))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public Taint copyTag()
}

public final void recalculate() {
if(!invalidated)
return;
invalidated = false;

if (children != null) {
taint = new Taint();
Expand Down Expand Up @@ -71,29 +74,21 @@ public final EnqueuedTaint push(Taint tag, EnqueuedTaint prev) {
if(taint == null)
taint = new Taint();
taint.addDependency(tag);

invalidated = true;
return entry;
}
public final void appendTag(Taint tag, Taint tag2) {
// push(tag);
// push(tag2);
}

public final void pop() {
// if(children == null || children.getFirst() == null)
// return;
// pop(children.getFirst().entry.taint);
}

public final void pop(EnqueuedTaint enq) {
if(enq == null || enq.taint == null)
{
return;
}
invalidated = true;

Taint tag = enq.taint;
boolean recalc = tag.lbl != null || !tag.hasNoDependencies();
LinkedList.Node<EnqueuedTaint> e = tag.enqueuedInControlFlow.getFirst();
LinkedList.Node<EnqueuedTaint> p = null;

while(e != null)
{
if(e.entry.controlTag == this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public synchronized boolean addAll(LinkedList<T> o)
Node<T> i = o.getFirst();
while(i != null)
{
added |= addUnique(i.entry);
if(i.entry != null)
added |= addUnique(i.entry);
// Node<T> n = new Node<T>();
// n.entry = i.entry;
// last.next=n;
Expand Down
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@
<modules>
<module>Phosphor</module>
</modules>
<distributionManagement>
<snapshotRepository>
<id>psl.internal</id>
<name>PSL Internal Repository</name>
<url>http://ase.cs.columbia.edu:8282/repository/snapshots</url>
</snapshotRepository>
</distributionManagement>

</project>

0 comments on commit 91f0a94

Please sign in to comment.