forked from torvalds/linux
Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
NAX LSM: Add initial support
Add initial support for NAX (No Anonymous Execution), which is a Linux Security Module that extends DAC by making impossible to make anonymous and modified pages executable for privileged processes. Intercepts anonymous executable pages created with mmap() and mprotect() system calls. Log violations (in non-quiet mode) and block the action or kill the offending process, depending on the enabled settings. See Documentation/admin-guide/LSM/NAX.rst. Signed-off-by: Igor Zhbanov <izh1979@gmail.com>
- Loading branch information
1 parent
349a2d5
commit 6c93ee3871fae69975f9fc3c41c0f65743ea7ac8
Showing
9 changed files
with
703 additions
and
5 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| ======= | ||
| NAX LSM | ||
| ======= | ||
|
|
||
| :Author: Igor Zhbanov | ||
|
|
||
| NAX (No Anonymous Execution) is a Linux Security Module that extends DAC | ||
| by making impossible to make anonymous and modified pages executable for | ||
| processes. The module intercepts anonymous executable pages created with | ||
| mmap() and mprotect() system calls. | ||
|
|
||
| To select it at boot time, add ``nax`` to ``security`` kernel command-line | ||
| parameter. | ||
|
|
||
| The following sysctl parameters are available: | ||
|
|
||
| * ``kernel.nax.check_all``: | ||
| - 0: Check all processes. | ||
| - 1: Check only privileged processes. The privileged process is a process | ||
| for which any of the following is true: | ||
| - ``uid == 0`` | ||
| - ``euid == 0`` | ||
| - ``suid == 0`` | ||
| - ``cap_effective`` has any capability except for the ones allowed | ||
| in ``kernel.nax.allowed_caps`` | ||
| - ``cap_permitted`` has any capability except for the ones allowed | ||
| in ``kernel.nax.allowed_caps`` | ||
|
|
||
| Checking of uid/euid/suid is important because a process may call seteuid(0) | ||
| to gain privileges (if SECURE_NO_SETUID_FIXUP secure bit is not set). | ||
|
|
||
| * ``kernel.nax.allowed_caps``: | ||
|
|
||
| Hexadecimal number representing the set of capabilities a non-root | ||
| process can possess without being considered "privileged" by NAX LSM. | ||
|
|
||
| For the meaning of the capabilities bits and their value, please check | ||
| ``include/uapi/linux/capability.h`` and ``capabilities(7)`` manual page. | ||
|
|
||
| For example, ``CAP_SYS_PTRACE`` has a number 19. Therefore, to add it to | ||
| allowed capabilities list, we need to set 19'th bit (2^19 or 1 << 19) | ||
| or 80000 in hexadecimal form. Capabilities can be bitwise ORed. | ||
|
|
||
| * ``kernel.nax.mode``: | ||
|
|
||
| - 0: Only log errors (when enabled by ``kernel.nax.quiet``) (default mode) | ||
| - 1: Forbid unsafe pages mappings (and log when enabled) | ||
| - 2: Kill the violating process (and log when enabled) | ||
|
|
||
| * ``kernel.nax.quiet``: | ||
|
|
||
| - 0: Log violations (default) | ||
| - 1: Be quiet | ||
|
|
||
| * ``kernel.nax.locked``: | ||
|
|
||
| - 0: Changing of the module's sysctl parameters is allowed | ||
| - 1: Further changing of the module's sysctl parameters is forbidden | ||
|
|
||
| Setting this parameter to ``1`` after initial setup during the system boot | ||
| will prevent the module disabling at the later time. | ||
|
|
||
| There are matching kernel command-line parameters (with the same values): | ||
|
|
||
| - ``nax_allowed_caps`` | ||
| - ``nax_check_all`` | ||
| - ``nax_mode`` | ||
| - ``nax_quiet`` | ||
| - ``nax_locked`` | ||
|
|
||
| The ``nax_locked`` command-line parameter must be specified last to avoid | ||
| premature setting locking. |
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 |
|---|---|---|
| @@ -42,6 +42,7 @@ subdirectories. | ||
|
|
||
| apparmor | ||
| LoadPin | ||
| NAX | ||
| SELinux | ||
| Smack | ||
| tomoyo | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| # SPDX-License-Identifier: GPL-2.0-only | ||
| config SECURITY_NAX | ||
| bool "NAX support" | ||
| depends on SECURITY | ||
| help | ||
| This selects NAX (No Anonymous Execution), which extends DAC | ||
| support with additional system-wide security settings beyond | ||
| regular Linux discretionary access controls. Currently, the only | ||
| available behavior is restricting the execution of anonymous and | ||
| modified pages. | ||
|
|
||
| The module can restrict either privileged or all processes, | ||
| depending on the settings. It is possible to configure action, | ||
| performed when the violation is detected (log, log + block, | ||
| log + kill). | ||
|
|
||
| Further information can be found in | ||
| Documentation/admin-guide/LSM/NAX.rst. | ||
|
|
||
| If you are unsure how to answer this question, answer N. | ||
|
|
||
| choice | ||
| prompt "NAX violation action mode" | ||
| default SECURITY_NAX_MODE_LOG | ||
| depends on SECURITY_NAX | ||
| help | ||
| Select the NAX violation action mode. | ||
|
|
||
| In the default permissive mode the violations are only logged | ||
| (if logging is not suppressed). In the enforcing mode the violations | ||
| are prohibited. And in the kill mode the process is terminated. | ||
|
|
||
| The value can be overridden at boot time with the kernel command-line | ||
| parameter "nax_mode=" (0, 1, 2) or "kernel.nax.mode=" (0, 1, 2) | ||
| sysctl parameter (if the settings are not locked). | ||
|
|
||
| config SECURITY_NAX_MODE_LOG | ||
| bool "Permissive mode" | ||
| help | ||
| In this mode violations are only logged (if logging is not | ||
| suppressed by the "kernel.nax.quiet" parameter). The | ||
| violating system call will not be prohibited. | ||
| config SECURITY_NAX_MODE_ENFORCING | ||
| bool "Enforcing mode" | ||
| help | ||
| In this mode violations are prohibited and logged (if | ||
| logging is not suppressed by the "kernel.nax.quiet" | ||
| parameter). The violating system call will return -EACCES | ||
| error. | ||
| config SECURITY_NAX_MODE_KILL | ||
| bool "Kill mode" | ||
| help | ||
| In this mode the violating process is terminated on the | ||
| first violation system call. The violation event is logged | ||
| (if logging is not suppressed by the "kernel.nax.quiet" | ||
| parameter). | ||
| endchoice | ||
|
|
||
| config SECURITY_NAX_MODE | ||
| int | ||
| depends on SECURITY_NAX | ||
| default 0 if SECURITY_NAX_MODE_LOG | ||
| default 1 if SECURITY_NAX_MODE_ENFORCING | ||
| default 2 if SECURITY_NAX_MODE_KILL | ||
|
|
||
| config SECURITY_NAX_CHECK_ALL | ||
| bool "Check all processes" | ||
| depends on SECURITY_NAX | ||
| help | ||
| If selected, NAX will check all processes. If not selected, NAX | ||
| will check only privileged processes (which is determined either | ||
| by having zero uid, euid, suid or fsuid; or by possessing | ||
| capabilities outside of allowed set). | ||
|
|
||
| The value can also be overridden at boot time with the kernel | ||
| command-line parameter "nax_check_all=" (0, 1) or | ||
| "kernel.nax.check_all=" (0, 1) sysctl parameter (if the settings | ||
| are not locked). | ||
|
|
||
| config SECURITY_NAX_ALLOWED_CAPS | ||
| hex "Process capabilities ignored by NAX" | ||
| default 0x0 | ||
| range 0x0 0xffffffffffff | ||
| depends on SECURITY_NAX | ||
| help | ||
| Hexadecimal number representing the set of capabilities | ||
| a non-root process can possess without being considered | ||
| "privileged" by NAX LSM. | ||
|
|
||
| The value can be overridden at boot time with the command-line | ||
| parameter "nax_allowed_caps=" or "kernel.nax.allowed_caps=" sysctl | ||
| parameter (if the settings are not locked). | ||
|
|
||
| config SECURITY_NAX_QUIET | ||
| bool "Silence NAX messages" | ||
| depends on SECURITY_NAX | ||
| help | ||
| If selected, NAX will not print violations. | ||
|
|
||
| The value can be overridden at boot with the command-line | ||
| parameter "nax_quiet=" (0, 1) or "kernel.nax.quiet=" (0, 1) sysctl | ||
| parameter (if the settings are not locked). | ||
|
|
||
| config SECURITY_NAX_LOCKED | ||
| bool "Lock NAX settings" | ||
| depends on SECURITY_NAX | ||
| help | ||
| Prevent any update to the settings of the NAX LSM. This applies to | ||
| both sysctl writes and the kernel command line. | ||
|
|
||
| If not selected, it can be enabled at boot time with the kernel | ||
| command-line parameter "nax_locked=1" or "kernel.nax_locked=1" | ||
| sysctl parameter (if the settings are not locked). |
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,4 @@ | ||
| # SPDX-License-Identifier: GPL-2.0-only | ||
| obj-$(CONFIG_SECURITY_NAX) := nax.o | ||
|
|
||
| nax-y := nax-lsm.o |
Oops, something went wrong.