|
1 | 1 | /*
|
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. |
4 | 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
5 | 5 | *
|
6 | 6 | * 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) {
|
294 | 294 | }
|
295 | 295 |
|
296 | 296 | bool frame::is_interpreted_frame_valid(JavaThread* thread) const {
|
297 |
| - // Is there anything to do? |
298 | 297 | 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()); |
300 | 347 | }
|
301 | 348 |
|
302 | 349 | BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {
|
|
0 commit comments