-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8297967: Make frame::safe_for_sender safer #11461
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ | |
#include "runtime/javaCalls.hpp" | ||
#include "runtime/monitorChunk.hpp" | ||
#include "runtime/os.inline.hpp" | ||
#include "runtime/safefetch.hpp" | ||
#include "runtime/signature.hpp" | ||
#include "runtime/stubCodeGenerator.hpp" | ||
#include "runtime/stubRoutines.hpp" | ||
|
@@ -104,6 +105,11 @@ bool frame::safe_for_sender(JavaThread *thread) { | |
if (!fp_safe) { | ||
return false; | ||
} | ||
// check that the accessed stack slots are safe too | ||
if (SafeFetchN(this->fp() + return_addr_offset, 0) == 0 || | ||
SafeFetchN(this->fp() + interpreter_frame_sender_sp_offset, 0) == 0 || | ||
SafeFetchN(this->fp() + link_offset, 0) == 0 | ||
) return false; | ||
|
||
sender_pc = (address) this->fp()[return_addr_offset]; | ||
sender_sp = (intptr_t*) addr_at(sender_sp_offset); | ||
|
@@ -210,8 +216,7 @@ bool frame::safe_for_sender(JavaThread *thread) { | |
|
||
// Will the pc we fetch be non-zero (which we'll find at the oldest frame) | ||
|
||
if ((address) this->fp()[return_addr_offset] == nullptr) return false; | ||
|
||
if ((address) this->fp()[return_addr_offset] == NULL) return false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Accidental revert: "nullptr" -> "NULL". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I started the PR before the whole move, thanks for noticing this :) |
||
|
||
// could try and do some more potential verification of native frame if we could think of some... | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ | |
#include "runtime/javaCalls.hpp" | ||
#include "runtime/monitorChunk.hpp" | ||
#include "runtime/os.inline.hpp" | ||
#include "runtime/safefetch.hpp" | ||
#include "runtime/signature.hpp" | ||
#include "runtime/stackWatermarkSet.hpp" | ||
#include "runtime/stubCodeGenerator.hpp" | ||
|
@@ -129,6 +130,11 @@ bool frame::safe_for_sender(JavaThread *thread) { | |
if (!fp_safe) { | ||
return false; | ||
} | ||
// check that the accessed stack slots are safe too | ||
if (SafeFetchN(this->fp() + return_addr_offset, 0) == 0 || | ||
SafeFetchN(this->fp() + interpreter_frame_sender_sp_offset, 0) == 0 || | ||
SafeFetchN(this->fp() + link_offset, 0) == 0 | ||
) return false; | ||
|
||
sender_pc = (address)this->fp()[return_addr_offset]; | ||
// for interpreted frames, the value below is the sender "raw" sp, | ||
|
@@ -250,7 +256,8 @@ bool frame::safe_for_sender(JavaThread *thread) { | |
} | ||
|
||
// Will the pc we fetch be non-zero (which we'll find at the oldest frame) | ||
if ((address)this->fp()[return_addr_offset] == nullptr) { return false; } | ||
|
||
if ((address) this->fp()[return_addr_offset] == NULL) return false; | ||
Comment on lines
+259
to
+260
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Excess newline. Accidental revert: "nullptr" -> "NULL". |
||
|
||
return true; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ | |
#include "runtime/handles.inline.hpp" | ||
#include "runtime/javaCalls.hpp" | ||
#include "runtime/monitorChunk.hpp" | ||
#include "runtime/safefetch.hpp" | ||
#include "runtime/signature.hpp" | ||
#include "runtime/stackWatermarkSet.hpp" | ||
#include "runtime/stubCodeGenerator.hpp" | ||
|
@@ -123,6 +124,11 @@ bool frame::safe_for_sender(JavaThread *thread) { | |
if (!fp_safe) { | ||
return false; | ||
} | ||
// check that the accessed stack slots are safe too | ||
if (SafeFetchN(this->fp() + return_addr_offset, 0) == 0 || | ||
SafeFetchN(this->fp() + interpreter_frame_sender_sp_offset, 0) == 0 || | ||
SafeFetchN(this->fp() + link_offset, 0) == 0 | ||
) return false; | ||
|
||
sender_pc = (address) this->fp()[return_addr_offset]; | ||
// for interpreted frames, the value below is the sender "raw" sp, | ||
|
@@ -256,7 +262,7 @@ bool frame::safe_for_sender(JavaThread *thread) { | |
|
||
// Will the pc we fetch be non-zero (which we'll find at the oldest frame) | ||
|
||
if ( (address) this->fp()[return_addr_offset] == nullptr) return false; | ||
if ((address) this->fp()[return_addr_offset] == NULL) return false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Accidental revert: "nullptr" -> "NULL". |
||
|
||
|
||
// could try and do some more potential verification of native frame if we could think of some... | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So these three are
sender_sp
,sender_unextended_sp
andsaved_fp
a few lines below, right? So we can just SafeFetch-check those vars after we got them? This also highlights we want to check that those pointers are safe to fetch from.I.e.:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right, that looks much better