Skip to content

Commit 00ff6a3

Browse files
committed
8344105: Remove SecurityManager and related calls from jdk.attach and jdk.hotspot.agent
Reviewed-by: amenkov, cjplummer
1 parent 475feb0 commit 00ff6a3

File tree

9 files changed

+10
-77
lines changed

9 files changed

+10
-77
lines changed

src/jdk.attach/aix/classes/sun/tools/attach/AttachProviderImpl.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2013 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -52,8 +52,6 @@ public String type() {
5252
public VirtualMachine attachVirtualMachine(String vmid)
5353
throws AttachNotSupportedException, IOException
5454
{
55-
checkAttachPermission();
56-
5755
// AttachNotSupportedException will be thrown if the target VM can be determined
5856
// to be not attachable.
5957
testAttachable(vmid);
@@ -72,7 +70,6 @@ public VirtualMachine attachVirtualMachine(VirtualMachineDescriptor vmd)
7270
// implementation which only returns a list of attachable VMs.
7371
if (vmd instanceof HotSpotVirtualMachineDescriptor) {
7472
assert ((HotSpotVirtualMachineDescriptor)vmd).isAttachable();
75-
checkAttachPermission();
7673
return new VirtualMachineImpl(this, vmd.id());
7774
} else {
7875
return attachVirtualMachine(vmd.id());

src/jdk.attach/linux/classes/sun/tools/attach/AttachProviderImpl.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -49,8 +49,6 @@ public String type() {
4949
public VirtualMachine attachVirtualMachine(String vmid)
5050
throws AttachNotSupportedException, IOException
5151
{
52-
checkAttachPermission();
53-
5452
// AttachNotSupportedException will be thrown if the target VM can be determined
5553
// to be not attachable.
5654
testAttachable(vmid);
@@ -69,7 +67,6 @@ public VirtualMachine attachVirtualMachine(VirtualMachineDescriptor vmd)
6967
// implementation which only returns a list of attachable VMs.
7068
if (vmd instanceof HotSpotVirtualMachineDescriptor) {
7169
assert ((HotSpotVirtualMachineDescriptor)vmd).isAttachable();
72-
checkAttachPermission();
7370
return new VirtualMachineImpl(this, vmd.id());
7471
} else {
7572
return attachVirtualMachine(vmd.id());

src/jdk.attach/macosx/classes/sun/tools/attach/AttachProviderImpl.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -49,8 +49,6 @@ public String type() {
4949
public VirtualMachine attachVirtualMachine(String vmid)
5050
throws AttachNotSupportedException, IOException
5151
{
52-
checkAttachPermission();
53-
5452
// AttachNotSupportedException will be thrown if the target VM can be determined
5553
// to be not attachable.
5654
testAttachable(vmid);
@@ -69,7 +67,6 @@ public VirtualMachine attachVirtualMachine(VirtualMachineDescriptor vmd)
6967
// implementation which only returns a list of attachable VMs.
7068
if (vmd instanceof HotSpotVirtualMachineDescriptor) {
7169
assert ((HotSpotVirtualMachineDescriptor)vmd).isAttachable();
72-
checkAttachPermission();
7370
return new VirtualMachineImpl(this, vmd.id());
7471
} else {
7572
return attachVirtualMachine(vmd.id());

src/jdk.attach/share/classes/com/sun/tools/attach/spi/AttachProvider.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import java.util.List;
3333
import com.sun.tools.attach.VirtualMachine;
3434
import com.sun.tools.attach.VirtualMachineDescriptor;
35-
import com.sun.tools.attach.AttachPermission;
3635
import com.sun.tools.attach.AttachNotSupportedException;
3736
import java.util.ServiceLoader;
3837

@@ -84,10 +83,6 @@ public abstract class AttachProvider {
8483
* Initializes a new instance of this class.
8584
*/
8685
protected AttachProvider() {
87-
@SuppressWarnings("removal")
88-
SecurityManager sm = System.getSecurityManager();
89-
if (sm != null)
90-
sm.checkPermission(new AttachPermission("createAttachProvider"));
9186
}
9287

9388
/**

src/jdk.attach/share/classes/sun/tools/attach/HotSpotAttachProvider.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,6 @@
2525
package sun.tools.attach;
2626

2727
import com.sun.tools.attach.VirtualMachineDescriptor;
28-
import com.sun.tools.attach.AttachPermission;
2928
import com.sun.tools.attach.AttachNotSupportedException;
3029
import com.sun.tools.attach.spi.AttachProvider;
3130

@@ -47,16 +46,6 @@ public abstract class HotSpotAttachProvider extends AttachProvider {
4746
public HotSpotAttachProvider() {
4847
}
4948

50-
public void checkAttachPermission() {
51-
@SuppressWarnings("removal")
52-
SecurityManager sm = System.getSecurityManager();
53-
if (sm != null) {
54-
sm.checkPermission(
55-
new AttachPermission("attachVirtualMachine")
56-
);
57-
}
58-
}
59-
6049
/*
6150
* This listVirtualMachines implementation is based on jvmstat. Can override
6251
* this in platform implementations when there is a more efficient mechanism

src/jdk.attach/share/classes/sun/tools/attach/HotSpotVirtualMachine.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import java.io.InputStream;
3838
import java.io.IOException;
3939
import java.io.InputStreamReader;
40-
import java.security.AccessController;
4140
import java.security.PrivilegedAction;
4241
import java.util.Properties;
4342
import java.util.stream.Collectors;
@@ -54,8 +53,7 @@ public abstract class HotSpotVirtualMachine extends VirtualMachine {
5453

5554
@SuppressWarnings("removal")
5655
private static long pid() {
57-
PrivilegedAction<ProcessHandle> pa = () -> ProcessHandle.current();
58-
return AccessController.doPrivileged(pa).pid();
56+
return ProcessHandle.current().pid();
5957
}
6058

6159
private static final boolean ALLOW_ATTACH_SELF;
@@ -361,12 +359,7 @@ protected int detectVersion() throws IOException {
361359
*/
362360
protected boolean isAPIv2Enabled() {
363361
// if "jdk.attach.compat" property is set, only v1 is enabled.
364-
try {
365-
String value = System.getProperty("jdk.attach.compat");
366-
return !("true".equalsIgnoreCase(value));
367-
} catch (SecurityException se) {
368-
}
369-
return true;
362+
return !Boolean.getBoolean("jdk.attach.compat");
370363
}
371364

372365
/*
@@ -563,7 +556,6 @@ long attachTimeout() {
563556
String s =
564557
System.getProperty("sun.tools.attach.attachTimeout");
565558
attachTimeout = Long.parseLong(s);
566-
} catch (SecurityException se) {
567559
} catch (NumberFormatException ne) {
568560
}
569561
if (attachTimeout <= 0) {

src/jdk.attach/windows/classes/sun/tools/attach/AttachProviderImpl.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -51,8 +51,6 @@ public String type() {
5151
public VirtualMachine attachVirtualMachine(String vmid)
5252
throws AttachNotSupportedException, IOException
5353
{
54-
checkAttachPermission();
55-
5654
// AttachNotSupportedException will be thrown if the target VM can be determined
5755
// to be not attachable.
5856
testAttachable(vmid);

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/SALauncherLoader.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -76,14 +76,6 @@ public SALauncherLoader(ClassLoader parent) {
7676
*/
7777
public synchronized Class loadClass(String name, boolean resolve)
7878
throws ClassNotFoundException {
79-
int i = name.lastIndexOf('.');
80-
if (i != -1) {
81-
@SuppressWarnings("removal")
82-
SecurityManager sm = System.getSecurityManager();
83-
if (sm != null) {
84-
sm.checkPackageAccess(name.substring(0, i));
85-
}
86-
}
8779

8880
Class clazz = findLoadedClass(name);
8981
if (clazz != null) return clazz;
@@ -104,15 +96,6 @@ public synchronized Class loadClass(String name, boolean resolve)
10496
}
10597
}
10698

107-
/**
108-
* allow any classes loaded from classpath to exit the VM.
109-
*/
110-
protected PermissionCollection getPermissions(CodeSource codesource) {
111-
PermissionCollection perms = super.getPermissions(codesource);
112-
perms.add(new RuntimePermission("exitVM"));
113-
return perms;
114-
}
115-
11699
//-- Internals only below this point
117100

118101
private String[] libpaths;

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/jcore/ByteCodeRewriter.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,9 +24,6 @@
2424

2525
package sun.jvm.hotspot.tools.jcore;
2626

27-
import java.security.AccessController;
28-
import java.security.PrivilegedAction;
29-
3027
import sun.jvm.hotspot.interpreter.Bytecodes;
3128
import sun.jvm.hotspot.oops.ConstantPool;
3229
import sun.jvm.hotspot.oops.ConstantPoolCache;
@@ -44,19 +41,7 @@ public class ByteCodeRewriter
4441
private Bytes bytes;
4542

4643
private static final int jintSize = 4;
47-
public static final boolean DEBUG;
48-
49-
static {
50-
@SuppressWarnings("removal")
51-
String debug = AccessController.doPrivileged(
52-
new PrivilegedAction<>() {
53-
public String run() {
54-
return System.getProperty("sun.jvm.hotspot.tools.jcore.ByteCodeRewriter.DEBUG");
55-
}
56-
}
57-
);
58-
DEBUG = (debug != null ? debug.equalsIgnoreCase("true") : false);
59-
}
44+
public static final boolean DEBUG = Boolean.getBoolean("sun.jvm.hotspot.tools.jcore.ByteCodeRewriter.DEBUG");
6045

6146

6247
protected void debugMessage(String message) {

0 commit comments

Comments
 (0)