diff --git a/tools/transforms/PNMain.cpp b/tools/transforms/PNMain.cpp index 0f095f97d20cd4869f9ca99dbfb48e4ed0bc3d22..95ed2959c292a8d5a05a2c54b55b9c1dbb430445 100644 --- a/tools/transforms/PNMain.cpp +++ b/tools/transforms/PNMain.cpp @@ -71,6 +71,7 @@ enum RECURSIVE_MIN_STACK_PAD_OPTION, RECURSIVE_MAX_STACK_PAD_OPTION, SHOULD_DOUBLE_FRAME_SIZE_OPTION, + DOUBLE_THRESHOLD_OPTION, SELECTIVE_CANARIES_OPTION, SET_RANDOM_SEED, SET_CANARY_VALUE, @@ -98,6 +99,7 @@ static struct option const long_options[] = {"recursive_min_stack_padding",required_argument, NULL, RECURSIVE_MIN_STACK_PAD_OPTION}, {"recursive_max_stack_padding",required_argument, NULL, RECURSIVE_MAX_STACK_PAD_OPTION}, {"should_double_frame_size",required_argument, NULL, SHOULD_DOUBLE_FRAME_SIZE_OPTION}, + {"double_threshold_size",required_argument, NULL, DOUBLE_THRESHOLD_OPTION,}, {"selective_canaries",required_argument, NULL, SELECTIVE_CANARIES_OPTION}, {"random_seed",required_argument, NULL, SET_RANDOM_SEED}, {"canary_value",required_argument, NULL, SET_CANARY_VALUE}, @@ -337,6 +339,13 @@ int main(int argc, char **argv) pn_options->setRecursiveMaxStackPadding(recursive_max_stack_padding); break; } + case DOUBLE_THRESHOLD_OPTION: + { + const auto double_threshold = atoi(optarg); + pn_options->setDoubleThreshold(double_threshold); + break; + } + case SHOULD_DOUBLE_FRAME_SIZE_OPTION: { if(strcasecmp("true",optarg)==0) diff --git a/tools/transforms/PNStackLayout.cpp b/tools/transforms/PNStackLayout.cpp index 53390d49ad9b0e7273ee7518c2306d6c8214b8c7..6ea04b8360b7f327e80079d4de6e19d45a261f3e 100644 --- a/tools/transforms/PNStackLayout.cpp +++ b/tools/transforms/PNStackLayout.cpp @@ -85,7 +85,7 @@ unsigned int PNStackLayout::GetRandomPadding(unsigned int obj_size) - if(pn_options->getShouldDoubleFrameSize()) + if(pn_options->getShouldDoubleFrameSize() && obj_size < pn_options->getDoubleThreshold()) { //if the original frame size is not aligned, then add as many bytes as necessary to align it //for example, if 3 bytes over alignment, and the alignment stride is 8, then add 8 - 3, or 5 bytes. diff --git a/tools/transforms/globals.h b/tools/transforms/globals.h index 67292dadbf6ee9af1a92d51f2c0835d442fc5a6a..a43c585af8ffa8929a279524ee8bb276180285db 100644 --- a/tools/transforms/globals.h +++ b/tools/transforms/globals.h @@ -26,6 +26,7 @@ #include <stdlib.h> #include <sys/types.h> #include <unistd.h> +#include <limits.h> @@ -47,6 +48,7 @@ class PNOptions random_seed=getpid(); canary_value=0; canary_value_inited=false; + double_threshold=32*1024; // 32kb } void setMinStackPadding(int val) { min_stack_padding = val; } @@ -56,12 +58,14 @@ class PNOptions void setShouldDoubleFrameSize(bool val) { should_double_frame_size = val; } void setRandomSeed(int val) { random_seed = val; } void setCanaryValue(int val) { canary_value = val; canary_value_inited=true; } + void setDoubleThreshold(int val) { double_threshold = val; } int getMinStackPadding() const { return min_stack_padding; } int getMaxStackPadding() const { return max_stack_padding; } int getRecursiveMinStackPadding() const { return recursive_min_stack_padding; } int getRecursiveMaxStackPadding() const { return recursive_max_stack_padding; } bool getShouldDoubleFrameSize() const { return should_double_frame_size; } + int getDoubleThreshold() { return double_threshold; } int getRandomSeed() { return random_seed; } int getCanaryValue() { @@ -99,6 +103,8 @@ class PNOptions int canary_value; bool canary_value_inited; + int double_threshold; + std::set<std::string> canary_functions; };