Skip to content

Commit 6f55625

Browse files
authored
Merge branch 'master' into goetz_backport_8322140
2 parents 62d5fd0 + 38c3f72 commit 6f55625

File tree

27 files changed

+1113
-146
lines changed

27 files changed

+1113
-146
lines changed

src/hotspot/share/memory/guardedMemory.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@
2727
#include "memory/guardedMemory.hpp"
2828
#include "runtime/os.hpp"
2929

30-
void* GuardedMemory::wrap_copy(const void* ptr, const size_t len, const void* tag) {
30+
void* GuardedMemory::wrap_copy(const void* ptr, const size_t len,
31+
const void* tag, const void* tag2) {
3132
size_t total_sz = GuardedMemory::get_total_size(len);
3233
void* outerp = os::malloc(total_sz, mtInternal);
3334
if (outerp != nullptr) {
34-
GuardedMemory guarded(outerp, len, tag);
35+
GuardedMemory guarded(outerp, len, tag, tag2);
3536
void* innerp = guarded.get_user_ptr();
3637
if (ptr != nullptr) {
3738
memcpy(innerp, ptr, len);
@@ -60,8 +61,8 @@ void GuardedMemory::print_on(outputStream* st) const {
6061
return;
6162
}
6263
st->print_cr("GuardedMemory(" PTR_FORMAT ") base_addr=" PTR_FORMAT
63-
" tag=" PTR_FORMAT " user_size=" SIZE_FORMAT " user_data=" PTR_FORMAT,
64-
p2i(this), p2i(_base_addr), p2i(get_tag()), get_user_size(), p2i(get_user_ptr()));
64+
" tag=" PTR_FORMAT "tag2=" PTR_FORMAT " user_size=" SIZE_FORMAT " user_data=" PTR_FORMAT,
65+
p2i(this), p2i(_base_addr), p2i(get_tag()), p2i(get_tag2()), get_user_size(), p2i(get_user_ptr()));
6566

6667
Guard* guard = get_head_guard();
6768
st->print_cr(" Header guard @" PTR_FORMAT " is %s", p2i(guard), (guard->verify() ? "OK" : "BROKEN"));

src/hotspot/share/memory/guardedMemory.hpp

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,7 @@
2626
#define SHARE_MEMORY_GUARDEDMEMORY_HPP
2727

2828
#include "memory/allocation.hpp"
29+
#include "runtime/os.hpp"
2930
#include "utilities/globalDefinitions.hpp"
3031

3132
/**
@@ -41,15 +42,19 @@
4142
* |Offset | Content | Description |
4243
* |------------------------------------------------------------
4344
* |base_addr | 0xABABABABABABABAB | Head guard |
44-
* |+16 | <size_t:user_size> | User data size |
45-
* |+sizeof(uintptr_t) | <tag> | Tag word |
45+
* |+GUARD_SIZE | <size_t:user_size> | User data size |
46+
* |+sizeof(size_t) | <tag> | Tag word |
47+
* |+sizeof(void*) | <tag2> | Tag word |
48+
* |+sizeof(void*) | <pad bytes> | Padding |
4649
* |+sizeof(void*) | 0xF1 <user_data> ( | User data |
4750
* |+user_size | 0xABABABABABABABAB | Tail guard |
4851
* -------------------------------------------------------------
4952
*
5053
* Where:
5154
* - guard padding uses "badResourceValue" (0xAB)
52-
* - tag word is general purpose
55+
* - tag word and tag2 word are general purpose
56+
* - padding is inserted as-needed by the compiler to ensure
57+
* the user data is aligned on a 16-byte boundary
5358
* - user data
5459
* -- initially padded with "uninitBlockPad" (0xF1),
5560
* -- to "freeBlockPad" (0xBA), when freed
@@ -111,6 +116,10 @@ class GuardedMemory : StackObj { // Wrapper on stack
111116
}
112117

113118
bool verify() const {
119+
// We may not be able to dereference directly.
120+
if (!os::is_readable_range((const void*) _guard, (const void*) (_guard + GUARD_SIZE))) {
121+
return false;
122+
}
114123
u_char* c = (u_char*) _guard;
115124
u_char* end = c + GUARD_SIZE;
116125
while (c < end) {
@@ -126,24 +135,30 @@ class GuardedMemory : StackObj { // Wrapper on stack
126135

127136
/**
128137
* Header guard and size
138+
*
139+
* NB: the size and placement of the GuardHeader must be such that the
140+
* user-ptr is maximally aligned i.e. 16-byte alignment for x86 ABI for
141+
* stack alignment and use of vector (xmm) instructions. We use alignas
142+
* to achieve this.
129143
*/
130-
class GuardHeader : Guard {
144+
class alignas(16) GuardHeader : Guard {
131145
friend class GuardedMemory;
132146
protected:
133-
// Take care in modifying fields here, will effect alignment
134-
// e.g. x86 ABI 16 byte stack alignment
135147
union {
136148
uintptr_t __unused_full_word1;
137149
size_t _user_size;
138150
};
139151
void* _tag;
152+
void* _tag2;
140153
public:
141154
void set_user_size(const size_t usz) { _user_size = usz; }
142155
size_t get_user_size() const { return _user_size; }
143156

144157
void set_tag(const void* tag) { _tag = (void*) tag; }
145158
void* get_tag() const { return _tag; }
146159

160+
void set_tag2(const void* tag2) { _tag2 = (void*) tag2; }
161+
void* get_tag2() const { return _tag2; }
147162
}; // GuardedMemory::GuardHeader
148163

149164
// Guarded Memory...
@@ -162,9 +177,11 @@ class GuardedMemory : StackObj { // Wrapper on stack
162177
* @param base_ptr allocation wishing to be wrapped, must be at least "GuardedMemory::get_total_size()" bytes.
163178
* @param user_size the size of the user data to be wrapped.
164179
* @param tag optional general purpose tag.
180+
* @param tag2 optional second general purpose tag.
165181
*/
166-
GuardedMemory(void* base_ptr, const size_t user_size, const void* tag = nullptr) {
167-
wrap_with_guards(base_ptr, user_size, tag);
182+
GuardedMemory(void* base_ptr, const size_t user_size,
183+
const void* tag = nullptr, const void* tag2 = nullptr) {
184+
wrap_with_guards(base_ptr, user_size, tag, tag2);
168185
}
169186

170187
/**
@@ -189,16 +206,19 @@ class GuardedMemory : StackObj { // Wrapper on stack
189206
* @param base_ptr allocation wishing to be wrapped, must be at least "GuardedMemory::get_total_size()" bytes.
190207
* @param user_size the size of the user data to be wrapped.
191208
* @param tag optional general purpose tag.
209+
* @param tag2 optional second general purpose tag.
192210
*
193211
* @return user data pointer (inner pointer to supplied "base_ptr").
194212
*/
195-
void* wrap_with_guards(void* base_ptr, size_t user_size, const void* tag = nullptr) {
213+
void* wrap_with_guards(void* base_ptr, size_t user_size,
214+
const void* tag = nullptr, const void* tag2 = nullptr) {
196215
assert(base_ptr != nullptr, "Attempt to wrap null with memory guard");
197216
_base_addr = (u_char*)base_ptr;
198217
get_head_guard()->build();
199218
get_head_guard()->set_user_size(user_size);
200219
get_tail_guard()->build();
201220
set_tag(tag);
221+
set_tag2(tag2);
202222
set_user_bytes(uninitBlockPad);
203223
assert(verify_guards(), "Expected valid memory guards");
204224
return get_user_ptr();
@@ -230,6 +250,20 @@ class GuardedMemory : StackObj { // Wrapper on stack
230250
*/
231251
void* get_tag() const { return get_head_guard()->get_tag(); }
232252

253+
/**
254+
* Set the second general purpose tag.
255+
*
256+
* @param tag general purpose tag.
257+
*/
258+
void set_tag2(const void* tag) { get_head_guard()->set_tag2(tag); }
259+
260+
/**
261+
* Return the second general purpose tag.
262+
*
263+
* @return the second general purpose tag, defaults to null.
264+
*/
265+
void* get_tag2() const { return get_head_guard()->get_tag2(); }
266+
233267
/**
234268
* Return the size of the user data.
235269
*
@@ -302,10 +336,12 @@ class GuardedMemory : StackObj { // Wrapper on stack
302336
* @param ptr the memory to be copied
303337
* @param len the length of the copy
304338
* @param tag optional general purpose tag (see GuardedMemory::get_tag())
339+
* @param tag2 optional general purpose tag (see GuardedMemory::get_tag2())
305340
*
306341
* @return guarded wrapped memory pointer to the user area, or null if OOM.
307342
*/
308-
static void* wrap_copy(const void* p, const size_t len, const void* tag = nullptr);
343+
static void* wrap_copy(const void* p, const size_t len,
344+
const void* tag = nullptr, const void* tag2 = nullptr);
309345

310346
/**
311347
* Free wrapped copy.

src/hotspot/share/prims/jniCheck.cpp

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -351,24 +351,33 @@ check_is_obj_array(JavaThread* thr, jarray jArray) {
351351
}
352352
}
353353

354+
// Arbitrary (but well-known) tag for GetStringChars
355+
const void* STRING_TAG = (void*)0x47114711;
356+
357+
// Arbitrary (but well-known) tag for GetStringUTFChars
358+
const void* STRING_UTF_TAG = (void*) 0x48124812;
359+
360+
// Arbitrary (but well-known) tag for GetPrimitiveArrayCritical
361+
const void* CRITICAL_TAG = (void*)0x49134913;
362+
354363
/*
355364
* Copy and wrap array elements for bounds checking.
356365
* Remember the original elements (GuardedMemory::get_tag())
357366
*/
358367
static void* check_jni_wrap_copy_array(JavaThread* thr, jarray array,
359-
void* orig_elements) {
368+
void* orig_elements, jboolean is_critical = JNI_FALSE) {
360369
void* result;
361370
IN_VM(
362371
oop a = JNIHandles::resolve_non_null(array);
363372
size_t len = arrayOop(a)->length() <<
364373
TypeArrayKlass::cast(a->klass())->log2_element_size();
365-
result = GuardedMemory::wrap_copy(orig_elements, len, orig_elements);
374+
result = GuardedMemory::wrap_copy(orig_elements, len, orig_elements, is_critical ? CRITICAL_TAG : nullptr);
366375
)
367376
return result;
368377
}
369378

370379
static void* check_wrapped_array(JavaThread* thr, const char* fn_name,
371-
void* obj, void* carray, size_t* rsz) {
380+
void* obj, void* carray, size_t* rsz, jboolean is_critical) {
372381
if (carray == nullptr) {
373382
tty->print_cr("%s: elements vector null" PTR_FORMAT, fn_name, p2i(obj));
374383
NativeReportJNIFatalError(thr, "Elements vector null");
@@ -387,6 +396,29 @@ static void* check_wrapped_array(JavaThread* thr, const char* fn_name,
387396
DEBUG_ONLY(guarded.print_on(tty);) // This may crash.
388397
NativeReportJNIFatalError(thr, err_msg("%s: unrecognized elements", fn_name));
389398
}
399+
if (orig_result == STRING_TAG || orig_result == STRING_UTF_TAG) {
400+
bool was_utf = orig_result == STRING_UTF_TAG;
401+
tty->print_cr("%s: called on something allocated by %s",
402+
fn_name, was_utf ? "GetStringUTFChars" : "GetStringChars");
403+
DEBUG_ONLY(guarded.print_on(tty);) // This may crash.
404+
NativeReportJNIFatalError(thr, err_msg("%s called on something allocated by %s",
405+
fn_name, was_utf ? "GetStringUTFChars" : "GetStringChars"));
406+
}
407+
408+
if (is_critical && (guarded.get_tag2() != CRITICAL_TAG)) {
409+
tty->print_cr("%s: called on something not allocated by GetPrimitiveArrayCritical", fn_name);
410+
DEBUG_ONLY(guarded.print_on(tty);) // This may crash.
411+
NativeReportJNIFatalError(thr, err_msg("%s called on something not allocated by GetPrimitiveArrayCritical",
412+
fn_name));
413+
}
414+
415+
if (!is_critical && (guarded.get_tag2() == CRITICAL_TAG)) {
416+
tty->print_cr("%s: called on something allocated by GetPrimitiveArrayCritical", fn_name);
417+
DEBUG_ONLY(guarded.print_on(tty);) // This may crash.
418+
NativeReportJNIFatalError(thr, err_msg("%s called on something allocated by GetPrimitiveArrayCritical",
419+
fn_name));
420+
}
421+
390422
if (rsz != nullptr) {
391423
*rsz = guarded.get_user_size();
392424
}
@@ -396,7 +428,7 @@ static void* check_wrapped_array(JavaThread* thr, const char* fn_name,
396428
static void* check_wrapped_array_release(JavaThread* thr, const char* fn_name,
397429
void* obj, void* carray, jint mode, jboolean is_critical) {
398430
size_t sz;
399-
void* orig_result = check_wrapped_array(thr, fn_name, obj, carray, &sz);
431+
void* orig_result = check_wrapped_array(thr, fn_name, obj, carray, &sz, is_critical);
400432
switch (mode) {
401433
case 0:
402434
memcpy(orig_result, carray, sz);
@@ -1431,9 +1463,6 @@ JNI_ENTRY_CHECKED(jsize,
14311463
return result;
14321464
JNI_END
14331465

1434-
// Arbitrary (but well-known) tag
1435-
const void* STRING_TAG = (void*)0x47114711;
1436-
14371466
JNI_ENTRY_CHECKED(const jchar *,
14381467
checked_jni_GetStringChars(JNIEnv *env,
14391468
jstring str,
@@ -1515,9 +1544,6 @@ JNI_ENTRY_CHECKED(jsize,
15151544
return result;
15161545
JNI_END
15171546

1518-
// Arbitrary (but well-known) tag - different than GetStringChars
1519-
const void* STRING_UTF_TAG = (void*) 0x48124812;
1520-
15211547
JNI_ENTRY_CHECKED(const char *,
15221548
checked_jni_GetStringUTFChars(JNIEnv *env,
15231549
jstring str,
@@ -1839,7 +1865,7 @@ JNI_ENTRY_CHECKED(void *,
18391865
)
18401866
void *result = UNCHECKED()->GetPrimitiveArrayCritical(env, array, isCopy);
18411867
if (result != nullptr) {
1842-
result = check_jni_wrap_copy_array(thr, array, result);
1868+
result = check_jni_wrap_copy_array(thr, array, result, JNI_TRUE);
18431869
}
18441870
functionExit(thr);
18451871
return result;

src/hotspot/share/runtime/vmThread.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -409,17 +409,17 @@ void VMThread::inner_execute(VM_Operation* op) {
409409
HandleMark hm(VMThread::vm_thread());
410410

411411
const char* const cause = op->cause();
412-
EventMarkVMOperation em("Executing %sVM operation: %s%s%s%s",
413-
prev_vm_operation != nullptr ? "nested " : "",
414-
op->name(),
415-
cause != nullptr ? " (" : "",
416-
cause != nullptr ? cause : "",
417-
cause != nullptr ? ")" : "");
418-
419-
log_debug(vmthread)("Evaluating %s %s VM operation: %s",
420-
prev_vm_operation != nullptr ? "nested" : "",
421-
_cur_vm_operation->evaluate_at_safepoint() ? "safepoint" : "non-safepoint",
422-
_cur_vm_operation->name());
412+
stringStream ss;
413+
ss.print("Executing%s%s VM operation: %s",
414+
prev_vm_operation != nullptr ? " nested" : "",
415+
op->evaluate_at_safepoint() ? " safepoint" : " non-safepoint",
416+
op->name());
417+
if (cause != nullptr) {
418+
ss.print(" (%s)", cause);
419+
}
420+
421+
EventMarkVMOperation em("%s", ss.freeze());
422+
log_debug(vmthread)("%s", ss.freeze());
423423

424424
bool end_safepoint = false;
425425
bool has_timeout_task = (_timeout_task != nullptr);

src/hotspot/share/services/mallocHeader.inline.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ inline OutTypeParam MallocHeader::resolve_checked_impl(InTypeParam memblock) {
104104
OutTypeParam header_pointer = (OutTypeParam)memblock - 1;
105105
if (!header_pointer->check_block_integrity(msg, sizeof(msg), &corruption)) {
106106
header_pointer->print_block_on_error(tty, corruption != nullptr ? corruption : (address)header_pointer);
107-
fatal("NMT corruption: Block at " PTR_FORMAT ": %s", p2i(memblock), msg);
107+
fatal("NMT has detected a memory corruption bug. Block at " PTR_FORMAT ": %s", p2i(memblock), msg);
108108
}
109109
return header_pointer;
110110
}

src/java.base/share/classes/sun/security/ssl/SignatureScheme.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ enum SignatureScheme {
132132
"DSA",
133133
ProtocolVersion.PROTOCOLS_TO_12),
134134
ECDSA_SHA1 (0x0203, "ecdsa_sha1", "SHA1withECDSA",
135-
"EC",
136-
ProtocolVersion.PROTOCOLS_TO_13),
135+
"EC", null, null, -1,
136+
ProtocolVersion.PROTOCOLS_TO_13,
137+
ProtocolVersion.PROTOCOLS_TO_12),
137138
RSA_PKCS1_SHA1 (0x0201, "rsa_pkcs1_sha1", "SHA1withRSA",
138139
"RSA", null, null, 511,
139140
ProtocolVersion.PROTOCOLS_TO_13,

src/java.base/share/conf/security/java.security

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,8 @@ http.auth.digest.disabledAlgorithms = MD5, SHA-1
784784
# rsa_pkcs1_sha1, secp224r1, TLS_RSA_*
785785
jdk.tls.disabledAlgorithms=SSLv3, TLSv1, TLSv1.1, DTLSv1.0, RC4, DES, \
786786
MD5withRSA, DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, \
787-
ECDH, TLS_RSA_*
787+
ECDH, TLS_RSA_*, rsa_pkcs1_sha1 usage HandshakeSignature, \
788+
ecdsa_sha1 usage HandshakeSignature, dsa_sha1 usage HandshakeSignature
788789

789790
#
790791
# Legacy algorithms for Secure Socket Layer/Transport Layer Security (SSL/TLS)

src/java.desktop/share/classes/java/awt/color/ICC_ColorSpace.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -140,10 +140,11 @@ public ICC_ColorSpace(ICC_Profile profile) {
140140
if (profileClass != ICC_Profile.CLASS_INPUT
141141
&& profileClass != ICC_Profile.CLASS_DISPLAY
142142
&& profileClass != ICC_Profile.CLASS_OUTPUT
143+
&& profileClass != ICC_Profile.CLASS_DEVICELINK
143144
&& profileClass != ICC_Profile.CLASS_COLORSPACECONVERSION
144145
&& profileClass != ICC_Profile.CLASS_NAMEDCOLOR
145146
&& profileClass != ICC_Profile.CLASS_ABSTRACT) {
146-
throw new IllegalArgumentException("Invalid profile type");
147+
throw new IllegalArgumentException("Invalid profile class");
147148
}
148149

149150
thisProfile = profile;

0 commit comments

Comments
 (0)