Implement range of memory access validation instead of pointer and use

it. Export new validator to users.
Various small fixes
This commit is contained in:
2020-05-06 11:49:22 +04:00
parent f483155e07
commit 657ddf182b
8 changed files with 27 additions and 18 deletions
+6 -6
View File
@@ -7,6 +7,10 @@
#include <inttypes.h>
#include <stdbool.h>
#include <sys/mman.h>
#include <unistd.h>
#include <errno.h>
#include "context.h"
int32_t decode_sleb128(uint8_t *sleb128)
@@ -116,11 +120,7 @@ unsigned getSLEB128Size(int64_t Value)
return Size;
}
#include <sys/mman.h>
#include <unistd.h>
#include <errno.h>
int pst_pointer_valid(void *p)
int pst_pointer_valid(void *p, uint32_t size)
{
long page_size = sysconf(_SC_PAGESIZE);
if(page_size < 0) {
@@ -130,7 +130,7 @@ int pst_pointer_valid(void *p)
void *aligned = (void *)((((long)p) / page_size) * page_size);
//void *aligned = (void *)((uintptr_t)p & ~(page_size - 1));
if(msync(aligned, page_size, MS_ASYNC) == 0) {
if(msync(aligned, size, MS_ASYNC) == 0) {
return 0;
}
+1 -1
View File
@@ -21,6 +21,6 @@
int32_t decode_sleb128(uint8_t *sleb128);
uint32_t decode_uleb128(uint8_t *uleb128);
int pst_pointer_valid(void *p);
int pst_pointer_valid(void *p, uint32_t size);
#endif // __PST_COMMON_H__
+1 -1
View File
@@ -147,7 +147,7 @@ void pst_call_site_init(pst_call_site* site, pst_context* c, uint64_t tgt, const
site->target = tgt;
if(orn) {
site->origin = strdup(orn);
site->origin = pst_strdup(orn);
} else {
site->origin = NULL;
}
+2 -1
View File
@@ -429,13 +429,14 @@ void pst_function_init(pst_function* fn, pst_context* _ctx, pst_function* _paren
fn->info.pc = 0;
fn->info.lowpc = 0;
fn->info.highpc = 0;
bzero(&fn->context, sizeof(fn->context));
fn->info.name = NULL;
fn->info.line = -1;
fn->info.file = NULL;
fn->info.sp = 0;
fn->info.flags = 0;
// internal fields
bzero(&fn->context, sizeof(fn->context));
fn->die = NULL;
list_head_init(&fn->params);
pst_call_site_storage_init(&fn->call_sites, _ctx);
+6 -5
View File
@@ -332,6 +332,8 @@ bool parameter_handle_type(pst_parameter* param, Dwarf_Die* result)
case DW_ATE_decimal_float:
parameter_add_type(param, type_name, PARAM_TYPE_FLOAT);
break;
default:
pst_log(SEVERITY_WARNING, "Unknown parameter base type encodings 0x%lX", enc_type);
}
}
@@ -379,6 +381,9 @@ bool parameter_handle_type(pst_parameter* param, Dwarf_Die* result)
case DW_TAG_volatile_type:
parameter_add_type(param, NULL, PARAM_VOLATILE);
break;
case DW_TAG_string_type:
pst_log(SEVERITY_DEBUG, "String type, skipping");
break;
default:
pst_log(SEVERITY_WARNING, "Unknown 0x%X tag type", dwarf_tag(&ret_die));
break;
@@ -445,14 +450,10 @@ bool parameter_handle_dwarf(pst_parameter* param, Dwarf_Die* result, pst_functio
pst_log(SEVERITY_WARNING, "Unknown form '0x%X' of attribute for Constant value", dwarf_whatform(attr));
param->info.flags &= ~PARAM_HAS_VALUE;
}
if(param->info.flags & PARAM_HAS_VALUE) {
pst_log(SEVERITY_DEBUG, "Parameter constant value: 0x%lX", param->info.value);
}
}
// check pointer validity
if((param->info.flags & (PARAM_TYPE_POINTER | PARAM_TYPE_FUNCPTR)) && pst_pointer_valid((void*)param->info.value)) {
if((param->info.flags & (PARAM_TYPE_POINTER | PARAM_TYPE_FUNCPTR)) && pst_pointer_valid((void*)param->info.value, sizeof((void*)param->info.size))) {
param->info.flags |= PARAM_INVALID;
}
+1 -1
View File
@@ -58,7 +58,7 @@ typedef union {
void* ptr;
} pst_sized_value;
typedef struct __pst_dwarf_value {
typedef struct {
list_node node; // uplink
// fields