Commit graph

167 commits

Author SHA1 Message Date
Mariusz Zaborski
6a670f48a6
Add macro to genereate install func.
Signed-off-by: Mariusz Zaborski <oshogbo@vexillium.org>
2020-05-11 09:42:10 +02:00
Mariusz Zaborski
cf7ac2f321
Simplify install/uninstall functions.
This deduplicate a lot of code.

Signed-off-by: Mariusz Zaborski <oshogbo@vexillium.org>
2020-05-11 09:42:06 +02:00
Mariusz Zaborski
ea08cd0414
Simplify the initialization of the hooks.
Signed-off-by: Mariusz Zaborski <oshogbo@vexillium.org>
2020-05-11 09:42:00 +02:00
Adam_pi3
3923eec14e
Add SMAP bit verification logic (x86 arch). It is guarded in the same way as SMEP. Two new LKRG sysctl interface are introduced to control verification and enforcement logic:
1) Introduce 'smap_validate' to control if SMAP validation will be performed
       0 - disable SMAP validation
       1 - enable SMAP validation
   6) Introduce 'smap_enforce' to control how LKRG reacts when SMAP validation fails:
       0 - log & accept
       1 - log & restore
       2 - panic() - kill the kernel
2020-05-10 16:56:47 -04:00
Adam_pi3
517961fd43
Add "/sbin/bridge-stp" to whitelisted UMH 2020-05-09 20:02:46 -04:00
Adam_pi3
b3694bfc2a
When LKRG is configured to allow only whitelisted executables to be run by UMH, we might be in the situation of overwriting RO page. Add support for that 2020-05-09 19:56:58 -04:00
Adam_pi3
4ca6cacbba
Fix typo 2020-05-09 17:21:08 -04:00
Adam_pi3
4da623e51e
Change WARN info when 'ovl_create_or_link' can't be hooked. 2020-05-09 16:39:50 -04:00
Adam_pi3
404a3aef32
Mariusz Zaborski and Patrick Schleizer pointed out that LKRG generates kernel panic when SMEP is not supported on x86. Such problem occure after the 2aef433. This commit fixes that issue. 2020-05-09 15:43:43 -04:00
Adam_pi3
fe54765efb
Refactor LKRG process tracking DB. Instead of relying on 1 global spinlock, now we have multiple RW-locks. This commit introduces 512 buckets of RB-trees + RW-locks. This commit significantly increases performance. 2020-05-09 14:30:11 -04:00
Adam_pi3
6bef8f5ee2
Revert 186608db69. Some SL*B allocators do not allow to delete/shutdown cache under IRQs being disabled. In such case we can hit BUG_ON() 2020-05-03 20:12:10 -04:00
Adam_pi3
2aef4330d9
Change SMEP enforcement/validation logic 2020-05-03 14:47:44 -04:00
Adam_pi3
c8e18884a6
Introduce LKRG's tasks integrity database locking API 2020-05-01 21:59:28 -04:00
Adam_pi3
2daf922b6f
[1] Add support for pCFI stackwalk when CONFIG_UNWINDER_ORC is enabled
[2] Whitelist true/false binaries
[3] Modify the logic when stack-page is updated
[4] Add __scm_send hook to verify creds on SCM_CREDENTIALS
2020-04-30 11:25:53 -04:00
Adam_pi3
5278bebd45
Add _trylock() in the ttwu_do_wakeup and __queue_work hook 2020-04-28 14:20:26 -04:00
Adam_pi3
186608db69
Update p_delete_rb_ed_pids() to use IRQ-save locks 2020-04-27 21:10:11 -04:00
Adam_pi3
f2ab708a67
Change the default log-level from P_LKRG_CRIT to P_LKRG_INFO when LKRG detects lost/extra module which is related to the current module activity events (system is stable and not hacked). Maybe we should use P_LKRG_WARN? for now it will be P_LKRG_INFO. 2020-04-25 21:26:52 -04:00
Adam_pi3
2febcf467d
This is a huge change. We completely rewrote communication channel and added a lot of new configuration options. Summary:
1) Introduce 'kint_validate' to control kernel/system integrity logic:
    0 - disabled
    1 - validation is performed only when manually triggered
    3 - validation is performed periodically by timer interrupt and on random events
 2) Introduce 'kint_enforce' to control how LKRG reacts when kernel/system integrity fails:
    0 - log & accept corruption
    1 - log only (for SELinux and CR0.WP violation log & restore original values)
    2 - panic() - kill the kernel

 3) Introduce 'pint_validate' to control tasks validation logic:
    0 - disabled
    1 - validate only currently running tasks
    2 - validate only currently running tasks + task which changes state to RUNNING
    3 - validate all tasks in the system (paranoid mode)
 4) Introduce 'pint_enforce' to control how LKRG reacts when task validation fails:
    0 - log & accept corruption
    1 - kill corrupted task
    2 - panic() - kill the kernel

 5) Introduce 'smep_validate' to control if SMEP validation will be performed
    0 - disable SMEP validation
    1 - enable SMEP validation
 6) Introduce 'smep_enforce' to control how LKRG reacts when SMEP validation fails:
    0 - log & accept
    1 - log & restore
    2 - panic() - kill the kernel

 7) Introduce 'umh_validate' to control if UMH validation will be performed
    0 - disable UMH validation
    1 - allow only whitelited binaries to execute via UMH
    2 - completely block UMH
 8) Introduce 'smep_enforce' to control how LKRG reacts when UMH validation fails:
    0 - log only
    1 - prevent execution
    2 - panic() - kill the kernel

 9) Introduce 'pcfi_validate' to control if pCFI validation will be performed
    0 - disabled
    1 - no stackwalk (weak pCFI)
    2 - fully enabled
