< prev index next >

test/lib/jdk/test/lib/Platform.java

Print this page

        

*** 21,30 **** --- 21,34 ---- * questions. */ package jdk.test.lib; + import java.io.IOException; + import java.nio.file.Files; + import java.nio.file.Path; + import java.nio.file.Paths; import java.util.regex.Pattern; public class Platform { public static final String vmName = System.getProperty("java.vm.name"); public static final String vmInfo = System.getProperty("java.vm.info");
*** 226,247 **** * if "ptrace_scope" is 1, and true otherwise. */ public static boolean canPtraceAttachLinux() throws Exception { // SELinux deny_ptrace: ! String deny_ptrace = Utils.fileAsString("/sys/fs/selinux/booleans/deny_ptrace"); if (deny_ptrace != null && deny_ptrace.contains("1")) { // ptrace will be denied: return false; } // YAMA enhanced security ptrace_scope: // 0 - a process can PTRACE_ATTACH to any other process running under the same uid // 1 - restricted ptrace: a process must be a children of the inferior or user is root // 2 - only processes with CAP_SYS_PTRACE may use ptrace or user is root // 3 - no attach: no processes may use ptrace with PTRACE_ATTACH ! String ptrace_scope = Utils.fileAsString("/proc/sys/kernel/yama/ptrace_scope"); if (ptrace_scope != null) { if (ptrace_scope.startsWith("3")) { return false; } if (!userName.equals("root") && !ptrace_scope.startsWith("0")) { --- 230,251 ---- * if "ptrace_scope" is 1, and true otherwise. */ public static boolean canPtraceAttachLinux() throws Exception { // SELinux deny_ptrace: ! String deny_ptrace = fileAsString("/sys/fs/selinux/booleans/deny_ptrace"); if (deny_ptrace != null && deny_ptrace.contains("1")) { // ptrace will be denied: return false; } // YAMA enhanced security ptrace_scope: // 0 - a process can PTRACE_ATTACH to any other process running under the same uid // 1 - restricted ptrace: a process must be a children of the inferior or user is root // 2 - only processes with CAP_SYS_PTRACE may use ptrace or user is root // 3 - no attach: no processes may use ptrace with PTRACE_ATTACH ! String ptrace_scope = fileAsString("/proc/sys/kernel/yama/ptrace_scope"); if (ptrace_scope != null) { if (ptrace_scope.startsWith("3")) { return false; } if (!userName.equals("root") && !ptrace_scope.startsWith("0")) {
*** 263,268 **** --- 267,278 ---- private static boolean isArch(String archnameRE) { return Pattern.compile(archnameRE, Pattern.CASE_INSENSITIVE) .matcher(osArch) .matches(); } + + private static String fileAsString(String filename) throws IOException { + Path filePath = Paths.get(filename); + if (!Files.exists(filePath)) return null; + return new String(Files.readAllBytes(filePath)); + } }
< prev index next >