Skip to content

Commit

Permalink
8270199: Most SA tests are skipped on macosx-aarch64 because all exec…
Browse files Browse the repository at this point in the history
…utables are signed

Reviewed-by: lucy
Backport-of: 16e0ad0ad088af3ba1c9903ed8df60799a1ba651
  • Loading branch information
GoeLin committed Oct 12, 2023
1 parent fa42a3e commit c17878a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 40 deletions.
6 changes: 3 additions & 3 deletions test/hotspot/jtreg/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ serviceability/dcmd/gc/RunFinalizationTest.java 8227120 linux-all,windows-x64
serviceability/sa/ClhsdbCDSCore.java 8294316,8269982,8267433 macosx-aarch64,macosx-x64
serviceability/sa/ClhsdbFindPC.java#id1 8294316,8269982,8267433 macosx-aarch64,macosx-x64
serviceability/sa/ClhsdbFindPC.java#id3 8294316,8269982,8267433 macosx-aarch64,macosx-x64
serviceability/sa/ClhsdbPmap.java#id1 8294316,8267433 macosx-x64
serviceability/sa/ClhsdbPmap.java#id1 8294316,8269982,8267433 macosx-aarch64,macosx-x64
serviceability/sa/ClhsdbPstack.java#id1 8294316,8269982,8267433 macosx-aarch64,macosx-x64
serviceability/sa/TestJmapCore.java 8294316,8267433 macosx-x64
serviceability/sa/TestJmapCoreMetaspace.java 8294316,8267433 macosx-x64
serviceability/sa/TestJmapCore.java 8294316,8269982,8267433 macosx-aarch64,macosx-x64
serviceability/sa/TestJmapCoreMetaspace.java 8294316,8269982,8267433 macosx-aarch64,macosx-x64

#############################################################################

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2022, 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
Expand Down Expand Up @@ -53,7 +53,7 @@ private static enum MethodGroup {
IGNORED("isEmulatedClient", "isDebugBuild", "isFastDebugBuild", "isMusl",
"isSlowDebugBuild", "hasSA", "isRoot", "isTieredSupported",
"areCustomLoadersSupportedForCDS", "isDefaultCDSArchiveSupported",
"isSignedOSX");
"isHardenedOSX");

public final List<String> methodNames;

Expand Down
63 changes: 35 additions & 28 deletions test/lib/jdk/test/lib/Platform.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2022, 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
Expand Down Expand Up @@ -261,13 +261,13 @@ public static boolean hasSA() {
}

