Skip to content

Commit d833173

Browse files
committedMay 30, 2022
8286711: AArch64: serviceability agent tests fail with PAC enabled
Reviewed-by: dholmes, cjplummer
1 parent 19fb8ab commit d833173

File tree

5 files changed

+41
-8
lines changed

5 files changed

+41
-8
lines changed
 

‎src/hotspot/cpu/aarch64/pauth_aarch64.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
#ifndef CPU_AARCH64_PAUTH_AARCH64_HPP
2626
#define CPU_AARCH64_PAUTH_AARCH64_HPP
2727

28+
#include "runtime/vm_version.hpp"
29+
#include "utilities/globalDefinitions.hpp"
30+
#include "utilities/macros.hpp"
31+
2832
#include OS_CPU_HEADER_INLINE(pauth)
2933

3034
// Support for ROP Protection in VM code.

‎src/hotspot/cpu/aarch64/vmStructs_aarch64.hpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2014, Red Hat Inc. All rights reserved. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -31,9 +31,12 @@
3131
// referenced by vmStructs.cpp.
3232

3333
#define VM_STRUCTS_CPU(nonstatic_field, static_field, unchecked_nonstatic_field, volatile_nonstatic_field, nonproduct_nonstatic_field, c2_nonstatic_field, unchecked_c1_static_field, unchecked_c2_static_field) \
34-
volatile_nonstatic_field(JavaFrameAnchor, _last_Java_fp, intptr_t*)
34+
volatile_nonstatic_field(JavaFrameAnchor, _last_Java_fp, intptr_t*) \
35+
static_field(VM_Version, _rop_protection, bool) \
36+
static_field(VM_Version, _pac_mask, uintptr_t)
3537

36-
#define VM_TYPES_CPU(declare_type, declare_toplevel_type, declare_oop_type, declare_integer_type, declare_unsigned_integer_type, declare_c1_toplevel_type, declare_c2_type, declare_c2_toplevel_type)
38+
#define VM_TYPES_CPU(declare_type, declare_toplevel_type, declare_oop_type, declare_integer_type, declare_unsigned_integer_type, declare_c1_toplevel_type, declare_c2_type, declare_c2_toplevel_type) \
39+
declare_toplevel_type(VM_Version)
3740

3841
#define VM_INT_CONSTANTS_CPU(declare_constant, declare_preprocessor_constant, declare_c1_constant, declare_c2_constant, declare_c2_preprocessor_constant)
3942

‎src/hotspot/cpu/aarch64/vm_version_aarch64.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525

2626
#include "precompiled.hpp"
27+
#include "pauth_aarch64.hpp"
2728
#include "runtime/arguments.hpp"
2829
#include "runtime/globals_extension.hpp"
2930
#include "runtime/java.hpp"
@@ -46,6 +47,7 @@ int VM_Version::_dcache_line_size;
4647
int VM_Version::_icache_line_size;
4748
int VM_Version::_initial_sve_vector_length;
4849
bool VM_Version::_rop_protection;
50+
uintptr_t VM_Version::_pac_mask;
4951

5052
SpinWait VM_Version::_spin_wait;
5153

@@ -444,8 +446,12 @@ void VM_Version::initialize() {
444446
vm_exit_during_initialization(err_msg("Unsupported UseBranchProtection: %s", UseBranchProtection));
445447
}
446448

447-
// The frame pointer must be preserved for ROP protection.
448449
if (_rop_protection == true) {
450+
// Determine the mask of address bits used for PAC. Clear bit 55 of
451+
// the input to make it look like a user address.
452+
_pac_mask = (uintptr_t)pauth_strip_pointer((address)~(UINT64_C(1) << 55));
453+
454+
// The frame pointer must be preserved for ROP protection.
449455
if (FLAG_IS_DEFAULT(PreserveFramePointer) == false && PreserveFramePointer == false ) {
450456
vm_exit_during_initialization(err_msg("PreserveFramePointer cannot be disabled for ROP-protection"));
451457
}

‎src/hotspot/cpu/aarch64/vm_version_aarch64.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "utilities/sizes.hpp"
3232

3333
class VM_Version : public Abstract_VM_Version {
34+
friend class VMStructs;
3435
friend class JVMCIVMStructs;
3536

3637
protected:
@@ -46,6 +47,7 @@ class VM_Version : public Abstract_VM_Version {
4647
static int _icache_line_size;
4748
static int _initial_sve_vector_length;
4849
static bool _rop_protection;
50+
static uintptr_t _pac_mask;
4951

5052
static SpinWait _spin_wait;
5153

‎src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/aarch64/AARCH64Frame.java

+22-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2015, 2019, Red Hat Inc.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -70,6 +70,9 @@ public class AARCH64Frame extends Frame {
7070
// Native frames
7171
private static final int NATIVE_FRAME_INITIAL_PARAM_OFFSET = 2;
7272

73+
private static CIntegerField ropProtectionField;
74+
private static CIntegerField pacMaskField;
75+
7376
private static VMReg fp = new VMReg(29 << 1);
7477

7578
static {
@@ -90,8 +93,11 @@ private static synchronized void initialize(TypeDataBase db) {
9093
INTERPRETER_FRAME_INITIAL_SP_OFFSET = INTERPRETER_FRAME_BCX_OFFSET - 1;
9194
INTERPRETER_FRAME_MONITOR_BLOCK_TOP_OFFSET = INTERPRETER_FRAME_INITIAL_SP_OFFSET;
9295
INTERPRETER_FRAME_MONITOR_BLOCK_BOTTOM_OFFSET = INTERPRETER_FRAME_INITIAL_SP_OFFSET;
93-
}
9496

97+
Type vmVersion = db.lookupType("VM_Version");
98+
ropProtectionField = vmVersion.getCIntegerField("_rop_protection");
99+
pacMaskField = vmVersion.getCIntegerField("_pac_mask");
100+
}
95101

96102
// an additional field beyond sp and pc:
97103
Address raw_fp; // frame pointer
@@ -391,7 +397,7 @@ private Frame senderForCompiledFrame(AARCH64RegisterMap map, CodeBlob cb) {
391397
Address senderSP = getUnextendedSP().addOffsetTo(cb.getFrameSize());
392398

393399
// The return_address is always the word on the stack
394-
Address senderPC = senderSP.getAddressAt(-1 * VM.getVM().getAddressSize());
400+
Address senderPC = stripPAC(senderSP.getAddressAt(-1 * VM.getVM().getAddressSize()));
395401

396402
// This is the saved value of FP which may or may not really be an FP.
397403
// It is only an FP if the sender is an interpreter frame.
@@ -445,7 +451,19 @@ public Address getLink() {
445451

446452
// Return address:
447453
public Address getSenderPCAddr() { return addressOfStackSlot(RETURN_ADDR_OFFSET); }
448-
public Address getSenderPC() { return getSenderPCAddr().getAddressAt(0); }
454+
public Address getSenderPC() { return stripPAC(getSenderPCAddr().getAddressAt(0)); }
455+
456+
// Remove any embedded pointer authentication code from an address.
457+
private Address stripPAC(Address addr) {
458+
// Really we should use the XPACI instruction to do this but we
459+
// can't access that from Java so rely on the mask of PAC bits
460+
// calculated by vm_version_aarch64.cpp on startup.
461+
if (ropProtectionField.getValue() != 0) {
462+
return addr.andWithMask(pacMaskField.getValue());
463+
} else {
464+
return addr;
465+
}
466+
}
449467

450468
// return address of param, zero origin index.
451469
public Address getNativeParamAddr(int idx) {

0 commit comments

Comments
 (0)
Please sign in to comment.