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: dholmes, kevinw
  • Loading branch information
plummercj committed Jan 26, 2022
1 parent d2a50a6 commit 16e0ad0
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 41 deletions.
8 changes: 4 additions & 4 deletions test/hotspot/jtreg/ProblemList.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2016, 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 @@ -121,10 +121,10 @@ serviceability/dcmd/gc/RunFinalizationTest.java 8227120 linux-all,windows-x64
serviceability/sa/ClhsdbCDSCore.java 8269982,8267433 macosx-aarch64,macosx-x64
serviceability/sa/ClhsdbFindPC.java#xcomp-core 8269982,8267433 macosx-aarch64,macosx-x64
serviceability/sa/ClhsdbFindPC.java#no-xcomp-core 8269982,8267433 macosx-aarch64,macosx-x64
serviceability/sa/ClhsdbPmap.java#core 8267433 macosx-x64
serviceability/sa/ClhsdbPmap.java#core 8269982,8267433 macosx-aarch64,macosx-x64
serviceability/sa/ClhsdbPstack.java#core 8269982,8267433 macosx-aarch64,macosx-x64
serviceability/sa/TestJmapCore.java 8267433 macosx-x64
serviceability/sa/TestJmapCoreMetaspace.java 8267433 macosx-x64
serviceability/sa/TestJmapCore.java 8269982,8267433 macosx-aarch64,macosx-x64
serviceability/sa/TestJmapCoreMetaspace.java 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",
"isSlowDebugBuild", "hasSA", "isRoot", "isTieredSupported",
"areCustomLoadersSupportedForCDS", "isDefaultCDSArchiveSupported",
"isSignedOSX");
"isHardenedOSX");

public final List<String> methodNames;

Expand Down
65 changes: 37 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 All @@ -23,8 +23,10 @@

package jdk.test.lib;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -242,13 +244,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 @@ -260,38 +262,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 @@ -138,12 +138,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

3 comments on commit 16e0ad0

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@luchenlin
Copy link

Choose a reason for hiding this comment

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

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 16e0ad0 Feb 27, 2024

Choose a reason for hiding this comment

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

@luchenlin Could not automatically backport 16e0ad0a to openjdk/jdk11u-dev due to conflicts in the following files:

  • test/hotspot/jtreg/ProblemList.txt
  • test/hotspot/jtreg/testlibrary_tests/TestMutuallyExclusivePlatformPredicates.java
  • test/lib/jdk/test/lib/Platform.java
  • test/lib/jdk/test/lib/SA/SATestUtils.java
  • test/lib/jdk/test/lib/util/CoreUtils.java

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk11u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk11u-dev.git master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b backport-luchenlin-16e0ad0a

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk.git 16e0ad0ad088af3ba1c9903ed8df60799a1ba651

# Backport the commit
$ git cherry-pick --no-commit 16e0ad0ad088af3ba1c9903ed8df60799a1ba651
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 16e0ad0ad088af3ba1c9903ed8df60799a1ba651'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk11u-dev with the title Backport 16e0ad0ad088af3ba1c9903ed8df60799a1ba651.

Below you can find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 16e0ad0a from the openjdk/jdk repository.

The commit being backported was authored by Chris Plummer on 26 Jan 2022 and was reviewed by David Holmes and Kevin Walls.

Thanks!

Please sign in to comment.