/**
* Return true if the test JDK is signed, otherwise false. Only valid on OSX.
* Return true if the test JDK is hardened, otherwise false. Only valid on OSX.
*/
public static boolean isSignedOSX() throws IOException {
// We only care about signed binaries for 10.14 and later (actually 10.14.5, but
public static boolean isHardenedOSX() throws IOException {
// We only care about hardened binaries for 10.14 and later (actually 10.14.5, but
// for simplicity we'll also include earlier 10.14 versions).
if (getOsVersionMajor() == 10 && getOsVersionMinor() < 14) {
return false; // assume not signed
return false; // assume not hardened
}

// Find the path to the java binary.
Expand All @@ -279,38 +279,45 @@ public static boolean isSignedOSX() throws IOException {
}

// Run codesign on the java binary.
ProcessBuilder pb = new ProcessBuilder("codesign", "-d", "-v", javaFileName);
pb.redirectError(ProcessBuilder.Redirect.DISCARD);
pb.redirectOutput(ProcessBuilder.Redirect.DISCARD);
ProcessBuilder pb = new ProcessBuilder("codesign", "--display", "--verbose", javaFileName);
pb.redirectErrorStream(true); // redirect stderr to stdout
Process codesignProcess = pb.start();
BufferedReader is = new BufferedReader(new InputStreamReader(codesignProcess.getInputStream()));
String line;
boolean isHardened = false;
boolean hardenedStatusConfirmed = false; // set true when we confirm whether or not hardened
while ((line = is.readLine()) != null) {
System.out.println("STDOUT: " + line);
if (line.indexOf("flags=0x10000(runtime)") != -1 ) {
hardenedStatusConfirmed = true;
isHardened = true;
System.out.println("Target JDK is hardened. Some tests may be skipped.");
} else if (line.indexOf("flags=0x20002(adhoc,linker-signed)") != -1 ) {
hardenedStatusConfirmed = true;
isHardened = false;
System.out.println("Target JDK is adhoc signed, but not hardened.");
} else if (line.indexOf("code object is not signed at all") != -1) {
hardenedStatusConfirmed = true;
isHardened = false;
System.out.println("Target JDK is not signed, therefore not hardened.");
}
}
if (!hardenedStatusConfirmed) {
System.out.println("Could not confirm if TargetJDK is hardened. Assuming not hardened.");
isHardened = false;
}

try {
if (codesignProcess.waitFor(10, TimeUnit.SECONDS) == false) {
System.err.println("Timed out waiting for the codesign process to complete. Assuming not signed.");
System.err.println("Timed out waiting for the codesign process to complete. Assuming not hardened.");
codesignProcess.destroyForcibly();
return false; // assume not signed
return false; // assume not hardened
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}

// Check codesign result to see if java binary is signed. Here are the
// exit code meanings:
// 0: signed
// 1: not signed
// 2: invalid arguments
// 3: only has meaning with the -R argument.
// So we should always get 0 or 1 as an exit value.
if (codesignProcess.exitValue() == 0) {
System.out.println("Target JDK is signed. Some tests may be skipped.");
return true; // signed
} else if (codesignProcess.exitValue() == 1) {
System.out.println("Target JDK is not signed.");
return false; // not signed
} else {
System.err.println("Executing codesign failed. Assuming unsigned: " +
codesignProcess.exitValue());
return false; // not signed
}
return isHardened;
}

private static boolean isArch(String archnameRE) {
Expand Down
6 changes: 3 additions & 3 deletions test/lib/jdk/test/lib/SA/SATestUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2022, 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
Expand Down Expand Up @@ -63,8 +63,8 @@ public static void skipIfCannotAttach() {
throw new SkippedException("SA Attach not expected to work. Ptrace attach not supported.");
}
} else if (Platform.isOSX()) {
if (Platform.isSignedOSX()) {
throw new SkippedException("SA Attach not expected to work. JDK is signed.");
if (Platform.isHardenedOSX()) {
throw new SkippedException("SA Attach not expected to work. JDK is hardened.");
}
if (!Platform.isRoot() && !canAddPrivileges()) {
throw new SkippedException("SA Attach not expected to work. Insufficient privileges (not root and can't use sudo).");
Expand Down
8 changes: 4 additions & 4 deletions test/lib/jdk/test/lib/util/CoreUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2022, 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
Expand Down Expand Up @@ -136,12 +136,12 @@ public static String getCoreFileLocation(String crashOutputString, long pid) thr
if (!coresDir.canWrite()) {
throw new SkippedException("Directory \"" + coresDir + "\" is not writable");
}
if (Platform.isSignedOSX()) {
if (Platform.isHardenedOSX()) {
if (Platform.getOsVersionMajor() > 10 ||
(Platform.getOsVersionMajor() == 10 && Platform.getOsVersionMinor() >= 15))
{
// We can't generate cores files with signed binaries on OSX 10.15 and later.
throw new SkippedException("Cannot produce core file with signed binary on OSX 10.15 and later");
// We can't generate cores files with hardened binaries on OSX 10.15 and later.
throw new SkippedException("Cannot produce core file with hardened binary on OSX 10.15 and later");
}
}
} else if (Platform.isLinux()) {
Expand Down

1 comment on commit c17878a

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.