mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8217920: Lookup.defineClass injects a class that can access private members of any class in its own module
Reviewed-by: psandoz, alanb, darcy
This commit is contained in:
parent
22c976a9b0
commit
7f05d57a87
2 changed files with 31 additions and 1 deletions
|
@ -597,6 +597,14 @@ public final class Module implements AnnotatedElement {
|
|||
*
|
||||
* <p> This method does not check if the given module reads this module. </p>
|
||||
*
|
||||
* @apiNote A package {@code p} opened to module {@code M} allows code in
|
||||
* {@code M} do {@linkplain java.lang.reflect.AccessibleObject#setAccessible(boolean)
|
||||
* deep reflection} on all types in the package.
|
||||
* Further, if {@code M} reads this module, it can obtain a
|
||||
* {@link java.lang.invoke.MethodHandles.Lookup Lookup} object that is allowed to
|
||||
* {@link java.lang.invoke.MethodHandles.Lookup#defineClass(byte[]) define classes}
|
||||
* in package {@code p}.
|
||||
*
|
||||
* @param pn
|
||||
* The package name
|
||||
* @param other
|
||||
|
@ -650,6 +658,14 @@ public final class Module implements AnnotatedElement {
|
|||
*
|
||||
* <p> This method does not check if the given module reads this module. </p>
|
||||
*
|
||||
* @apiNote A package {@code p} opened to module {@code M} allows code in
|
||||
* {@code M} do {@linkplain java.lang.reflect.AccessibleObject#setAccessible(boolean)
|
||||
* deep reflection} on all types in the package.
|
||||
* Further, if {@code M} reads this module, it can obtain a
|
||||
* {@link java.lang.invoke.MethodHandles.Lookup Lookup} object that is allowed to
|
||||
* {@link java.lang.invoke.MethodHandles.Lookup#defineClass(byte[]) define classes}
|
||||
* in package {@code p}.
|
||||
*
|
||||
* @param pn
|
||||
* The package name
|
||||
*
|
||||
|
@ -657,6 +673,8 @@ public final class Module implements AnnotatedElement {
|
|||
* unconditionally
|
||||
*
|
||||
* @see ModuleDescriptor#opens()
|
||||
* @see java.lang.reflect.AccessibleObject#setAccessible(boolean)
|
||||
* @see java.lang.invoke.MethodHandles#privateLookupIn
|
||||
*/
|
||||
public boolean isOpen(String pn) {
|
||||
Objects.requireNonNull(pn);
|
||||
|
|
|
@ -233,6 +233,12 @@ public class MethodHandles {
|
|||
* <p>
|
||||
* The resulting {@code Lookup} object has no {@code ORIGINAL} access.
|
||||
*
|
||||
* @apiNote The {@code Lookup} object returned by this method is allowed to
|
||||
* {@linkplain Lookup#defineClass(byte[]) define classes} in the runtime package
|
||||
* of {@code targetClass}. Extreme caution should be taken when opening a package
|
||||
* to another module as such defined classes have the same full privilege
|
||||
* access as other members in {@code targetClass}'s module.
|
||||
*
|
||||
* @param targetClass the target class
|
||||
* @param caller the caller lookup object
|
||||
* @return a lookup object for the target class, with private access
|
||||
|
@ -851,7 +857,7 @@ public class MethodHandles {
|
|||
* <p>
|
||||
* {@link MethodHandles#privateLookupIn(Class, Lookup) MethodHandles.privateLookupIn(T.class, lookup)}
|
||||
* can be used to teleport a {@code lookup} from class {@code C} to class {@code T}
|
||||
* and create a new {@code Lookup} with <a href="#privacc">private access</a>
|
||||
* and produce a new {@code Lookup} with <a href="#privacc">private access</a>
|
||||
* if the lookup class is allowed to do <em>deep reflection</em> on {@code T}.
|
||||
* The {@code lookup} must have {@link #MODULE} and {@link #PRIVATE} access
|
||||
* to call {@code privateLookupIn}.
|
||||
|
@ -869,6 +875,12 @@ public class MethodHandles {
|
|||
* it cannot be used to obtain another private {@code Lookup} by calling
|
||||
* {@link MethodHandles#privateLookupIn(Class, Lookup) privateLookupIn}
|
||||
* because it has no {@code MODULE} access.
|
||||
* <p>
|
||||
* The {@code Lookup} object returned by {@code privateLookupIn} is allowed to
|
||||
* {@linkplain Lookup#defineClass(byte[]) define classes} in the runtime package
|
||||
* of {@code T}. Extreme caution should be taken when opening a package
|
||||
* to another module as such defined classes have the same full privilege
|
||||
* access as other members in {@code M2}.
|
||||
*
|
||||
* <h2><a id="module-access-check"></a>Cross-module access checks</h2>
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue