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
73c7c7eb
Commit
73c7c7eb
authored
4 months ago
by
iliya.saroukha
Browse files
Options
Downloads
Patches
Plain Diff
wip: refacto and VMM work
parent
ac93955c
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
+23
-41
23 additions, 41 deletions
proto/hypervisor.c
with
23 additions
and
41 deletions
proto/hypervisor.c
+
23
−
41
View file @
73c7c7eb
...
...
@@ -12,27 +12,27 @@
#include
<linux/slab.h>
/*============== my includes ==============*/
#include
"asm/smp.h"
#include
"asm/special_insns.h"
#include
"asm/tlbflush.h"
#include
"debug/debug.h"
#include
"linux/threads.h"
#include
"msr/msr.h"
#include
"region/vxmon.h"
#include
"vcpu/vcpu.h"
#include
"vmm/vmm.h"
#include
"vmx/vmx.h"
#define NULL ((void *)0)
#define NB_VCPUS 1
/*asm ( assembler template*/
/* : output operands (optional)*/
/* : input operands (optional)*/
/* : clobbered registers list (optional)*/
/* );*/
static
struct
v
cpu_t
vcpus
[
1
]
;
static
struct
v
mm_t
ctx
;
static
int
my_init
(
void
)
{
DEBUG_FMT
(
"CPU id = %d
\n
"
,
smp_processor_id
());
DEBUG_FMT
(
"Nb available CPUs = %d
\n
"
,
num_online_cpus
());
pr_info
(
"Checking VMX support using CPUID
\n
"
);
if
(
!
vmx_support_cpuid
())
{
pr_err
(
"VMX isn't supported
\n
"
);
...
...
@@ -41,26 +41,15 @@ static int my_init(void) {
DEBUG_FMT
(
"IA32_VMX_BASIC_MSR = 0x%llx
\n
"
,
__rdmsr
(
IA32_VMX_BASIC
));
pr_info
(
"
Allocating VMXON region
\n
"
);
pr_info
(
"
Initializing VMM context
\n
"
);
struct
vmxon_t
*
vmxon_reg
=
alloc_vmxon
()
;
int
ret_err
;
if
(
!
vmxon_reg
)
{
pr_err
(
"VM
XON region alloc
ation failed
\n
"
);
return
-
ENOMEM
;
if
(
(
ret_err
=
init_vmm
(
&
ctx
,
1
))
!=
0
)
{
pr_err
(
"VM
M initializ
ation
has
failed
\n
"
);
return
ret_err
;
}
if
(
init_vcpu
(
&
vcpus
[
0
],
vmxon_reg
)
!=
0
)
{
pr_err
(
"VCPU initialization failed
\n
"
);
return
-
EFAULT
;
}
pr_info
(
"VA of the allocated region = 0x%px
\n
"
,
vmxon_reg
);
pr_info
(
"PA of the allocated region = 0x%lx
\n
"
,
__pa
(
vmxon_reg
));
pr_info
(
"Reading VMXON region for VMCS ID: 0x%x
\n
"
,
vmxon_reg
->
header
.
vmcs_rev_id
);
pr_info
(
"Patching CR0 and CR4 depending on the value of their respective "
"MSRs
\n
"
);
patch_control_registers
();
...
...
@@ -70,6 +59,7 @@ static int my_init(void) {
if
((
ret_cr4_vmx
=
cr4_enable_vmx
())
!=
0
)
{
pr_err
(
"CPU not available, VMXE bit in CR4 has already been set
\n
"
);
destroy_vmm
(
&
ctx
);
return
ret_cr4_vmx
;
}
...
...
@@ -77,28 +67,20 @@ static int my_init(void) {
if
(
!
ia32_feature_control_flags
())
{
pr_err
(
"The flags of the IA32_FEATURE_CONTROL MSR do not permit "
"virtualization
\n
"
);
destroy_vmm
(
&
ctx
);
return
-
EPERM
;
}
pr_info
(
"Executing VMXON with address = 0x%lx as its operand
\n
"
,
__pa
(
vmxon_reg
));
unsigned
char
vmxon_ret
=
0
;
for
(
unsigned
long
i
=
0
;
i
<
ctx
.
vcpu_count
;
i
++
)
{
if
((
ret_err
=
kvm_cpu_vmxon
(
__pa
(
&
ctx
.
vcpu_table
[
i
])))
!=
0
)
{
pr_err
(
"Failed to execute `vmxon` on vCPU[%lu]
\n
"
,
i
);
destroy_vmm
(
&
ctx
);
return
ret_err
;
}
/*if ((vmxon_ret = vmxon(vmxon_region.pa) != 0)) {*/
if
((
vmxon_ret
=
kvm_cpu_vmxon
(
__pa
(
vmxon_reg
))
!=
0
))
{
/*unsigned long vm_err = __rdmsr(0x4400);*/
/*pr_err("VM_ERR val = 0x%lx\n", vm_err);*/
cr4_clear_bits
(
13
);
kfree
(
vmxon_reg
);
/*__asm__ volatile("vmxoff");*/
pr_err
(
"`vmxon` failed with return code %d
\n
"
,
vmxon_ret
);
return
-
1
;
pr_info
(
"[+] vCPU[%lu] is in VMX operation
\n
"
,
i
);
}
pr_info
(
"`vmxon` was successfully executed!
\n
"
);
return
0
;
}
...
...
@@ -112,8 +94,8 @@ static void my_exit(void) {
return
;
}
pr_info
(
"Freeing
memory of the VMXON region
\n
"
);
kfree
(
vcpus
[
0
].
vmxon
);
pr_info
(
"
[*]
Freeing
VMM ctx
\n
"
);
destroy_vmm
(
&
ctx
);
pr_info
(
"vmbr.ko has exited
\n
"
);
}
...
...
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