Skip to content

Commit

Permalink
Don't surpress compiler warnings on debug builds (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
tklengyel authored Aug 30, 2016
1 parent b7e48b9 commit cf9f0ee
Show file tree
Hide file tree
Showing 26 changed files with 417 additions and 202 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ before_install:
- cd volatility && python setup.py build && sudo python setup.py install
- cd ..

script: "./autogen.sh; ./configure; make clean; make"
script: "./autogen.sh; ./configure --enable-debug; make clean; make"

env:
global:
Expand Down
10 changes: 5 additions & 5 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
# DRAKVUF, and also available from #
# https://github.com/tklengyel/drakvuf/COPYING) #
# #
#*************************************************************************#
#*************************************************************************#

bin_PROGRAMS = drakvuf xen_memclone injector

Expand All @@ -127,10 +127,10 @@ endif

# Note that -pg is incompatible with HARDENING
if DEBUG
AM_CFLAGS += -DDRAKVUF_DEBUG -Wall -Wextra -Wno-override-init -Wno-strict-aliasing -g -ggdb3
AM_CFLAGS += -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-unused-variable
AM_CPPFLAGS += -DDRAKVUF_DEBUG -Wall -Wextra -Wno-strict-aliasing -g -ggdb3
AM_CPPFLAGS += -Wno-unused-parameter -Wno-unused-variable
AM_CFLAGS += -DDRAKVUF_DEBUG -Werror -Wall -Wextra -g -ggdb3
AM_CFLAGS += -Wno-missing-field-initializers
AM_CPPFLAGS += -DDRAKVUF_DEBUG -Werror -Wall -Wextra -g -ggdb3
AM_CPPFLAGS += -Wno-missing-field-initializers
if !HARDENING
AM_CFLAGS += -pg
AM_CPPFLAGS += -pg
Expand Down
5 changes: 3 additions & 2 deletions src/dirwatch/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,13 @@
# DRAKVUF, and also available from #
# https://github.com/tklengyel/drakvuf/COPYING) #
# #
#*************************************************************************#
#*************************************************************************#

bin_PROGRAMS = dirwatch

dirwatch_SOURCES = dirwatch.c
dirwatch_LDADD = ../xen_helper/libxenhelper.la

AM_CFLAGS = $(CFLAGS) $(GLIB_CFLAGS)
AM_CFLAGS = -Werror -Wall -Wextra $(CFLAGS) $(GLIB_CFLAGS)
AM_CFLAGS += -Wno-missing-field-initializers

27 changes: 14 additions & 13 deletions src/dirwatch/dirwatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@
#define CLEANUP_CMD "%s %u %u"
#define TCPDUMP_CMD "%s %u %s %s %s"

#define UNUSED(x) (void)(x)

struct start_drakvuf {
int threadid;
domid_t cloneID;
Expand All @@ -142,18 +144,16 @@ static const char *config_script;
static const char *drakvuf_script;
static const char *cleanup_script;
static const char *tcpdump_script;
static const char *name;
static domid_t domID;
static uint32_t threads;
static uint32_t injection_pid;

static GMutex locks[128];
static GMutex prepare_lock;

xen_interface_t *xen;

static void
make_clone(xen_interface_t *xen, domid_t *cloneID,
uint16_t vlan, char **clone_name)
make_clone(xen_interface_t *xen, domid_t *cloneID, uint16_t vlan, char **clone_name)
{
char *command = g_malloc0(snprintf(NULL, 0, CLONE_CMD, clone_script, domain_name, vlan, domain_config) + 1);
sprintf(command, CLONE_CMD, clone_script, domain_name, vlan, domain_config);
Expand All @@ -179,7 +179,7 @@ gpointer tcpdump(gpointer data) {

static inline int find_thread()
{
int i=0;
unsigned int i=0;
for (;i<threads;i++) {
if(g_mutex_trylock(&locks[i]))
return i;
Expand Down Expand Up @@ -272,16 +272,14 @@ static void prepare(char *sample, struct start_drakvuf *start)

void run_drakvuf(gpointer data, gpointer user_data)
{
UNUSED(user_data);
struct start_drakvuf *start = data;
char *command;
char *output, *err;
gint rc;
GThread *timer, *tcpd;

restart:
command = NULL;
output = NULL;
err = NULL;
rc = 0;
printf("[%i] Starting %s on domid %u\n", start->threadid, start->input, start->cloneID);

Expand Down Expand Up @@ -348,7 +346,8 @@ int main(int argc, char** argv)
{
DIR *dir;
struct dirent *ent;
int i, ret = 1, processed = 0;
unsigned int i, processed = 0;
int ret = 0;

if(argc!=14) {
printf("Not enough arguments: %i!\n", argc);
Expand Down Expand Up @@ -408,21 +407,23 @@ int main(int argc, char** argv)
closedir (dir);
} else {
printf("Failed to open target folder!\n");
goto exit;
ret = 1;
break;
}

if (!processed) {
printf("Run folder is empty, waiting for file creation\n");
int l = read( fd, buffer, sizeof(struct inotify_event) + NAME_MAX + 1 );
if ( l <= 0 ) {
ret = 1;
break;
}
}
} while(1);

inotify_rm_watch( fd, wd );
close(fd);

ret = 0;

exit:
g_thread_pool_free(pool, FALSE, TRUE);

g_mutex_clear(&prepare_lock);
Expand Down
6 changes: 3 additions & 3 deletions src/libdrakvuf/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
# DRAKVUF, and also available from #
# https://github.com/tklengyel/drakvuf/COPYING) #
# #
#*************************************************************************#
#*************************************************************************#

h_sources = libdrakvuf.h
c_sources = drakvuf.c win-exports.c vmi.c win-symbols.c win-handles.c win-processes.c
Expand All @@ -116,8 +116,8 @@ endif

# Note that -pg is incompatible with HARDENING
if DEBUG
AM_CFLAGS += -DDRAKVUF_DEBUG -Wall -Wextra -Wno-override-init -Wno-strict-aliasing -g -ggdb3
AM_CFLAGS += -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-unused-variable
AM_CFLAGS += -DDRAKVUF_DEBUG -Werror -Wall -Wextra -g -ggdb3
AM_CFLAGS += -Wno-missing-field-initializers
if !HARDENING
AM_CFLAGS += -pg
endif
Expand Down
10 changes: 7 additions & 3 deletions src/libdrakvuf/drakvuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
#include "private.h"
#include "win-symbols.h"
#include "win-exports.h"
#include "win-offsets.h"

#ifdef DRAKVUF_DEBUG
bool verbose = 0;
Expand All @@ -125,10 +126,11 @@ void drakvuf_close(drakvuf_t drakvuf) {
if (drakvuf->xen)
xen_free_interface(drakvuf->xen);

g_free(drakvuf->offsets);
g_mutex_clear(&drakvuf->vmi_lock);
free(drakvuf->dom_name);
free(drakvuf->rekall_profile);
free(drakvuf);
g_free(drakvuf->dom_name);
g_free(drakvuf->rekall_profile);
g_free(drakvuf);
}

bool drakvuf_init(drakvuf_t *drakvuf, const char *domain, const char *rekall_profile, bool _verbose) {
Expand All @@ -153,6 +155,8 @@ bool drakvuf_init(drakvuf_t *drakvuf, const char *domain, const char *rekall_pro
if ( (*drakvuf)->domID == test )
goto err;

(*drakvuf)->offsets = g_malloc0(sizeof(addr_t) * OFFSET_MAX);

if (!init_vmi(*drakvuf))
goto err;

Expand Down
10 changes: 6 additions & 4 deletions src/libdrakvuf/private.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,18 @@

extern bool verbose;

#define PRINT_DEBUG(args...) \
#define PRINT_DEBUG(...) \
do { \
if(verbose) fprintf (stderr, args); \
if(verbose) fprintf (stderr, __VA_ARGS__); \
} while (0)

#else
#define PRINT_DEBUG(args...) \
#define PRINT_DEBUG(...) \
do {} while(0)
#endif

#define UNUSED(x) (void)(x)

struct drakvuf {
char *dom_name;
domid_t domID;
Expand All @@ -152,7 +154,7 @@ struct drakvuf {
vmi_event_t mem_event;
vmi_event_t *step_event[16];

size_t offsets[OFFSET_MAX];
size_t *offsets;

// Processing trap removals in trap callbacks
// is problematic so we save all such requests
Expand Down
15 changes: 9 additions & 6 deletions src/libdrakvuf/vmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,17 @@
#include "libdrakvuf.h"
#include "win-symbols.h"
#include "vmi.h"
#include "win-offsets.h"
#include "win-offsets-map.h"

static uint8_t bp = 0xCC;
static uint8_t bp = TRAP;

/*
* This function gets called from the singlestep event
* after an int3 or a read event happens.
*/
event_response_t vmi_reset_trap(vmi_instance_t vmi, vmi_event_t *event) {
UNUSED(vmi);
drakvuf_t drakvuf = event->data;
PRINT_DEBUG("reset trap, switching %u->%u\n", event->slat_id, drakvuf->altp2m_idx);
event->slat_id = drakvuf->altp2m_idx;
Expand Down Expand Up @@ -163,7 +166,7 @@ void process_free_requests(drakvuf_t drakvuf) {

/* Here we are in singlestep mode already and this is a singlstep cb */
event_response_t post_mem_cb(vmi_instance_t vmi, vmi_event_t *event) {

UNUSED(vmi);
struct memcb_pass *pass = event->data;
drakvuf_t drakvuf = pass->drakvuf;
struct wrapper *s =
Expand Down Expand Up @@ -260,7 +263,7 @@ event_response_t post_mem_cb(vmi_instance_t vmi, vmi_event_t *event) {

/* This hits on the first access on a page, so not in singlestep yet */
event_response_t pre_mem_cb(vmi_instance_t vmi, vmi_event_t *event) {

UNUSED(vmi);
drakvuf_t drakvuf = event->data;
struct wrapper *s =
g_hash_table_lookup(drakvuf->memaccess_lookup_gfn, &event->mem_event.gfn);
Expand Down Expand Up @@ -304,7 +307,7 @@ event_response_t pre_mem_cb(vmi_instance_t vmi, vmi_event_t *event) {
/* We need to call breakpoint handlers registered for this physical address */
if (event->mem_event.out_access & VMI_MEMACCESS_X) {
struct wrapper *sbp = g_hash_table_lookup(drakvuf->breakpoint_lookup_pa, &s->memaccess.pa);

if (sbp) {
PRINT_DEBUG("Simulated INT3 event vCPU %u altp2m:%u CR3: 0x%"PRIx64" PA=0x%"PRIx64" RIP=0x%"PRIx64"\n",
event->vcpu_id, event->slat_id, event->regs.x86->cr3, s->memaccess.pa, event->regs.x86->rip);
Expand Down Expand Up @@ -367,9 +370,8 @@ event_response_t pre_mem_cb(vmi_instance_t vmi, vmi_event_t *event) {
}

event_response_t int3_cb(vmi_instance_t vmi, vmi_event_t *event) {

UNUSED(vmi);
reg_t cr3 = event->regs.x86->cr3;

drakvuf_t drakvuf = event->data;
addr_t pa = (event->interrupt_event.gfn << 12)
+ event->interrupt_event.offset + event->interrupt_event.insn_length - 1;
Expand Down Expand Up @@ -438,6 +440,7 @@ event_response_t int3_cb(vmi_instance_t vmi, vmi_event_t *event) {
}

event_response_t cr3_cb(vmi_instance_t vmi, vmi_event_t *event) {
UNUSED(vmi);
drakvuf_t drakvuf = (drakvuf_t)event->data;

#ifdef DRAKVUF_DEBUG
Expand Down
Loading

0 comments on commit cf9f0ee

Please sign in to comment.