Skip to content

Commit

Permalink
Revert "Add unique trap id to avoid relying on pointers as keys (tkle…
Browse files Browse the repository at this point in the history
…ngyel#1197)" (tklengyel#1205)

This reverts commit c0a3658.
  • Loading branch information
tklengyel authored Apr 15, 2021
1 parent 789b86f commit fc6ecab
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 62 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ AC_ARG_ENABLE([plugin_libhooktest],
[AS_HELP_STRING([--enable-plugin-libhooktest],
[Enable libhooktest plugin for testing @<:@no@:>@])],
[plugin_libhooktest="$enableval"],
[plugin_libhooktest="no"])
[plugin_libhooktest=""])
AM_CONDITIONAL([PLUGIN_LIBHOOKTEST], [test x$plugin_libhooktest = xyes])
if test x$plugin_libhooktest = xyes; then
AC_DEFINE_UNQUOTED(ENABLE_PLUGIN_LIBHOOKTEST, 1, "")
Expand Down
10 changes: 5 additions & 5 deletions src/libdrakvuf/drakvuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,14 +424,12 @@ bool drakvuf_add_trap(drakvuf_t drakvuf, drakvuf_trap_t* trap)
if (!trap || !trap->cb)
return 0;

if (!trap->id)
trap->id = ++drakvuf->trap_counter;
if (!trap->ah_cb)
trap->ah_cb = drakvuf_unhook_trap;

if (g_hash_table_lookup(drakvuf->remove_traps, GSIZE_TO_POINTER(trap->id)))
if (g_hash_table_lookup(drakvuf->remove_traps, &trap))
{
g_hash_table_remove(drakvuf->remove_traps, GSIZE_TO_POINTER(trap->id));
g_hash_table_remove(drakvuf->remove_traps, &trap);
return 1;
}

Expand Down Expand Up @@ -479,7 +477,9 @@ void drakvuf_remove_trap(drakvuf_t drakvuf, drakvuf_trap_t* trap,
free_wrapper = (struct free_trap_wrapper*)g_slice_alloc0(sizeof(struct free_trap_wrapper));
free_wrapper->free_routine = free_routine;
free_wrapper->trap = trap;
g_hash_table_insert(drakvuf->remove_traps, GSIZE_TO_POINTER(trap->id), free_wrapper);
g_hash_table_insert(drakvuf->remove_traps,
g_memdup(&trap, sizeof(void*)),
free_wrapper);
}

free_wrapper->counter++;
Expand Down
1 change: 0 additions & 1 deletion src/libdrakvuf/libdrakvuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ typedef struct drakvuf_trap_info
struct drakvuf_trap
{
trap_type_t type;
uint64_t id;
event_response_t (*cb)(drakvuf_t, drakvuf_trap_info_t*);
void* data;

Expand Down
1 change: 0 additions & 1 deletion src/libdrakvuf/private.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ struct drakvuf
fd_info_t fd_info_lookup; // auto-generated for fast drakvuf_loop lookups
int poll_rc;

uint64_t trap_counter; // incremental unique trap ID
uint64_t event_counter; // incremental unique trap event ID

ipt_state_t ipt_state[MAX_DRAKVUF_VCPU];
Expand Down
99 changes: 54 additions & 45 deletions src/libdrakvuf/vmi.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/libhook/hooks/return.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ auto ReturnHook::create(drakvuf_t drakvuf, drakvuf_trap_info* info, cb_wrapper_t

// not using std::make_unique because ctor is private
auto hook = std::unique_ptr<ReturnHook>(new ReturnHook(drakvuf, cb));
hook->trap_ = new drakvuf_trap_t();
hook->trap_ = new drakvuf_trap_t;

auto ret_addr = drakvuf_get_function_return_address(drakvuf, info);
if (!ret_addr)
Expand Down
2 changes: 1 addition & 1 deletion src/libhook/hooks/syscall.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ auto SyscallHook::create(drakvuf_t drakvuf, const std::string& syscall_name, cb_

// not using std::make_unique because ctor is private
auto hook = std::unique_ptr<SyscallHook>(new SyscallHook(drakvuf, syscall_name, cb));
hook->trap_ = new drakvuf_trap_t();
hook->trap_ = new drakvuf_trap_t;

if (!drakvuf_get_kernel_symbol_rva(hook->drakvuf_, hook->syscall_name_.c_str(), &hook->trap_->breakpoint.rva))
{
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/cpuidmon/cpuidmon.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class cpuidmon: public plugin
{
public:
output_format_t format;
drakvuf_trap_t cpuid{};
drakvuf_trap_t cpuid;
drakvuf_t drakvuf;
bool stealth;

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/debugmon/debugmon.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class debugmon: public plugin
{
public:
output_format_t format;
drakvuf_trap_t debug{};
drakvuf_trap_t debug;
drakvuf_t drakvuf;

debugmon(drakvuf_t drakvuf, output_format_t output);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/exploitmon/exploitmon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static bool hook_page(
event_response_t (*callback)(drakvuf_t, drakvuf_trap_info_t*),
addr_t data = 0)
{
auto trap = new drakvuf_trap_t();
auto trap = new drakvuf_trap_t;
if (!trap)
return false;

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/plugins_ex.h
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ drakvuf_trap_t* pluginex::register_trap(drakvuf_trap_info_t* info,
int64_t ttl,
ah_cb_t ah_cb)
{
auto trap = new drakvuf_trap_t();
auto trap = new drakvuf_trap_t;

if constexpr (std::is_same_v<Params, void>)
{
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/poolmon/poolmon.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class poolmon: public plugin
public:
output_format_t format;
GTree* pooltag_tree;
drakvuf_trap_t trap{};
drakvuf_trap_t trap;

poolmon(drakvuf_t drakvuf, output_format_t output);
~poolmon();
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/ssdtmon/ssdtmon.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ class ssdtmon: public plugin
{
public:
output_format_t format;
drakvuf_trap_t ssdtwrite{};
drakvuf_trap_t ssdtwrite2{};
drakvuf_trap_t ssdtwrite;
drakvuf_trap_t ssdtwrite2;

addr_t kiservicetable;
uint32_t kiservicelimit;
Expand Down

0 comments on commit fc6ecab

Please sign in to comment.