Skip to content

Commit c809d34

Browse files
committedJan 14, 2022
8279924: [PPC64, s390] implement frame::is_interpreted_frame_valid checks
Reviewed-by: rrich, mbaesken
1 parent 4b520f0 commit c809d34

File tree

2 files changed

+102
-8
lines changed

2 files changed

+102
-8
lines changed
 

‎src/hotspot/cpu/ppc/frame_ppc.cpp

+51-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2012, 2021 SAP SE. All rights reserved.
2+
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2012, 2022 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -294,9 +294,56 @@ void frame::patch_pc(Thread* thread, address pc) {
294294
}
295295

296296
bool frame::is_interpreted_frame_valid(JavaThread* thread) const {
297-
// Is there anything to do?
298297
assert(is_interpreted_frame(), "Not an interpreted frame");
299-
return true;
298+
// These are reasonable sanity checks
299+
if (fp() == 0 || (intptr_t(fp()) & (wordSize-1)) != 0) {
300+
return false;
301+
}
302+
if (sp() == 0 || (intptr_t(sp()) & (wordSize-1)) != 0) {
303+
return false;
304+
}
305+
if (fp() - (abi_minframe_size + ijava_state_size) < sp()) {
306+
return false;
307+
}
308+
// These are hacks to keep us out of trouble.
309+
// The problem with these is that they mask other problems
310+
if (fp() <= sp()) { // this attempts to deal with unsigned comparison above
311+
return false;
312+
}
313+
314+
// do some validation of frame elements
315+
316+
// first the method
317+
318+
Method* m = *interpreter_frame_method_addr();
319+
320+
// validate the method we'd find in this potential sender
321+
if (!Method::is_valid_method(m)) return false;
322+
323+
// stack frames shouldn't be much larger than max_stack elements
324+
// this test requires the use of unextended_sp which is the sp as seen by
325+
// the current frame, and not sp which is the "raw" pc which could point
326+
// further because of local variables of the callee method inserted after
327+
// method arguments
328+
if (fp() - unextended_sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) {
329+
return false;
330+
}
331+
332+
// validate bci/bcx
333+
334+
address bcp = interpreter_frame_bcp();
335+
if (m->validate_bci_from_bcp(bcp) < 0) {
336+
return false;
337+
}
338+
339+
// validate constantPoolCache*
340+
ConstantPoolCache* cp = *interpreter_frame_cache_addr();
341+
if (MetaspaceObj::is_valid(cp) == false) return false;
342+
343+
// validate locals
344+
345+
address locals = (address) *interpreter_frame_locals_addr();
346+
return thread->is_in_stack_range_incl(locals, (address)fp());
300347
}
301348

302349
BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {

‎src/hotspot/cpu/s390/frame_s390.cpp

+51-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2016, 2019 SAP SE. All rights reserved.
2+
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2016, 2022 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -298,9 +298,56 @@ void frame::patch_pc(Thread* thread, address pc) {
298298
}
299299

300300
bool frame::is_interpreted_frame_valid(JavaThread* thread) const {
301-
// Is there anything to do?
302301
assert(is_interpreted_frame(), "Not an interpreted frame");
303-
return true;
302+
// These are reasonable sanity checks
303+
if (fp() == 0 || (intptr_t(fp()) & (wordSize-1)) != 0) {
304+
return false;
305+
}
306+
if (sp() == 0 || (intptr_t(sp()) & (wordSize-1)) != 0) {
307+
return false;
308+
}
309+
if (fp() - (z_abi_16_size + z_ijava_state_size) < sp()) {
310+
return false;
311+
}
312+
// These are hacks to keep us out of trouble.
313+
// The problem with these is that they mask other problems
314+
if (fp() <= sp()) { // this attempts to deal with unsigned comparison above
315+
return false;
316+
}
317+
318+
// do some validation of frame elements
319+
320+
// first the method
321+
322+
Method* m = *interpreter_frame_method_addr();
323+
324+
// validate the method we'd find in this potential sender
325+
if (!Method::is_valid_method(m)) return false;
326+
327+
// stack frames shouldn't be much larger than max_stack elements
328+
// this test requires the use of unextended_sp which is the sp as seen by
329+
// the current frame, and not sp which is the "raw" pc which could point
330+
// further because of local variables of the callee method inserted after
331+
// method arguments
332+
if (fp() - unextended_sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) {
333+
return false;
334+
}
335+
336+
// validate bci/bcx
337+
338+
address bcp = interpreter_frame_bcp();
339+
if (m->validate_bci_from_bcp(bcp) < 0) {
340+
return false;
341+
}
342+
343+
// validate constantPoolCache*
344+
ConstantPoolCache* cp = *interpreter_frame_cache_addr();
345+
if (MetaspaceObj::is_valid(cp) == false) return false;
346+
347+
// validate locals
348+
349+
address locals = (address) *interpreter_frame_locals_addr();
350+
return thread->is_in_stack_range_incl(locals, (address)fp());
304351
}
305352

306353
BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {

0 commit comments

Comments
 (0)
Please sign in to comment.