diff mbox series

[08/43] windbg: hook to wrmsr operation

Message ID 150642389121.3900.12320775067244184010.stgit@Misha-PC.lan02.inno
State New
Headers show
Series Windbg supporting | expand

Commit Message

Mikhail Abakumov Sept. 26, 2017, 11:04 a.m. UTC
Inserted hook to wrmsr operation. Windows Kernel put address on KPCR struct to fs/gs (x32/x64) register. Needs catch this moment and allow windbg server handle packets.

Signed-off-by: Mihail Abakumov <mikhail.abakumov@ispras.ru>
Signed-off-by: Pavel Dovgalyuk <dovgaluk@ispras.ru>
Signed-off-by: Dmitriy Koltunov <koltunov@ispras.ru>
---
 include/exec/windbgstub-utils.h |    3 +++
 include/exec/windbgstub.h       |    1 +
 target/i386/misc_helper.c       |    3 +++
 windbgstub-utils.c              |    8 ++++++++
 windbgstub.c                    |    8 ++++++++
 5 files changed, 23 insertions(+)

Comments

Ladi Prosek Oct. 3, 2017, 11:57 a.m. UTC | #1
On Tue, Sep 26, 2017 at 1:04 PM, Mihail Abakumov
<mikhail.abakumov@ispras.ru> wrote:
> Inserted hook to wrmsr operation. Windows Kernel put address on KPCR struct to fs/gs (x32/x64) register. Needs catch this moment and allow windbg server handle packets.
>
> Signed-off-by: Mihail Abakumov <mikhail.abakumov@ispras.ru>
> Signed-off-by: Pavel Dovgalyuk <dovgaluk@ispras.ru>
> Signed-off-by: Dmitriy Koltunov <koltunov@ispras.ru>
> ---
>  include/exec/windbgstub-utils.h |    3 +++
>  include/exec/windbgstub.h       |    1 +
>  target/i386/misc_helper.c       |    3 +++
>  windbgstub-utils.c              |    8 ++++++++
>  windbgstub.c                    |    8 ++++++++
>  5 files changed, 23 insertions(+)
>
> diff --git a/include/exec/windbgstub-utils.h b/include/exec/windbgstub-utils.h
> index 65f336e4bf..90fb766839 100755
> --- a/include/exec/windbgstub-utils.h
> +++ b/include/exec/windbgstub-utils.h
> @@ -62,4 +62,7 @@
>      _t;                                                       \
>  })
>
> +bool windbg_on_load(void);
> +void windbg_on_exit(void);
> +
>  #endif
> diff --git a/include/exec/windbgstub.h b/include/exec/windbgstub.h
> index 703fc26b8f..2dbf1b1f13 100755
> --- a/include/exec/windbgstub.h
> +++ b/include/exec/windbgstub.h
> @@ -15,6 +15,7 @@
>  #define WINDBG "windbg"
>  #define WINDBG_DEBUG_ON false
>
> +void windbg_try_load(void);
>  int windbg_server_start(const char *device);
>
>  #endif
> diff --git a/target/i386/misc_helper.c b/target/i386/misc_helper.c
> index 628f64aad5..ec1fcd2899 100644
> --- a/target/i386/misc_helper.c
> +++ b/target/i386/misc_helper.c
> @@ -24,6 +24,7 @@
>  #include "exec/exec-all.h"
>  #include "exec/cpu_ldst.h"
>  #include "exec/address-spaces.h"
> +#include "exec/windbgstub.h"
>
>  void helper_outb(CPUX86State *env, uint32_t port, uint32_t data)
>  {
> @@ -385,6 +386,8 @@ void helper_wrmsr(CPUX86State *env)
>          /* XXX: exception? */
>          break;
>      }
> +
> +    windbg_try_load();

Most people use QEMU with KVM and won't ever hit this code. Does your
work rely on TCG only for FS/GS write interception?

If KVM is out of scope for you, you should at least make sure that
users won't expect -windbg to work with it. So either fall back to TCG
if -windbg is passed or issue a warning.

