-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a kprobe verification functionality
Add a new logic to the integrity verification routine verifying if the kprobes are enabled and correctly run. This commit makes kprobe verification functionality as an independent module invoked by integrity verification routine as well as during initialization to make sure kprobes are enabled and run as intended (otherwise, initialization fails).
- Loading branch information
Showing
7 changed files
with
188 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/modules/integrity_timer/verify_kprobes/p_verify_kprobes.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* pi3's Linux kernel Runtime Guard | ||
* | ||
* Component: | ||
* - Integrity verification kprobe verification submodule | ||
* | ||
* Notes: | ||
* - Verify if kprobes are enabled and correctly run | ||
* | ||
* Timeline: | ||
* - Created: 30.XI.2022 | ||
* | ||
* Author: | ||
* - Adam 'pi3' Zabrocki (http://pi3.com.pl) | ||
* | ||
*/ | ||
|
||
#include "../../../p_lkrg_main.h" | ||
|
||
static int p_lkrg_dummy_entry(struct kretprobe_instance *p_ri, struct pt_regs *p_regs); | ||
static int p_lkrg_dummy_ret(struct kretprobe_instance *ri, struct pt_regs *p_regs); | ||
|
||
static char p_lkrg_dummy_kretprobe_state = 0; | ||
|
||
static struct kretprobe p_lkrg_dummy_kretprobe = { | ||
.kp.symbol_name = "lkrg_dummy", | ||
.handler = p_lkrg_dummy_ret, | ||
.entry_handler = p_lkrg_dummy_entry, | ||
}; | ||
|
||
__attribute__((optimize(0))) | ||
noinline int lkrg_dummy(int arg) { | ||
|
||
p_debug_log(P_LOG_DEBUG, | ||
"[lkrg_dummy] Argument value: [%d]\n",arg); | ||
|
||
/* | ||
* TODO: | ||
* We can verify integrity of the internal kprobe structures here | ||
*/ | ||
|
||
return arg+1; | ||
} | ||
|
||
|
||
int lkrg_verify_kprobes(void) { | ||
|
||
int p_ret = 0, ret = -1; | ||
|
||
/* Verify kprobes now */ | ||
if ( (ret = lkrg_dummy(0)) != 3) { | ||
/* I'm hacked! ;( */ | ||
p_print_log(P_LOG_ALERT, "DETECT: Kprobes: Don't work as intended (disabled?)"); | ||
p_ret = -1; | ||
} | ||
p_print_log(P_LOG_WATCH, "lkrg_dummy returned %d vs. expected 3",ret); | ||
|
||
return p_ret; | ||
} | ||
|
||
static int p_lkrg_dummy_entry(struct kretprobe_instance *p_ri, struct pt_regs *p_regs) { | ||
|
||
p_regs_set_arg1(p_regs, p_regs_get_arg1(p_regs) + 1); | ||
return 0; | ||
} | ||
|
||
|
||
static int p_lkrg_dummy_ret(struct kretprobe_instance *ri, struct pt_regs *p_regs) { | ||
|
||
p_regs_set_ret(p_regs, p_regs_get_ret(p_regs) + 1); | ||
return 0; | ||
} | ||
|
||
GENERATE_INSTALL_FUNC(lkrg_dummy) |
26 changes: 26 additions & 0 deletions
26
src/modules/integrity_timer/verify_kprobes/p_verify_kprobes.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* pi3's Linux kernel Runtime Guard | ||
* | ||
* Component: | ||
* - Integrity verification kprobe verification submodule | ||
* | ||
* Notes: | ||
* - Verify if kprobes are enabled and correctly run | ||
* | ||
* Timeline: | ||
* - Created: 2.XII.2022 | ||
* | ||
* Author: | ||
* - Adam 'pi3' Zabrocki (http://pi3.com.pl) | ||
* | ||
*/ | ||
|
||
#ifndef P_LKRG_INTEGRITY_VERIFY_KPROBES_H | ||
#define P_LKRG_INTEGRITY_VERIFY_KPROBES_H | ||
|
||
int lkrg_verify_kprobes(void); | ||
|
||
int p_install_lkrg_dummy_hook(int p_isra); | ||
void p_uninstall_lkrg_dummy_hook(void); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters