Commit graph

206 commits

Author SHA1 Message Date
0xC0ncord
c7d427de47 Fix resolution and usage of put_seccomp_filter on Linux >= 5.9 2020-10-19 10:19:23 +02:00
0xC0ncord
24d7117647 Dynamically resolve __module_address and __module_text_address on Linux
>= 5.9
2020-10-19 10:19:23 +02:00
0xC0ncord
a46e7b0ae1 Fix checking of umh in-memory files on Linux >= 5.9 2020-10-19 10:19:23 +02:00
Adam_pi3
330bd59fb7
Remove dependency on 'jump_label_mutex'
With the current design of JUMP_LABEL support we do not need to manually take this mutex. Our hooks are deep enough to be protected and integrity routine depends on text mutext
2020-10-11 14:22:29 -04:00
Adam_pi3
fa7857a7ea
Minor change in deregister function
Move arch-specific kprobe deregistration close to ED.
2020-10-10 21:30:34 -04:00
Solar Designer
1b6d98e123 Detect any changes of UIDs/GIDs, not just lowering of them
The limited detection was an inadvertent leftover from very early stages of
LKRG development.  Reported by Vadim Andreev.
2020-09-18 23:24:43 +02:00
William
372bb0cdbb Log file permissions in octal format 2020-09-18 09:07:54 +02:00
Adam_pi3
ef4d2c5f0b
Change SELinux synchronization logic
Introduce new type of SELinux lock type - p_lkrg_selinux_lock. Verification routine can take this lock only when atomic counter is zero. This means there are no other consumers of SELinux variables
2020-08-31 15:05:00 -04:00
Adam_pi3
6f700b5b08
Add support for RHEL 8.2
New kernels for RHEL 8.2 backported JUMP_LABEL batch-mode feature. Add support for it.
2020-08-27 21:59:16 -04:00
Adam_pi3
a311616633
Introduce P_LKRG_JUMP_LABEL_STEXT_DEBUG compilation flag.
If we want to track all changes in kernel core .text section and when modification happens we want to know which exactly bytes were modified, which offset and what's the symbol corelated to it, we can compile LKRG with this feature. Disabled by default. It's mostly useful for debugging.
2020-08-27 21:55:02 -04:00
Adam_pi3
2404d32a19
Don't disable preemption.
We don't need to disable preemption in this code path.
2020-08-27 21:18:58 -04:00
Adam_pi3
73e923b5b0
Fix failure path
If error appears during database creation, we might deadlock system since we do not unlock text section
2020-08-27 21:15:29 -04:00
Adam_pi3
4adc39fe68
Remove internal JL sync lock
It's OK to remove such lock, since LKRG .text section validation is syncing with the kernel through JL mutex and .text mutex. There is one corner case where these mutexes are not taken by the kernel when new kernel module might be compiled without long nops. In such case, Linux kernel might modify such .text and 'inject' long-nops where is needed, however, it is done when new module has UNFORMED state. UNFORMED modules can't be verified yet so we are fine.
2020-08-25 11:53:52 -04:00
Vitaly Chikunov
072a1b8367 Fix implicit declaration of function 'task_stack_page' on arm
Due to kernel commit f3ac60671954c ("sched/headers: Move task-stack
related APIs from <linux/sched.h> to <linux/sched/task_stack.h>") (Linux
v4.11) `linux/sched/task_stack.h' should be included to access
`task_stack_page'.

Compilation failure is appearing on armv8l arch:

  In file included from ./include/linux/prefetch.h:15,
		   from ./arch/arm/include/asm/atomic.h:12,
		   from ./include/linux/atomic.h:7,
		   from ./include/asm-generic/bitops/lock.h:5,
		   from ./arch/arm/include/asm/bitops.h:243,
		   from ./include/linux/bitops.h:26,
		   from ./include/linux/kernel.h:12,
		   from /usr/src/RPM/BUILD/lkrg-0.8.1/src/modules/exploit_detection/../../p_lkrg_main.h:23,
		   from /usr/src/RPM/BUILD/lkrg-0.8.1/src/modules/exploit_detection/p_exploit_detection.c:18:
  /usr/src/RPM/BUILD/lkrg-0.8.1/src/modules/exploit_detection/p_exploit_detection.c: In function 'p_iterate_processes':
  ./arch/arm/include/asm/processor.h:99:40: error: implicit declaration of function 'task_stack_page'; did you mean 'walk_stackframe'? [-Werror=implicit-function-declaration]
     99 |  ((struct pt_regs *)(THREAD_START_SP + task_stack_page(p)) - 1)
	|                                        ^~~~~~~~~~~~~~~
  /usr/src/RPM/BUILD/lkrg-0.8.1/src/modules/exploit_detection/p_exploit_detection.c:779:30: note: in expansion of macro 'task_pt_regs'
    779 |                p_regs_set_ip(task_pt_regs(p_tmp), -1);
	|                              ^~~~~~~~~~~~
  cc1: some warnings being treated as errors
  make[1]: *** [scripts/Makefile.build:265: /usr/src/RPM/BUILD/lkrg-0.8.1/src/modules/exploit_detection/p_exploit_detection.o] Error 1

Signed-off-by: Vitaly Chikunov <vt@altlinux.org>
2020-08-19 17:02:27 +02:00
Vitaly Chikunov
2648a1d607 Various spelling and grammar corrections (#7)
* Various spelling corrections by codespell 1.17.1
* Various grammar corrections

Signed-off-by: Vitaly Chikunov <vt@altlinux.org>
Co-authored-by: Solar Designer <solar@openwall.com>
2020-08-19 00:59:35 +02:00
Adam_pi3
671b079eb9
Since kernel 5.8 function native_write_cr4 is not exported anymore. We could write own function which modifies CR4, however, we don't want to introduce new potential gadgets. Instead we dynamically resolve it to fix this problem. 2020-08-16 13:38:24 -04:00
Solar Designer
8d926b99fe Fix build with non-RHEL kernels broken with the previous commit 2020-08-05 18:19:32 +02:00
Solar Designer
b459b334e6 Don't include linux/cryptohash.h on recent kernels
This fixes LKRG build on Linux 5.8+, which renamed that header file.  Thanks to
Andy Lavr for reporting this problem and suggesting a (different) fix, which
made us revisit our use of that header file.

We only need that header file on older kernels (< 4.4.72 or < RHEL 7.4) for the
one use of md5_transform() in get_random_long().  On newer kernels, we simply
use the kernel-provided get_random_long().  Further, 5.8's crypto/sha.h doesn't
declare md5_transform() anyway (linux/cryptohash.h on much older kernels did).
2020-08-04 21:49:32 +02:00
Adam_pi3
32fc7d27ae
New RHEL kernels define 'struct stack_trace' by themselves. Take this into account 2020-07-15 20:26:23 -04:00
Solar Designer
cfe3bf406e No longer ask people to contact us for no-CONFIG_JUMP_LABEL support 2020-07-08 16:36:28 +02:00
Solar Designer
ccd71872c5 Drop init_module() and delete_module() syscall hooks 2020-07-08 15:26:20 +02:00
Adam_pi3
b3a499e7f6
Fix user-triggerable Oops (dereference of a near-NULL pointer) on newer kernels with new syscall implementation. Found by Jason A. Donenfeld. 2020-07-04 16:11:17 -04:00
Adam_pi3
ec595f555b
It was reported that in a very slow devices, some of the busy loop of locking/unlocking text_mutext is too tight and optimize_kprobe() can't win the race of getting text_mutex. This simple patch helps to solve that problem. 2020-06-30 12:11:10 -04:00
Adam_pi3
7ee25605d5
Rename profile names 2020-06-23 18:19:32 -04:00
Adam_pi3
73ec77654f
Make msr_validate=1 only in paranoid profile 2020-06-23 14:47:48 -04:00
Adam_pi3
07eb00cee1
Before leaving process integrity verification routine in paranoid mode, verify current task 2020-06-22 19:00:28 -04:00
Adam_pi3
8e4d93380e
Set default knobs and profile values to: profile_validate=3 and profile_enforce=2 2020-06-21 12:46:23 -04:00
Adam_pi3
97cb12a801
Cleanup commit 2020-06-19 13:20:39 -04:00
Adam_pi3
bb3a3a9ec7
Change the logic of detecting a situation when already blocked path sotred in memory is being reexecuted 2020-06-18 14:33:22 -04:00
Adam_pi3
44dc1bb72d
Minor fix 2020-06-17 13:43:59 -04:00
Adam_pi3
75f866d5ca
Minor fix on on-x86 platforms 2020-06-17 13:10:34 -04:00
Adam_pi3
b67e642ee6
Remove misleading comments 2020-06-16 17:45:33 -04:00
Adam_pi3
841bb4dc47
unwind.h is not available on RHEL7 with old kernel(s). Fix it. 2020-06-14 19:21:09 -04:00
Adam_pi3
a900c9fa41
[1] Change UMH messages to not be unnecessarily verbose and shouting.
[2] Take into account a special case situation when already blocked path sotred in memory is being reexecuted.
2020-06-14 15:02:20 -04:00
Adam_pi3
9b4dea13da
Change log_level from ERR->WARN for ISRA / CONSPROP. Refactor when the logs are printed 2020-06-13 18:40:13 -04:00
Adam_pi3
72084d989a
Add support for CONSTPROP optimized functions:
- Some of the functions might be optimized by CONSTPROP. However, some of the hooks can still be functional even under CONSTPROP optimized functions.
2020-06-12 17:58:05 -04:00
Adam_pi3
cd62484459
Fix RB-tree deletion logic 2020-06-11 11:28:16 -04:00
Adam_pi3
ee1263aa66
[1] Change initialization logic for exploit detection module:
- Not all hooks are fatal. If for any reason non-fatal hook can't be placed, continue initialization and print appropriate message
  - If hook is fatal, stop intialization
[2] Add support for ISRA optimized functions:
  - Some of the functions might be optimized by ISRA. However, some of the hooks can still be functional even under ISRA optimized functions.
2020-06-09 17:38:01 -04:00
Adam_pi3
8e660501d8
[x86] Use Boot CPU to verify smXp flags 2020-06-04 16:42:32 -04:00
Adam_pi3
5ddb061719
Fix hiding feature. This code was not correctly adopted to support newly introduced RO page 2020-06-04 13:37:14 -04:00
Adam_pi3
c46108cec6
Add verification whether specific CONFIG_* options are enabled 2020-06-04 12:32:43 -04:00
Adam_pi3
d57b4c0f0e
Since kernel 5.7 "kallsyms_lookup_name" and "kallsyms_on_each_symbol" functions are not exported. This patch (hack) retrives necessary function pointer 2020-06-03 16:28:30 -04:00
Adam_pi3
d8869b0e85
Minor fixes - typos, spaces, formating, etc. 2020-06-03 00:22:04 -04:00
Mariusz Zaborski
7a99c0c599 Merged in oshogbo/lkrg-osho/umh (pull request #6)
Rework UMH.

* Introduce nitems for nice array counting scheme.

* Rework the umh whitelist.

    No functional changes intended.

* Sort the UMH and remove dups.
2020-06-03 03:34:30 +00:00
Adam_pi3
0b0b469739
[1] Fix 'kint_validate = 1' logic
[2] Change timer delete logic
2020-05-28 02:22:04 -04:00
Adam_pi3
11da921d41
Introduce 'profiles' configurable from the sysctl interfact:
1) profile_validate:
     a) 0 (Disabled):
        -> kint_validate = 0 (Disabled)
        -> pint_validate = 0 (Disabled)
        -> pcfi_validate = 0 (Disabled)
        -> umh_validate  = 0 (Disabled)
        -> msr_validate  = 0 (Disabled)
        -> smep_validate = 0 (Disabled)
        -> smap_validate = 0 (Disabled)
     b) 1 (Light):
        -> kint_validate = 1 (Manual trigger only)
        -> pint_validate = 1 (Current task only)
        -> pcfi_validate = 1 (Weak pCFI)
        -> umh_validate  = 1 (Whitelist)
        -> msr_validate  = 0 (Disabled)
        -> smep_validate = 1 (Enabled)
        -> smap_validate = 1 (Enabled)
     c) 2 (Balanced):
        -> kint_validate = 2 (Triggered by timer)
        -> pint_validate = 2 (Current + weaking up task)
        -> pcfi_validate = 1 (Weak pCFI)
        -> umh_validate  = 1 (Whitelist)
        -> msr_validate  = 0 (Disabled)
        -> smep_validate = 1 (Enabled)
        -> smap_validate = 1 (Enabled)
     d) 3 (Moderate):
        -> kint_validate = 3 (Triggered by timer + random events)
        -> pint_validate = 2 (Current + weaking up task)
        -> pcfi_validate = 2 (Full pCFI)
        -> umh_validate  = 1 (Whitelist)
        -> msr_validate  = 1 (Enabled)
        -> smep_validate = 1 (Enabled)
        -> smap_validate = 1 (Enabled)
     e) 4 (Heavy):
        -> kint_validate = 3 (Triggered by timer + random events)
        -> pint_validate = 3 (Paranoid mode - verify all tasks in the system by every hook)
        -> pcfi_validate = 2 (Full pCFI)
        -> umh_validate  = 2 (Full UMH lock-down)
        -> msr_validate  = 1 (Enabled)
        -> smep_validate = 1 (Enabled)
        -> smap_validate = 1 (Enabled)

 2) profile_enforce:
     a) 0 (Log & Accept):
        -> kint_enforce = 0 (Log & accept)
        -> pint_enforce = 0 (Log & accept)
        -> pcfi_enforce = 0 (Log only)
        -> umh_enforce  = 0 (Log only)
        -> smep_enforce = 0 (Log & accept)
        -> smap_enforce = 0 (Log & accept)
     b) 1 (Balanced - selective panic):
        -> kint_enforce = 1 (Log only)
        -> pint_enforce = 1 (Kill task)
        -> pcfi_enforce = 1 (Kill task)
        -> umh_enforce  = 1 (Prevent execution)
        -> smep_enforce = 2 (Panic)
        -> smap_enforce = 2 (Panic)
     c) 2 (Moderate - more panic):
        -> kint_enforce = 2 (Panic)
        -> pint_enforce = 1 (Kill task)
        -> pcfi_enforce = 1 (Kill task)
        -> umh_enforce  = 1 (Prevent execution)
        -> smep_enforce = 2 (Panic)
        -> smap_enforce = 2 (Panic)
     d) 3 (Panic):
        -> kint_enforce = 2 (Panic)
        -> pint_enforce = 2 (Panic)
        -> pcfi_enforce = 2 (Panic)
        -> umh_enforce  = 2 (Panic)
        -> smep_enforce = 2 (Panic)
        -> smap_enforce = 2 (Panic)
2020-05-27 12:24:00 -04:00
Adam_pi3
b1b11e99cf
Group hot RO page settings into a cache line 2020-05-21 15:16:53 -04:00
Adam_pi3
5f691f6324
Remove redundant checks for CPU bits 2020-05-20 21:07:40 -04:00
Adam_pi3
37fa35e0cc
Fix typo 2020-05-19 21:40:53 -04:00
Adam_pi3
9077cae8b9
Some more improvements regarding smXp validation 2020-05-18 16:03:29 -04:00