mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-24 04:54:40 +02:00
6904691: Java Applet Trusted Methods Chaining Privilege Escalation Vulnerability
Reviewed-by: hawtin, peterz
This commit is contained in:
parent
a3c0096fcf
commit
6fa1d77169
4 changed files with 46 additions and 16 deletions
|
@ -32,7 +32,6 @@ import java.security.AccessControlContext;
|
||||||
import java.security.AccessController;
|
import java.security.AccessController;
|
||||||
import java.security.PrivilegedAction;
|
import java.security.PrivilegedAction;
|
||||||
|
|
||||||
import java.util.EventObject;
|
|
||||||
import sun.reflect.misc.MethodUtil;
|
import sun.reflect.misc.MethodUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -279,9 +278,9 @@ import sun.reflect.misc.MethodUtil;
|
||||||
public class EventHandler implements InvocationHandler {
|
public class EventHandler implements InvocationHandler {
|
||||||
private Object target;
|
private Object target;
|
||||||
private String action;
|
private String action;
|
||||||
private String eventPropertyName;
|
private final String eventPropertyName;
|
||||||
private String listenerMethodName;
|
private final String listenerMethodName;
|
||||||
private AccessControlContext acc;
|
private final AccessControlContext acc = AccessController.getContext();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new <code>EventHandler</code> object;
|
* Creates a new <code>EventHandler</code> object;
|
||||||
|
@ -310,7 +309,6 @@ public class EventHandler implements InvocationHandler {
|
||||||
*/
|
*/
|
||||||
@ConstructorProperties({"target", "action", "eventPropertyName", "listenerMethodName"})
|
@ConstructorProperties({"target", "action", "eventPropertyName", "listenerMethodName"})
|
||||||
public EventHandler(Object target, String action, String eventPropertyName, String listenerMethodName) {
|
public EventHandler(Object target, String action, String eventPropertyName, String listenerMethodName) {
|
||||||
this.acc = AccessController.getContext();
|
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.action = action;
|
this.action = action;
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
|
@ -422,7 +420,11 @@ public class EventHandler implements InvocationHandler {
|
||||||
* @see EventHandler
|
* @see EventHandler
|
||||||
*/
|
*/
|
||||||
public Object invoke(final Object proxy, final Method method, final Object[] arguments) {
|
public Object invoke(final Object proxy, final Method method, final Object[] arguments) {
|
||||||
return AccessController.doPrivileged(new PrivilegedAction() {
|
AccessControlContext acc = this.acc;
|
||||||
|
if ((acc == null) && (System.getSecurityManager() != null)) {
|
||||||
|
throw new SecurityException("AccessControlContext is not set");
|
||||||
|
}
|
||||||
|
return AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||||
public Object run() {
|
public Object run() {
|
||||||
return invokeInternal(proxy, method, arguments);
|
return invokeInternal(proxy, method, arguments);
|
||||||
}
|
}
|
||||||
|
@ -482,7 +484,10 @@ public class EventHandler implements InvocationHandler {
|
||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
catch (InvocationTargetException ex) {
|
catch (InvocationTargetException ex) {
|
||||||
throw new RuntimeException(ex.getTargetException());
|
Throwable th = ex.getTargetException();
|
||||||
|
throw (th instanceof RuntimeException)
|
||||||
|
? (RuntimeException) th
|
||||||
|
: new RuntimeException(th);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -29,6 +29,10 @@ import java.lang.reflect.Array;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.security.AccessControlContext;
|
||||||
|
import java.security.AccessController;
|
||||||
|
import java.security.PrivilegedActionException;
|
||||||
|
import java.security.PrivilegedExceptionAction;
|
||||||
|
|
||||||
import com.sun.beans.finder.ClassFinder;
|
import com.sun.beans.finder.ClassFinder;
|
||||||
import com.sun.beans.finder.ConstructorFinder;
|
import com.sun.beans.finder.ConstructorFinder;
|
||||||
|
@ -63,9 +67,10 @@ public class Statement {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Object target;
|
private final AccessControlContext acc = AccessController.getContext();
|
||||||
String methodName;
|
private final Object target;
|
||||||
Object[] arguments;
|
private final String methodName;
|
||||||
|
private final Object[] arguments;
|
||||||
ClassLoader loader;
|
ClassLoader loader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -145,6 +150,26 @@ public class Statement {
|
||||||
}
|
}
|
||||||
|
|
||||||
Object invoke() throws Exception {
|
Object invoke() throws Exception {
|
||||||
|
AccessControlContext acc = this.acc;
|
||||||
|
if ((acc == null) && (System.getSecurityManager() != null)) {
|
||||||
|
throw new SecurityException("AccessControlContext is not set");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return AccessController.doPrivileged(
|
||||||
|
new PrivilegedExceptionAction<Object>() {
|
||||||
|
public Object run() throws Exception {
|
||||||
|
return invokeInternal();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
acc
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (PrivilegedActionException exception) {
|
||||||
|
throw exception.getException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object invokeInternal() throws Exception {
|
||||||
Object target = getTarget();
|
Object target = getTarget();
|
||||||
String methodName = getMethodName();
|
String methodName = getMethodName();
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2005-2007 Sun Microsystems, Inc. All Rights Reserved.
|
* Copyright 2005-2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -49,10 +49,10 @@ public class Test6277246 {
|
||||||
catch (NoSuchMethodException exception) {
|
catch (NoSuchMethodException exception) {
|
||||||
throw new Error("unexpected exception", exception);
|
throw new Error("unexpected exception", exception);
|
||||||
}
|
}
|
||||||
catch (RuntimeException exception) {
|
catch (SecurityException exception) {
|
||||||
if (exception.getCause() instanceof SecurityException) {
|
// expected security exception
|
||||||
return; // expected security exception
|
|
||||||
}
|
}
|
||||||
|
catch (RuntimeException exception) {
|
||||||
throw new Error("unexpected exception", exception);
|
throw new Error("unexpected exception", exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2005-2007 Sun Microsystems, Inc. All Rights Reserved.
|
* Copyright 2005-2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -51,7 +51,7 @@ public class Test6277266 {
|
||||||
);
|
);
|
||||||
throw new Error("SecurityException expected");
|
throw new Error("SecurityException expected");
|
||||||
} catch (InvocationTargetException exception) {
|
} catch (InvocationTargetException exception) {
|
||||||
if (exception.getCause().getCause() instanceof SecurityException){
|
if (exception.getCause() instanceof SecurityException){
|
||||||
return; // expected security exception
|
return; // expected security exception
|
||||||
}
|
}
|
||||||
throw new Error("unexpected exception", exception);
|
throw new Error("unexpected exception", exception);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue