mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 14:24:46 +02:00
8343958: Remove security manager impl in java.lang.Process and java.lang.Runtime.exec
Reviewed-by: jpai, mullan, alanb
This commit is contained in:
parent
5ac330b1ac
commit
168b18ec68
4 changed files with 55 additions and 169 deletions
|
@ -339,11 +339,6 @@ public final class ProcessBuilder
|
|||
* @see System#getenv()
|
||||
*/
|
||||
public Map<String,String> environment() {
|
||||
@SuppressWarnings("removal")
|
||||
SecurityManager security = System.getSecurityManager();
|
||||
if (security != null)
|
||||
security.checkPermission(new RuntimePermission("getenv.*"));
|
||||
|
||||
if (environment == null)
|
||||
environment = ProcessEnvironment.environment();
|
||||
|
||||
|
@ -1069,11 +1064,6 @@ public final class ProcessBuilder
|
|||
// Throws IndexOutOfBoundsException if command is empty
|
||||
String prog = cmdarray[0];
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
SecurityManager security = System.getSecurityManager();
|
||||
if (security != null)
|
||||
security.checkExec(prog);
|
||||
|
||||
String dir = directory == null ? null : directory.toString();
|
||||
|
||||
for (String s : cmdarray) {
|
||||
|
@ -1112,24 +1102,13 @@ public final class ProcessBuilder
|
|||
}
|
||||
return process;
|
||||
} catch (IOException | IllegalArgumentException e) {
|
||||
String exceptionInfo = ": " + e.getMessage();
|
||||
Throwable cause = e;
|
||||
if ((e instanceof IOException) && security != null) {
|
||||
// Can not disclose the fail reason for read-protected files.
|
||||
try {
|
||||
security.checkRead(prog);
|
||||
} catch (SecurityException se) {
|
||||
exceptionInfo = "";
|
||||
cause = se;
|
||||
}
|
||||
}
|
||||
// It's much easier for us to create a high-quality error
|
||||
// message than the low-level C code which found the problem.
|
||||
throw new IOException(
|
||||
"Cannot run program \"" + prog + "\""
|
||||
+ (dir == null ? "" : " (in directory \"" + dir + "\")")
|
||||
+ exceptionInfo,
|
||||
cause);
|
||||
+ ": " + e.getMessage(),
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -84,28 +84,28 @@ final class ProcessHandleImpl implements ProcessHandle {
|
|||
/**
|
||||
* The thread pool of "process reaper" daemon threads.
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
private static final Executor processReaperExecutor =
|
||||
AccessController.doPrivileged((PrivilegedAction<Executor>) () -> {
|
||||
// Initialize ThreadLocalRandom now to avoid using the smaller stack
|
||||
// of the processReaper threads.
|
||||
ThreadLocalRandom.current();
|
||||
private static final Executor processReaperExecutor = initReaper();
|
||||
|
||||
// For a debug build, the stack shadow zone is larger;
|
||||
// Increase the total stack size to avoid potential stack overflow.
|
||||
int debugDelta = "release".equals(System.getProperty("jdk.debug")) ? 0 : (4*4096);
|
||||
final long stackSize = Boolean.getBoolean("jdk.lang.processReaperUseDefaultStackSize")
|
||||
? 0 : REAPER_DEFAULT_STACKSIZE + debugDelta;
|
||||
private static Executor initReaper() {
|
||||
// Initialize ThreadLocalRandom now to avoid using the smaller stack
|
||||
// of the processReaper threads.
|
||||
ThreadLocalRandom.current();
|
||||
|
||||
ThreadFactory threadFactory = grimReaper -> {
|
||||
Thread t = InnocuousThread.newSystemThread("process reaper", grimReaper,
|
||||
stackSize, Thread.MAX_PRIORITY);
|
||||
privilegedThreadSetDaemon(t, true);
|
||||
return t;
|
||||
};
|
||||
// For a debug build, the stack shadow zone is larger;
|
||||
// Increase the total stack size to avoid potential stack overflow.
|
||||
int debugDelta = "release".equals(System.getProperty("jdk.debug")) ? 0 : (4 * 4096);
|
||||
final long stackSize = Boolean.getBoolean("jdk.lang.processReaperUseDefaultStackSize")
|
||||
? 0 : REAPER_DEFAULT_STACKSIZE + debugDelta;
|
||||
|
||||
return Executors.newCachedThreadPool(threadFactory);
|
||||
});
|
||||
ThreadFactory threadFactory = grimReaper -> {
|
||||
Thread t = InnocuousThread.newSystemThread("process reaper", grimReaper,
|
||||
stackSize, Thread.MAX_PRIORITY);
|
||||
t.setDaemon(true);
|
||||
return t;
|
||||
};
|
||||
|
||||
return Executors.newCachedThreadPool(threadFactory);
|
||||
}
|
||||
|
||||
private static class ExitCompletion extends CompletableFuture<Integer> {
|
||||
final boolean isReaping;
|
||||
|
@ -115,22 +115,6 @@ final class ProcessHandleImpl implements ProcessHandle {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
private static void privilegedThreadSetName(Thread thread, String name) {
|
||||
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
|
||||
thread.setName(name);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
private static void privilegedThreadSetDaemon(Thread thread, boolean on) {
|
||||
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
|
||||
thread.setDaemon(on);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a CompletableFuture that completes with process exit status when
|
||||
* the process completes.
|
||||
|
@ -158,7 +142,7 @@ final class ProcessHandleImpl implements ProcessHandle {
|
|||
public void run() {
|
||||
Thread t = Thread.currentThread();
|
||||
String threadName = t.getName();
|
||||
privilegedThreadSetName(t, "process reaper (pid " + pid + ")");
|
||||
t.setName("process reaper (pid " + pid + ")");
|
||||
try {
|
||||
int exitValue = waitForProcessExit0(pid, shouldReap);
|
||||
if (exitValue == NOT_A_CHILD) {
|
||||
|
@ -189,7 +173,7 @@ final class ProcessHandleImpl implements ProcessHandle {
|
|||
completions.remove(pid, newCompletion);
|
||||
} finally {
|
||||
// Restore thread name
|
||||
privilegedThreadSetName(t, threadName);
|
||||
t.setName(threadName);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -255,14 +239,8 @@ final class ProcessHandleImpl implements ProcessHandle {
|
|||
* @param pid the native process identifier
|
||||
* @return The ProcessHandle for the pid if the process is alive;
|
||||
* or {@code null} if the process ID does not exist in the native system.
|
||||
* @throws SecurityException if RuntimePermission("manageProcess") is not granted
|
||||
*/
|
||||
static Optional<ProcessHandle> get(long pid) {
|
||||
@SuppressWarnings("removal")
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPermission(new RuntimePermission("manageProcess"));
|
||||
}
|
||||
long start = isAlive0(pid);
|
||||
return (start >= 0)
|
||||
? Optional.of(new ProcessHandleImpl(pid, start))
|
||||
|
@ -296,14 +274,8 @@ final class ProcessHandleImpl implements ProcessHandle {
|
|||
* Returns the ProcessHandle for the current native process.
|
||||
*
|
||||
* @return The ProcessHandle for the OS process.
|
||||
* @throws SecurityException if RuntimePermission("manageProcess") is not granted
|
||||
*/
|
||||
public static ProcessHandleImpl current() {
|
||||
@SuppressWarnings("removal")
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPermission(new RuntimePermission("manageProcess"));
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
|
@ -319,15 +291,8 @@ final class ProcessHandleImpl implements ProcessHandle {
|
|||
*
|
||||
* @return a ProcessHandle of the parent process; {@code null} is returned
|
||||
* if the child process does not have a parent
|
||||
* @throws SecurityException if permission is not granted by the
|
||||
* security policy
|
||||
*/
|
||||
public Optional<ProcessHandle> parent() {
|
||||
@SuppressWarnings("removal")
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPermission(new RuntimePermission("manageProcess"));
|
||||
}
|
||||
long ppid = parent0(pid, startTime);
|
||||
if (ppid <= 0) {
|
||||
return Optional.empty();
|
||||
|
@ -442,11 +407,6 @@ final class ProcessHandleImpl implements ProcessHandle {
|
|||
* @return a stream of ProcessHandles
|
||||
*/
|
||||
static Stream<ProcessHandle> children(long pid) {
|
||||
@SuppressWarnings("removal")
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPermission(new RuntimePermission("manageProcess"));
|
||||
}
|
||||
int size = 100;
|
||||
long[] childpids = null;
|
||||
long[] starttimes = null;
|
||||
|
@ -463,11 +423,6 @@ final class ProcessHandleImpl implements ProcessHandle {
|
|||
|
||||
@Override
|
||||
public Stream<ProcessHandle> descendants() {
|
||||
@SuppressWarnings("removal")
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPermission(new RuntimePermission("manageProcess"));
|
||||
}
|
||||
int size = 100;
|
||||
long[] pids = null;
|
||||
long[] ppids = null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue