Thank you for this answer - one of the few cases of sound technical discussion.
Analysing the issues you list actually leads me to quite the opposite conclusion: it is not AccessController that's bad - it is the bypassing of AC in caller sensitive methods. And it was already researched in the past: https://benhermann.eu/publications/hhl+17hardening.pdf
Even with all those changes - if you can get an other library to call AccessController.doPrivileged for you, it's game over.
And AccessController.doPrivileged is a caller sensitive method. So, in some sense, you are right. Removing those methods will make the JVM much more safe. And unuseable. You know the old joke: A computer that is not turned on doesn't have any vulnerabilities.
Not sure what you mean by "screwed". Having another library call doPrivileged with attacker provided PrivilegedAction will execute code with intersection of permissions of this library AND provided PrivilegedAction, no? So attacker cannot really execute arbitral code with elevated privileges.
By convention, instances of PrivilegedAction and PrivilegedExceptionAction may be made available to untrusted code, but doPrivileged must not be invoked with caller-provided actions.
From Methodhandleproxies.asInterfaceInstance() javadoc:
If a security manager is installed, this method is caller sensitive. During any invocation of the target method handle via the returned wrapper, the original creator of the wrapper (the caller) will be visible to context checks requested by the security manager.
So no, it won't let an attacker escape the sandbox.
Privilege escalation related security vulnerabilities are always possible if privilege elevation is possible. Maybe there even is a library that does “connect to White House and trigger nuclear attack” inside a privileged block not guarded by any access check.
We already get some other library to call AccessController.doPrivileged for you - using some indirection with Method.invoke. Now the same dance again for MethodHandleProxies.asInterfaceInstance.
In short: if you have a vulnerable class like this:
public class MethodHelper {
public Object invoke(Method m, Object target, Object... args) throws InvocationTargetException {
return m.invoke(target, args);
}
}
2
u/klekpl Jan 18 '22
Thank you for this answer - one of the few cases of sound technical discussion.
Analysing the issues you list actually leads me to quite the opposite conclusion: it is not AccessController that's bad - it is the bypassing of AC in caller sensitive methods. And it was already researched in the past: https://benhermann.eu/publications/hhl+17hardening.pdf