10) Introduce 'pcfi_enforce' to control how LKRG reacts when pCFI validation fails:
    0 - log only
    1 - kill corrupted task
    2 - panic() - kill the kernel

11) Rename 'timestamp' to 'interval'
12) Rename 'force_run' to 'trigger'
13) Rename 'clean_message' to 'heartbeat'
14) Rename 'msr_enforce' to 'msr_validate'

15) Option 'hide' stays the same
16) Option 'log_level' stays the same
17) Option 'block_modules' stays the same
2020-04-25 13:41:52 -04:00
Adam_pi3
0f7c6350a8
Add support for kernels 5.6+ 2020-04-17 00:50:59 +00:00
Adam_pi3
82f76f8183
[1] Change the logic how ED verifies processes:
a) By default, only verify currently executed process
    b) Introduce a paranoid mode of process verification.
       This mode verifies all tasks in the system
       (like LKRG's old logic). This mode is executed from the
       CI verification routine.
[2] Add new hooks to verify process credentials:
    a) cover that cases where various capabilities are checked
    b) before any task changes the state to TASK_RUNNING
[3] Create multiple RB-trees for tracking ED process. Until now
    we had only 1 root RB-tree. new logic change can improve
    performance when system is overloaded.
[4] Introduce a new ED API which enforces process to crash itself
    when SIGKILL can't be delivered
[5] Enforce CPU metadata verification (like SMEP) in more places
[6] Fix some minor issues
2020-04-15 15:35:49 -04:00
Adam_pi3
d379e93c29
Move copy of THIS_MODULE to RO page. Fix the problem of 'block_modules' as being a parameter. 2020-03-12 00:21:21 -04:00
Adam_pi3
f58ac6fce9
Replace 'hide_module' variable with 'hide_lkrg' to make rkhunter happy. Thanks goes to Lionel Debroux 2020-03-10 01:35:45 -04:00
Adam_pi3
41da7e95bd
Update INSTALL file 2020-03-01 05:39:30 +00:00
Adam_pi3
cd348148ae
Fix variable name 2020-02-25 01:15:18 +00:00
Adam_pi3
6edf89fd60
Cleanup some log-levels 2020-02-25 01:11:48 +00:00
Adam_pi3
0f279e7e3d
Some cleanups 2020-02-25 00:22:23 +00:00
Adam_pi3
0cf451be9b
Add support for DKMS. Take into account variable KERNELRELEASE 2020-02-15 22:41:07 +00:00
Adam_pi3
3b9644ed91
Add support for kernels 5.5+ 2020-02-03 22:28:17 +00:00
Adam_pi3
3a16c657c3
[ED] Fix compilation problem on older kernels. PID namespace pointer has different name on older kernels (< 3.11) 2020-02-03 20:20:16 +00:00
Adam_pi3
63b10994c0
[1] Add a new logic in Exploit-Detection feature for detection namespaces escape. LKRG now validates various namespace configurations per thread (task_struct)
[2] Update lkrg.service script
2020-02-01 00:39:37 +00:00
Adam_pi3
2c1177b585
[1] Rename 'p_init_log_level' module param name to 'log_level'
[2] Introduce 5 new module parameters:
    -> clean_message
    -> block_modules
    -> enforce_umh
    -> enforce_msr
    -> enforce_pcfi
2020-01-25 23:13:07 +00:00
Adam_pi3
347d13e9b8
[ED] Replace 'umh_lock' sysctl interface with 'enforce_umh'. New interface has 3 possible states:
lkrg.enforce_umh:
            0 - Disable protection
            1 - Whitelist UMH paths (default)
            2 - Completely block UMH
2020-01-25 22:07:34 +00:00
Adam_pi3
ef9ac30776
[1] Small fix of systemd installation script
[2] Small fix of IDT max size value
2020-01-24 01:22:53 +00:00
Adam_pi3
c8fc287599
[ED] Introduce new sysctl interface - lkrg.enforce_pcfi (fully enabled by default):
lkrg.enforce_pcfi:
        0 - completely disable pcfi
        1 - enable weak pcfi (no stackwalk)
        2 - enable full pcfi
2020-01-23 05:37:46 +00:00
Adam_pi3
22941e818e
[CI] fix bug in a new code adding support for batch mode for *_JUMP_LABEL on kernels 5.3+ on x86 platform. 2020-01-20 02:29:04 +00:00
Adam_pi3
403f2fa92c
Fix compilation on non-x86 platforms for kernel 5.3+ 2020-01-16 06:05:15 +00:00
Adam_pi3
3262383a68 [1] Remove P_LKRG_CI_X86_NO_MSR compilation option
[2] Introduce new sysctl interface - lkrg.enforce_msr (enabled by default):

	lkrg.enforce_msr:
	  0 - disable MSRs verification during CI
	  1 - enable MSRs verification during CI
2019-12-31 11:28:08 -05:00
Adam_pi3
9f502087ac Split some of the printed information into various log-level 2019-12-20 19:26:15 -05:00
Adam_pi3
aea93dc9cc Introduce a P_CTRL macro for referencing control structure in RO-page 2019-12-20 18:52:06 -05:00
Adam_pi3
5eb075e322 Change debug output to provide more useful information about some kernel addresses 2019-12-20 18:08:59 -05:00
Adam_pi3
a218d81039 Fix fallback path in the initialization routine 2019-12-20 18:05:16 -05:00
Adam_pi3
d5032b4376 This is a pretty big change in LKRG:
[1] Introducing a RO-page which keeps the most-critical internal structures
  [2] Moving internal control structure (configurable via sysctl interface) to the RO-page
  [3] Introducing a new structure which keeps all dynamically resolved pointers
  [4] Moving a new structure with dynamic pointers to the RO-page
  [5] Refactoring the entire code to be compatible with the new design
  [6] Adding appropriate messages when a new sysctl option is put in place
  [7] A few more minor changes
2019-12-20 15:44:21 -05:00
Adam_pi3
161a3c11e2 [CI] <x86/AMD64> Introduce an option to compile LKRG without verifying MSRs on each (v)CPU core. It might be useful for the host machines which manages VMs (root-partition). This compilation option is DISABLED by default. 2019-12-01 20:59:25 -05:00
Adam_pi3
bfcc8de9b5 [ED] Introduce an option to compile LKRG without full stack-walk valdation during pCFI. It might be useful for not-so-smart drivers which might dynamically allocate RWX page and execute code from there. This compilation option is DISABLED by default. 2019-12-01 19:52:12 -05:00
Adam_pi3
bbd126efa7 [CI] Disable MSR_IA32_CR_PAT validation for now. It can be reenabled in the future if needed. On x86/AMD64 kernel might reconfigure MTRR after CPU is being put online which might be problematic for S3/S4 state. 2019-11-30 21:20:57 -05:00
Adam_pi3
196266c5ed [ED] Do not print stacktrace if CONFIG_STACKTRACE is not enabled 2019-11-27 01:38:53 -05:00
Adam_pi3
17ae51c73b [CI] Some kernels are not compiled with CONFIG_USB=y. E.g. Debian's kernel is setting CONFIG_USB=m and usbcode can (or not) be loaded dynamically. In such a case LKRG has no guarantee that USB notifiers are available in the system. They might be after usbcore being loaded but it's not enough. This commit takes this into account and in case 'usbcore' is not natively compiled in the system, usb notifiers are not used 2019-11-11 01:55:29 -05:00
Adam_pi3
9acaaa2e0c Whitelist systemd-coredump 2019-11-03 14:13:46 -05:00
Adam_pi3
29867f6ecd [1] Add support for JUMP_LABEL batch mode (support for kernels 5.3+)
[2] Some minor fixes
2019-11-02 04:48:55 +00:00
Adam_pi3
5b86565089 Update script permisions 2019-10-31 18:38:12 +00:00