>  }
>
>  void helper_rdmsr(CPUX86State *env)
> diff --git a/windbgstub-utils.c b/windbgstub-utils.c
> index dc5e505c63..b5fb6db3f2 100755
> --- a/windbgstub-utils.c
> +++ b/windbgstub-utils.c
> @@ -10,3 +10,11 @@
>   */
>
>  #include "exec/windbgstub-utils.h"
> +
> +bool windbg_on_load(void)
> +{
> +    return false;
> +}
> +
> +void windbg_on_exit(void)
> +{}
> diff --git a/windbgstub.c b/windbgstub.c
> index 378d1b911f..99c3ef9b14 100755
> --- a/windbgstub.c
> +++ b/windbgstub.c
> @@ -39,8 +39,16 @@ static void windbg_chr_receive(void *opaque, const uint8_t *buf, int size)
>      }
>  }
>
> +void windbg_try_load(void)
> +{
> +    if (windbg_state && !windbg_state->is_loaded) {
> +        windbg_state->is_loaded = windbg_on_load();
> +    }
> +}
> +
>  static void windbg_exit(void)
>  {
> +    windbg_on_exit();
>      g_free(windbg_state);
>  }
>
>
Mikhail Abakumov Oct. 24, 2017, 11:50 a.m. UTC | #2
Ladi Prosek писал 2017-10-03 14:57:
> On Tue, Sep 26, 2017 at 1:04 PM, Mihail Abakumov
> <mikhail.abakumov@ispras.ru> wrote:
> 
> Most people use QEMU with KVM and won't ever hit this code. Does your
> work rely on TCG only for FS/GS write interception?
> 
> If KVM is out of scope for you, you should at least make sure that
> users won't expect -windbg to work with it. So either fall back to TCG
> if -windbg is passed or issue a warning.
> 

KVM is unsupported, at the moment. Therefore, I added additional 
checking on it in windbg_server_start.

Thanks,
Mihail Abakumov
diff mbox series

Patch

diff --git a/include/exec/windbgstub-utils.h b/include/exec/windbgstub-utils.h
index 65f336e4bf..90fb766839 100755
--- a/include/exec/windbgstub-utils.h
+++ b/include/exec/windbgstub-utils.h
@@ -62,4 +62,7 @@ 
     _t;                                                       \
 })
 
+bool windbg_on_load(void);
+void windbg_on_exit(void);
+
 #endif
diff --git a/include/exec/windbgstub.h b/include/exec/windbgstub.h
index 703fc26b8f..2dbf1b1f13 100755
--- a/include/exec/windbgstub.h
+++ b/include/exec/windbgstub.h
@@ -15,6 +15,7 @@ 
 #define WINDBG "windbg"
 #define WINDBG_DEBUG_ON false
 
+void windbg_try_load(void);
 int windbg_server_start(const char *device);
 
 #endif
diff --git a/target/i386/misc_helper.c b/target/i386/misc_helper.c
index 628f64aad5..ec1fcd2899 100644
--- a/target/i386/misc_helper.c
+++ b/target/i386/misc_helper.c
@@ -24,6 +24,7 @@ 
 #include "exec/exec-all.h"
 #include "exec/cpu_ldst.h"
 #include "exec/address-spaces.h"
+#include "exec/windbgstub.h"
 
 void helper_outb(CPUX86State *env, uint32_t port, uint32_t data)
 {
@@ -385,6 +386,8 @@  void helper_wrmsr(CPUX86State *env)
         /* XXX: exception? */
         break;
     }
+
+    windbg_try_load();
 }
 
 void helper_rdmsr(CPUX86State *env)
diff --git a/windbgstub-utils.c b/windbgstub-utils.c
index dc5e505c63..b5fb6db3f2 100755
--- a/windbgstub-utils.c
+++ b/windbgstub-utils.c
@@ -10,3 +10,11 @@ 
  */
 
 #include "exec/windbgstub-utils.h"
+
+bool windbg_on_load(void)
+{
+    return false;
+}
+
+void windbg_on_exit(void)
+{}
diff --git a/windbgstub.c b/windbgstub.c
index 378d1b911f..99c3ef9b14 100755
--- a/windbgstub.c
+++ b/windbgstub.c
@@ -39,8 +39,16 @@  static void windbg_chr_receive(void *opaque, const uint8_t *buf, int size)
     }
 }
 
+void windbg_try_load(void)
+{
+    if (windbg_state && !windbg_state->is_loaded) {
+        windbg_state->is_loaded = windbg_on_load();
+    }
+}
+
 static void windbg_exit(void)
 {
+    windbg_on_exit();
     g_free(windbg_state);
 }