Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hypervisor rootkit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
flg_bachelors
TS
2024
hypervisor rootkit
Commits
f87b2ef9
Commit
f87b2ef9
authored
6 months ago
by
iliya.saroukha
Browse files
Options
Downloads
Patches
Plain Diff
wip: reading the values of cr0 and cr4 and their respective VMX MSRs
parent
f486b6b1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
proto/hypervisor.c
+39
-8
39 additions, 8 deletions
proto/hypervisor.c
with
39 additions
and
8 deletions
proto/hypervisor.c
+
39
−
8
View file @
f87b2ef9
#include
"asm/cpuid.h"
#include
"asm/msr.h"
#include
"asm/msr.h"
#include
"asm/paravirt.h"
#include
"linux/kern_levels.h"
#include
"linux/kern_levels.h"
#include
"linux/printk.h"
#include
"linux/printk.h"
#include
<linux/init.h>
/* Needed for the macros */
#include
<linux/init.h>
/* Needed for the macros */
#include
<linux/module.h>
/* Needed by all modules */
#include
<linux/module.h>
/* Needed by all modules */
#define IA32_FEATURE_CONTROL_LOCK_BIT (1 << 0)
#define IA32_FEATURE_CONTROL_LOCK_BIT (1
UL
<< 0)
#define IA32_FEATURE_CONTROL_VMXON_IN_SMX (1 << 1)
#define IA32_FEATURE_CONTROL_VMXON_IN_SMX (1
UL
<< 1)
#define IA32_FEATURE_CONTROL_VMXON_OUTSIDE_SMX (1 << 2)
#define IA32_FEATURE_CONTROL_VMXON_OUTSIDE_SMX (1
UL
<< 2)
#define IA32_FEATURE_CONTROL_MSR (0x3a)
#define IA32_FEATURE_CONTROL_MSR (0x3a)
// Appendix 8 p. 4'592 of Intel SDM
#define IA32_VMX_CR0_FIXED0 (0x486)
#define IA32_VMX_CR0_FIXED1 (0x487)
#define IA32_VMX_CR4_FIXED0 (0x488)
#define IA32_VMX_CR4_FIXED1 (0x489)
#define CR0_PE (1UL << 0)
#define CR0_NE (1UL << 5)
#define CR0_PG (1UL << 31)
/*asm ( assembler template*/
/*asm ( assembler template*/
/* : output operands (optional)*/
/* : output operands (optional)*/
/* : input operands (optional)*/
/* : input operands (optional)*/
...
@@ -24,11 +36,10 @@ static void cr4_enable_vmx(void) {
...
@@ -24,11 +36,10 @@ static void cr4_enable_vmx(void) {
}
}
static
bool
vmx_supported
(
void
)
{
static
bool
vmx_supported
(
void
)
{
int
ecx
;
unsigned
int
ecx
=
cpuid_ecx
(
1
);
/*__asm__ volatile("mov $1, %rax");*/
__asm__
volatile
(
"mov $1, %rax"
);
/*__asm__ volatile("cpuid");*/
__asm__
volatile
(
"cpuid"
);
/*__asm__ volatile("mov %%ecx , %0\n\t" : "=r"(ecx));*/
__asm__
volatile
(
"mov %%ecx , %0
\n\t
"
:
"=r"
(
ecx
));
return
(
ecx
>>
5
)
&
1
;
return
(
ecx
>>
5
)
&
1
;
}
}
...
@@ -52,6 +63,24 @@ static bool ia32_feature_control_flags(void) {
...
@@ -52,6 +63,24 @@ static bool ia32_feature_control_flags(void) {
return
true
;
return
true
;
}
}
static
void
reading_cr_msr
(
void
)
{
unsigned
long
long
cr0
,
cr4
;
__asm__
volatile
(
"mov %%cr0, %0"
:
"=r"
(
cr0
));
__asm__
volatile
(
"mov %%cr4, %0"
:
"=r"
(
cr4
));
pr_debug
(
"CR0 = 0x%llx
\n
"
,
cr0
);
pr_debug
(
"CR4 = 0x%llx
\n\n
"
,
cr4
);
/*unsigned long cr0_fixed0 = __rdmsr(IA32_VMX_CR0_FIXED0);*/
/*unsigned long cr0_fixed1 = __rdmsr(IA32_VMX_CR0_FIXED1);*/
pr_debug
(
KERN_INFO
"CR0_FIXED0 = 0x%llx
\n
"
,
__rdmsr
(
IA32_VMX_CR0_FIXED0
));
pr_debug
(
KERN_INFO
"CR0_FIXED1 = 0x%llx
\n\n
"
,
__rdmsr
(
IA32_VMX_CR0_FIXED1
));
pr_debug
(
KERN_INFO
"CR4_FIXED0 = 0x%llx
\n
"
,
__rdmsr
(
IA32_VMX_CR4_FIXED0
));
pr_debug
(
KERN_INFO
"CR4_FIXED1 = 0x%llx
\n
"
,
__rdmsr
(
IA32_VMX_CR4_FIXED1
));
}
static
int
my_init
(
void
)
{
static
int
my_init
(
void
)
{
if
(
!
vmx_supported
())
{
if
(
!
vmx_supported
())
{
printk
(
KERN_INFO
"VMX isn't supported
\n
"
);
printk
(
KERN_INFO
"VMX isn't supported
\n
"
);
...
@@ -73,6 +102,8 @@ static int my_init(void) {
...
@@ -73,6 +102,8 @@ static int my_init(void) {
printk
(
KERN_INFO
"IA32_FEATURE_CONTROL MSR flags allow virtualization
\n
"
);
printk
(
KERN_INFO
"IA32_FEATURE_CONTROL MSR flags allow virtualization
\n
"
);
reading_cr_msr
();
return
0
;
return
0
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment