diff --git a/tools/transforms/OffsetInference.cpp b/tools/transforms/OffsetInference.cpp index 96fe92392658da0abdd0b683bb5c81beae59621e..b68dd266f8055ec6ec26082ed9426e716433f725 100644 --- a/tools/transforms/OffsetInference.cpp +++ b/tools/transforms/OffsetInference.cpp @@ -118,6 +118,8 @@ StackLayout* OffsetInference::SetupLayout(Function_t *func) //until entry is null, or entry has left the function. while(entry != NULL && (entry->GetFunction()==func)) { + + in_prologue[entry]=true; string matched; //Instruction_t* instr=*it; @@ -514,6 +516,21 @@ pn_p1_offsets = new PNStackLayout("P1 Layout",func->GetName(),stack_frame_size,s } else */ + + if(regexec(&(pn_regex->regex_push_anything), disasm_str.c_str(), max, pmatch, 0)==0) + { + if(!in_prologue[instr]) + { + cerr<<"Found push instruction not in prologue, marking as not canary safe\n"; + pn_direct_offsets->SetCanarySafe(false); + pn_scaled_offsets->SetCanarySafe(false); + pn_all_offsets->SetCanarySafe(false); + pn_p1_offsets->SetCanarySafe(false); + + } + } + + /* check for an lea with an rsp in it -- needs to be done before other regex's */ if(regexec(&(pn_regex->regex_lea_rsp), disasm_str.c_str(), 5, pmatch, 0)==0) { diff --git a/tools/transforms/OffsetInference.hpp b/tools/transforms/OffsetInference.hpp index b040e1938ed00acc3fb6013029a63a812734938a..d332ecfc86975dad40cadb122272d80ac9c12f5c 100644 --- a/tools/transforms/OffsetInference.hpp +++ b/tools/transforms/OffsetInference.hpp @@ -9,6 +9,7 @@ class OffsetInference : public PNStackLayoutInference { protected: + std::map<libIRDB::Instruction_t*, bool> in_prologue; std::map<libIRDB::Function_t*,PNStackLayout*> direct; std::map<libIRDB::Function_t*,PNStackLayout*> scaled; std::map<libIRDB::Function_t*,PNStackLayout*> all_offsets; diff --git a/tools/transforms/PNStackLayoutInference.hpp b/tools/transforms/PNStackLayoutInference.hpp index 45c8271954d15c38923ef72c9137ac619a534414..0e418d52d644e0de58440a64e407798adde1c1fe 100644 --- a/tools/transforms/PNStackLayoutInference.hpp +++ b/tools/transforms/PNStackLayoutInference.hpp @@ -6,6 +6,7 @@ #include "StackLayout.hpp" #include "PNStackLayout.hpp" #include <string> +#include <map> class PNStackLayoutInference {