Commit graph

50 commits

Author SHA1 Message Date
Adam_pi3
26f36ed495 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).
2022-12-04 21:31:22 +01:00
Adam_pi3
6f3627e32c Rework the logic supporting OverlayFS/docker
The original logic was hooking 'ovl_create_or_link' function but it could be
inlined. This commit changes it by hooking 'ovl_dentry_is_whiteout' when
possible.

Fixes #215
2022-07-29 13:50:45 +02:00
Solar Designer
49a3117542 Rename the module from p_lkrg to lkrg 2022-07-20 17:57:37 +02:00
Mariusz Zaborski
0cf357d9c0 make: introduce an option to build LKRG with debug 2022-04-15 14:21:34 +02:00
Adam_pi3
cccc01dd05
Add support for x86/static_call used by TRACEPOINTs since kernel 5.10+
Since kernel 5.10 tracepoints don't use JUMP_LABEL engine for .text kernel
modification.
Linux kernel introduced 'static_call' as a replacement for global function
pointers. It uses code patching to allow direct calls to be used instead of
indirect calls. Related Linux kernel commits:

e6d6c071f2
1e7e478838 (diff-d7873f00dcd8c46df3e1e57b3225ff91036c83d5d7339d410b468418fc9a32a4)

Currently, only x86(-64) architecture has implementation for static calls.
This commit should address #69
2021-04-23 01:36:29 -04:00
Mariusz Zaborski
59bed0a813 SELinux: Refactor state monitoring
Introduce a new API for SELinux state monitoring.
Move the API to a separate file.
2021-03-19 15:17:11 -07:00
Adam_pi3
d3276d45e7
Modify the logic how LKRG tracks the exec syscalls
Since kernel 5.8 function search_binary_handler is not exported anymore.
On the aggressively optimized kernels it is possible that
`search_binary_handler` can be inlined. However, GCC can splits the
function to put the big part in its own function, which receives as a name
the original function name plus .part + .<some number>, and inlines the
rest in other functions.

This is a very problematic behavior from the LKRG point of view and was
reported as #41 and #45. This commit fixes the problem by replacing the
'search_binary_handler' (or 'do_execveat_common') hook with
security_bprm_committing_creds and security_bprm_committed_creds.
Additionally, this change is desired from the security point of view.
2021-01-19 00:42:25 -05:00
Adam_pi3
f7335cf712
Remove validation of waking-up tasks
Current LKRG's architecture has small benefits from validation waking-up
tasks. However, it might have noticeable performance impact. After this
commit, 'pint_validate' option 2 has the same meaning as option 1.
2021-01-08 16:18:57 -05:00
Adam_pi3
1299583b56
Fix commit: c049fa5695 2020-12-30 15:35:43 -05:00
Adam_pi3
58b9ec06e5
Integrate LKRG with 'out-of-tree' framework
Mikhail Klementev created an amazing framework which allows to automatically
verify LKRG under various kernel versions. Let's integrate LKRG's code-base
with it. We also have a simple configuration file to run it under simulated
Ubuntu 18.04 environment.
2020-12-29 18:21:39 -05:00
Mariusz Zaborski
645983fbf6 ptrace: replace ptrace kprobes with security_ptrace_access_check 2020-11-09 08:47:20 -08:00
Adam_pi3
6857d18aea
Add FTRACE support
1) We are hooking into FTRACE's internal functions to be able to monitor when new modifications are executed and react accordingly.
2) Linux kernel has bugs in FTRACE code. The LKRG may highlight them.
3) We are introducing 'p_state_init' variable to track when full LKRG's initialization is complete.
2020-11-01 21:40:46 -05:00
Adam_pi3
477be5d84c
Add LKRG's counter lock around *JUMP_LABEL engine
1) This is necessary for future FTRACE support. FTRACE is not fully synchronized with JUMP_LABEL (which I think is a buggy logic in the kernel). However, we can manually add such logic. The way how text_mutex is used by both subsystems makes it prone to deadlock if 3rd system wants to sync with both of them.
2) New lock efnorces changes in p_text_section_(un)lock API which we do in the same commit
3) Introduce new LKRG's counter lock API - trylock
4) Add a few minor changes:
  - notrace attribute (probably, we need to add such attributes to majority of our functions)
  - add information about module name in case of KMOD notifier activity
2020-10-30 14:34:53 -04:00
Mariusz Zaborski
069e10df4d Rework debug logging of entry and return from functions
Use instrumentation.  This reduces source code size by over 10%.

Signed-off-by: Mariusz Zaborski <oshogbo@vexillium.org>
2020-10-19 20:56:38 +02:00
Solar Designer
ccd71872c5 Drop init_module() and delete_module() syscall hooks 2020-07-08 15:26:20 +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
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
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
0cf451be9b
Add support for DKMS. Take into account variable KERNELRELEASE 2020-02-15 22:41:07 +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
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
b4fbad4989 [1] Add beta version support for ARM32, tested on raspberry pi 3 (model B)
[2] Refactor initialization logic
[3] Some minor fixes
2019-10-31 14:29:46 -04:00
Adam_pi3
15bb5f1c50 Cleanup 2019-07-18 18:16:24 +00:00
Adam_pi3
9eef608688 Change the logic how to dump/track a newly created task in the system 2019-07-10 21:51:34 +00:00
Adam_pi3
1be9ad649b Cleanups:
[1] Mask exporting global CFLAGS since it might be incompatible when LKRG is part of the bigger build project
 [2] Add default path for UMH when CONFIG_STATIC_USERMODEHELPER is used
 [3] Mask the most noisy STRONG_DEBUG output - doesn't have as much value. It can be always unmasked if needed.
 [4] Add support for the kernels without enabled CONFIG_DYNAMIC_DEBUG
 [5] Add support for the kernels without enabled CONFIG_ACPI
2019-05-23 18:46:52 +00:00
Adam_pi3
fcf720967b [1] Add potential debug compilation option to Makefile
[2] Fix 'colors' issue when systemd service installation fails
[3] [CI] Fix race condition with *_JUMP_LABEL engine resulting potential deadlock when LKRG is initialized parallel with other heavy kernel module (un)loading events
[4] [ED] Rewrite internal logic how LKRG synchronizes with the task's resources - big change
[5] [ED] Filter our kernel threads and system-init process when validation is performed bypassing threads iteration
[6] [ED] Disable IRQ in most cases when ED's pids DB lock is taken. Otherwise, we might have potential race and deadlock with kprobe engine itself, and SoftIRQs might deadlock with pCFI
2019-04-29 19:38:04 +00:00
Adam_pi3
3a9ef66437 [1] Refactor LKRG's code to support various CPU architecture
[2] Add beta version support for ARM64
[3] [ED] Fix FP (race condition) in pCFI in glitching scenario during process update and add memory barrier
[4] [ED] Fix potential FP during LKRG unloading procedure and add memory barrier
[5] [ED] Create own version of user_access_begin() function compatible across various kernel versions and leverage it for argument extraction for *init_module/delete_module
[6] [ED] Fix logic for *init_module/delete_module for kernel with CONFIG_ARCH_HAS_SYSCALL_WRAPPER
2019-04-20 19:17:00 +01:00
Adam_pi3
776aafc410 [1] Add support for OverlayFS commonly used by docker [2] Change internal flags logic [3] Address changes in subprocess_info structure for kernel 4.18+ 2019-04-02 17:28:40 +00:00
Adam_pi3
110360ac89 [1] Introduce a new LKRG sysctl interface lkrg.smep_panic enabled by default. [2] Introduce a new LKRG sysctl interface lkrg.umh_lock disabled by default [3] Add SMEP/WP bit verification in a new various places. [4] Enfore Stack Pointer validation on lookup_fast function 2019-02-20 18:35:27 -08:00
Adam_pi3
a214f6eb3e [CI] Complete rewrite of *_JUMP_LABEL support. New logic simplifies some internal algorithms, removes whitelisting logic (not needed anymore) and significantly reduce memory footprint. It's a huge change! 2019-02-15 06:52:21 -08:00
Adam_pi3
96721f15ec 1. Add LKRG early boot systemd script file. Currently only Systemd init system is supported. There are no technical reasons to not add support for other Init systems. 2. Modify Makefile to support install/unistall option which will deploy/remove systemd boot service. 3. [ED] Add functionality of freezing all user-mode processes during Exploit-Detection initialization. 2019-02-13 03:12:10 +03:00
Adam_pi3
072ecf0da4 Introduce pCFI mitigation - new type of mitigation which dynamically adds "poor's man CFI" 2018-12-31 12:52:20 -08:00
Adam_pi3
d17deeb974 Refactor wrapper code 2018-11-13 19:06:13 -05:00
Adam_pi3
f1a9b413fb Extend P_KVER variable definition in Makefile 2018-11-12 20:19:33 -08:00
Adam_pi3
343153fe5b Correctly handle override / revert creds 2018-10-17 20:22:11 -04:00
Adam_pi3
1be0d37de2 [ED] Replace 'may_open' with 'generic_permission' function hook. More information about what was the reason behind it, you can find in the source-code comments. 2018-09-18 14:23:44 -04:00
Adam_pi3
0b2b400cc2 [1] Add Mikhail Klementev's <jollheef@riseup.net> patch for Makefile. [2] Add Mikhail Klementev's <jollheef@riseup.net> patch which creates .gitignore file. [3] Add Mikhail Klementev's <jollheef@riseup.net> patch for missing include file (linux/profile.h) [4] [CI] Change output message format when *_JUMP_LABEL was detected for kernel module's .text section. 2018-09-04 17:43:48 -07:00
Adam_pi3
eaab5ec34e [CI] Add *_JUMP_LABEL support for kernel modules - very big and heavy change. 2018-09-04 17:25:37 -07:00
Adam_pi3
110cd7189f 1) This is a pretty big change in LKRG which brings support for 4.17+ kernels. 4.17 introduced a new logic how syscall stubs are created and change the name convetions + added new one. If kernel is compiled with CONFIG_IA32_EMULATION (implies CONFIG_COMPAT) and/or CONFIG_X32_X86 (and many distros does that), each syscall might generate up to 4 different stubs as an entry-point. Even 4 stubs exists, not all of them are used :) This of course affects Exploit Detection feature which needs to be aware about execution of critical syscalls, regardless if the entry point was from X32, IA32 or standard stub. Moreover, in the previous kernels, X32 ended up in the standard compat syscall, but now we need to create a separate hooks for the newly generated stubs. Also, now we need to add more syscalls to cover IA32_EMULATION logic - it was not needed in the previous kernels. I think this patch covers all corner cases - I hope I didn't miss anything :) 2) SELinux variables are now accumulated in one structure, before they were just global variables. We are addressing this change in this patch too. 3) Change the INFO messages (log_level=4) in case of error during ED initialization (more useful for debugging). 4) Change a bit the logic for monitoring a setgroups() syscall. This change is compatible across all kernels and can avoid monitoring multiple syscall stubs mentioned at point 1) 2018-08-14 21:50:54 +00:00
Adam_pi3
d277d3c234 [ED] Add support for call_usermodehelper 2018-02-12 23:06:38 -08:00
Adam_pi3
c8e92d37b2 Makefile changes (and clean up) 2018-02-04 19:26:06 -08:00
Adam_pi3
d83a339834 1. [ED] Change how the keyrings are supported 2. [ED] Add new logic for 'off' flag 3. [ED] Re-enable 'off_count' 4. [ED] Add ptrace interception 5. Fix typos... 2018-01-31 13:36:52 -08:00
Adam_pi3
1f729a1c11 1. Add new sysctl to silent 'clean' message regardless log_level 2. [ED] Add support for keyctl 3. [ED] Add support for COMPAT 2018-01-17 22:16:43 -08:00
Adam_pi3
67ca40fe9a [ED] Fix very gentle p_off_count uninit usage after mem cache reuse for the process tracking structure during OFFing process but before update is done. [ED] Add missing execveat syscall available since kernel 3.19+. [ED] Temporarily disable OFF count data corruption validation. [LKRG] Fix handling of ED initializaiton failure and hot plugging CPU not being executed yet. 2018-01-04 06:32:31 -08:00
Adam_pi3
51c60bbbc7 Replace SuperFastHash algorithm with SipHash 2017-12-20 20:45:46 -08:00
Adam_pi3
86b65cd650 [ED] Add Keyring support. Make LKRG fully functional on kernel 3.xx 2017-12-12 16:18:39 -08:00
Adam_pi3
77c9e0c353 [ED] Fix seccomp corner case. Refactor ED XOR p_off cookie code. Add missing commit_creds() entry points. 2017-12-05 22:51:33 -08:00
Adam_pi3
5a91e389e1 [ED] Add SECCOMP protection 2017-11-18 14:42:29 -08:00
Adam_pi3
a6f8abfcc0 Guard SELinux variables 2017-11-13 00:17:20 -08:00
Adam_pi3
45cf3846d0 Initial LKRG-main 2017-10-26 22:29:49 -07:00