From: Kyle Hale Date: Thu, 23 Jun 2011 00:23:46 +0000 (-0500) Subject: added extension for syscall interception X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=6c6ad2a1b0a88307b9e129ca37522b444ddd7cab added extension for syscall interception --- diff --git a/palacios/include/interfaces/syscall_hijack.h b/palacios/include/interfaces/syscall_hijack.h new file mode 100644 index 0000000..389b8f0 --- /dev/null +++ b/palacios/include/interfaces/syscall_hijack.h @@ -0,0 +1,32 @@ +/* + * This file is part of the Palacios Virtual Machine Monitor developed + * by the V3VEE Project with funding from the United States National + * Science Foundation and the Department of Energy. + * + * The V3VEE Project is a joint project between Northwestern University + * and the University of New Mexico. You can find out more at + * http://www.v3vee.org + * + * Copyright (c) 2011, Kyle C. Hale + * Copyright (c) 2011, The V3VEE Project + * All rights reserved. + * + * Author: Kyle C. Hale + * + * This is free software. You are permitted to use, + * redistribute, and modify it as specified in the file "V3VEE_LICENSE". + */ + +#ifndef __SYSCALL_HIJACK_H__ +#define __SYSCALL_HIJACK_H__ + + +int v3_hook_syscall (struct guest_info * core, + uint_t syscall_nr, + int (*handler)(struct guest_info * core, uint_t syscall_nr, void * priv_data), + void * priv_data); + +int v3_hook_passthrough_syscall (struct guest_info * core, uint_t syscall_nr); + + +#endif diff --git a/palacios/src/extensions/ext_syscall_hijack.c b/palacios/src/extensions/ext_syscall_hijack.c index 31445df..59ea961 100644 --- a/palacios/src/extensions/ext_syscall_hijack.c +++ b/palacios/src/extensions/ext_syscall_hijack.c @@ -24,13 +24,14 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include -#ifndef CONFIG_DEBUG_SYSCALL_HIJACK +#include "syscall_ref.h" + +#ifndef V3_CONFIG_DEBUG_EXT_SYSCALL_HIJACK #undef PrintDebug #define PrintDebug(fmt, args...) #endif @@ -40,6 +41,56 @@ #define max(a, b) ( ((a) > (b)) ? (a) : (b) ) #endif +#define SYSCALL_INT_VECTOR 0x80 + + +struct v3_syscall_hook { + int (*handler)(struct guest_info * core, uint_t syscall_nr, void * priv_data); + void * priv_data; +}; + +static struct v3_syscall_hook * syscall_hooks[512]; + + +static int v3_syscall_handler (struct guest_info * core, uint8_t vector, void * priv_data) { + + uint_t syscall_nr = (uint_t) core->vm_regs.rax; + int err = 0; + + struct v3_syscall_hook * hook = syscall_hooks[syscall_nr]; + if (hook == NULL) { +#ifdef V3_CONFIG_EXT_SYSCALL_PASSTHROUGH + if (v3_hook_passthrough_syscall(core, syscall_nr) == -1) { + PrintDebug("Error hooking passthrough syscall\n"); + return -1; + } + hook = syscall_hooks[syscall_nr]; +#else + return v3_signal_swintr(core, vector); +#endif + } + + err = hook->handler(core, syscall_nr, hook->priv_data); + if (err == -1) { + PrintDebug("V3 Syscall Handler: Error in syscall hook\n"); + return -1; + } + + return 0; +} + + +static int init_syscall_hijack (struct v3_vm_info * vm, v3_cfg_tree_t * cfg, void ** priv_data) { + + return 0; +} + + +static int init_syscall_hijack_core (struct guest_info * core, void * priv_data) { + + v3_hook_swintr(core, SYSCALL_INT_VECTOR, v3_syscall_handler, NULL); + return 0; +} static void print_arg (struct guest_info * core, v3_reg_t reg, uint8_t argnum) { @@ -85,36 +136,25 @@ static void print_syscall (uint8_t is64, struct guest_info * core) { } -int v3_syscall_handler (struct guest_info * core, uint8_t vector, void * priv_data) { - - uint_t syscall_nr = (uint_t) core->vm_regs.rax; - int err = 0; - struct v3_syscall_hook * hook = core->sc_hook_map.syscall_hooks[syscall_nr]; - if (hook == NULL) { -#ifdef CONFIG_SYSCALL_PASSTHROUGH - if (v3_hook_passthrough_syscall(core, syscall_nr) == -1) { - PrintDebug("Error hooking passthrough syscall\n"); - return -1; - } - hook = core->sc_hook_map.syscall_hooks[syscall_nr]; -#else - return v3_signal_swintr(core, vector); -#endif - } - - err = hook->handler(core, syscall_nr, hook->priv_data); - if (err == -1) { - PrintDebug("V3 Syscall Handler: Error in syscall hook\n"); - return -1; - } - return 0; -} +static struct v3_extension_impl syscall_impl = { + .name = "syscall_intercept", + .init = init_syscall_hijack, + .deinit = NULL, + .core_init = init_syscall_hijack_core, + .core_deinit = NULL, + .on_entry = NULL, + .on_exit = NULL +}; + +register_extension(&syscall_impl); + + static inline struct v3_syscall_hook * get_syscall_hook (struct guest_info * core, uint_t syscall_nr) { - return core->sc_hook_map.syscall_hooks[syscall_nr]; + return syscall_hooks[syscall_nr]; } @@ -138,7 +178,7 @@ int v3_hook_syscall (struct guest_info * core, hook->handler = handler; hook->priv_data = priv_data; - core->sc_hook_map.syscall_hooks[syscall_nr] = hook; + syscall_hooks[syscall_nr] = hook; return 0; } @@ -166,7 +206,7 @@ int v3_hook_passthrough_syscall (struct guest_info * core, uint_t syscall_nr) { return 0; } - +/* int v3_sysexecve_handler (struct guest_info * core, uint_t syscall_nr, void * priv_data) { addr_t hva, key; struct exec_hook * hook; @@ -189,3 +229,4 @@ int v3_sysexecve_handler (struct guest_info * core, uint_t syscall_nr, void * pr return 0; } +*/