-
Notifications
You must be signed in to change notification settings - Fork 91
LKRG Lockdown #439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
LKRG Lockdown #439
Changes from all commits
fc9a6d8
6e26c46
51144f5
ca33f69
d2e6608
7dfeede
b0ebcda
fed13e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,11 +18,20 @@ | |
| #ifndef P_LKRG_MAIN_H | ||
| #define P_LKRG_MAIN_H | ||
|
|
||
| #ifndef LKRG_LOCKED_DOWN | ||
| #define LKRG_LOCKED_DOWN 0 | ||
| #endif | ||
|
|
||
| #ifndef LKRG_LOCKDOWN_BY_KERNEL | ||
| #define LKRG_LOCKDOWN_BY_KERNEL 0 | ||
| #endif | ||
|
|
||
| #define LKRG_WITH_HIDE | ||
| #define P_BOOT_DISABLE_LKRG "nolkrg" | ||
|
|
||
| #include <linux/kernel.h> | ||
| #include <linux/init.h> | ||
| #include <linux/cred.h> | ||
| #include <linux/module.h> | ||
| #include <linux/moduleparam.h> | ||
| #include <linux/kallsyms.h> | ||
|
|
@@ -507,6 +516,39 @@ static inline int p_lkrg_counter_lock_val_read(p_lkrg_counter_lock *p_arg) { | |
| } | ||
| /* End */ | ||
|
|
||
| /* | ||
| * LKRG lockdown global | ||
| */ | ||
| extern int p_lkrg_lockdown __ro_after_init; | ||
|
|
||
| /* | ||
| * Kernel lockdown API | ||
| */ | ||
| #if LINUX_VERSION_CODE >= KERNEL_VERSION(5,4,0) | ||
|
|
||
| typedef bool (*kernel_is_locked_down_t)(const struct cred *, unsigned int); | ||
|
|
||
| /* Resolve kernel_is_locked_down(). Returns: 1 - kernel is locked down, 0 - no lockdown, -1 - error. */ | ||
| static inline int is_kernel_locked_down(void) | ||
| { | ||
| kernel_is_locked_down_t fn = NULL; | ||
|
|
||
| fn = (kernel_is_locked_down_t)kallsyms_lookup_name("kernel_is_locked_down"); | ||
| if (fn) { | ||
| return fn(current_cred(), 0) ? 1 : 0; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see how you're able to call |
||
| } | ||
|
|
||
| unsigned long addr = kallsyms_lookup_name("kernel_locked_down"); | ||
| if (addr) { | ||
| int val = *(int *)addr; | ||
| return val ? 1 : 0; | ||
| } | ||
|
|
||
| return -1; | ||
| } | ||
| #endif | ||
| /* End */ | ||
|
|
||
| /* | ||
| * LKRG modules | ||
| */ | ||
|
|
@@ -561,4 +603,12 @@ static inline int p_lkrg_counter_lock_val_read(p_lkrg_counter_lock *p_arg) { | |
| #error "LKRG requires CONFIG_TRIM_UNUSED_KSYMS to be disabled if it should be built as a kernel module" | ||
| #endif | ||
|
|
||
| #if LKRG_LOCKED_DOWN != 0 && LKRG_LOCKED_DOWN != 1 | ||
| #error "LKRG_LOCKED_DOWN must be 0 or 1" | ||
| #endif | ||
|
|
||
| #if LKRG_LOCKDOWN_BY_KERNEL != 0 && LKRG_LOCKDOWN_BY_KERNEL != 1 | ||
| #error "LKRG_LOCKDOWN_BY_KERNEL must be 0 or 1" | ||
| #endif | ||
|
|
||
| #endif | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
__ro_after_initis ineffective for modules, isn't it? We use our own usually-read-only page instead.