Skip to content

Commit b1dba24

Browse files
committed
Merge tag 'selinux-pr-20200127' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux
Pull SELinux update from Paul Moore: "This is one of the bigger SELinux pull requests in recent years with 28 patches. Everything is passing our test suite and the highlights are below: - Mark CONFIG_SECURITY_SELINUX_DISABLE as deprecated. We're some time away from actually attempting to remove this in the kernel, but the only distro we know that still uses it (Fedora) is working on moving away from this so we want to at least let people know we are planning to remove it. - Reorder the SELinux hooks to help prevent bad things when SELinux is disabled at runtime. The proper fix is to remove the CONFIG_SECURITY_SELINUX_DISABLE functionality (see above) and just take care of it at boot time (e.g. "selinux=0"). - Add SELinux controls for the kernel lockdown functionality, introducing a new SELinux class/permissions: "lockdown { integrity confidentiality }". - Add a SELinux control for move_mount(2) that reuses the "file { mounton }" permission. - Improvements to the SELinux security label data store lookup functions to speed up translations between our internal label representations and the visible string labels (both directions). - Revisit a previous fix related to SELinux inode auditing and permission caching and do it correctly this time. - Fix the SELinux access decision cache to cleanup properly on error. In some extreme cases this could limit the cache size and result in a decrease in performance. - Enable SELinux per-file labeling for binderfs. - The SELinux initialized and disabled flags were wrapped with accessors to ensure they are accessed correctly. - Mark several key SELinux structures with __randomize_layout. - Changes to the LSM build configuration to only build security/lsm_audit.c when needed. - Changes to the SELinux build configuration to only build the IB object cache when CONFIG_SECURITY_INFINIBAND is enabled. - Move a number of single-caller functions into their callers. - Documentation fixes (/selinux -> /sys/fs/selinux). - A handful of cleanup patches that aren't worth mentioning on their own, the individual descriptions have plenty of detail" * tag 'selinux-pr-20200127' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux: (28 commits) selinux: fix regression introduced by move_mount(2) syscall selinux: do not allocate ancillary buffer on first load selinux: remove redundant allocation and helper functions selinux: remove redundant selinux_nlmsg_perm selinux: fix wrong buffer types in policydb.c selinux: reorder hooks to make runtime disable less broken selinux: treat atomic flags more carefully selinux: make default_noexec read-only after init selinux: move ibpkeys code under CONFIG_SECURITY_INFINIBAND. selinux: remove redundant msg_msg_alloc_security Documentation,selinux: fix references to old selinuxfs mount point selinux: deprecate disabling SELinux and runtime selinux: allow per-file labelling for binderfs selinuxfs: use scnprintf to get real length for inode selinux: remove set but not used variable 'sidtab' selinux: ensure the policy has been loaded before reading the sidtab stats selinux: ensure we cleanup the internal AVC counters on error in avc_update() selinux: randomize layout of key structures selinux: clean up selinux_enabled/disabled/enforcing_boot selinux: remove unnecessary selinux cred request ...
2 parents 07e309a + 98aa003 commit b1dba24

30 files changed

+1045
-559
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
What: /sys/fs/selinux/disable
2+
Date: April 2005 (predates git)
3+
KernelVersion: 2.6.12-rc2 (predates git)
4+
5+
Description:
6+
7+
The selinuxfs "disable" node allows SELinux to be disabled at runtime
8+
prior to a policy being loaded into the kernel. If disabled via this
9+
mechanism, SELinux will remain disabled until the system is rebooted.
10+
11+
The preferred method of disabling SELinux is via the "selinux=0" boot
12+
parameter, but the selinuxfs "disable" node was created to make it
13+
easier for systems with primitive bootloaders that did not allow for
14+
easy modification of the kernel command line. Unfortunately, allowing
15+
for SELinux to be disabled at runtime makes it difficult to secure the
16+
kernel's LSM hooks using the "__ro_after_init" feature.
17+
18+
Thankfully, the need for the SELinux runtime disable appears to be
19+
gone, the default Kconfig configuration disables this selinuxfs node,
20+
and only one of the major distributions, Fedora, supports disabling
21+
SELinux at runtime. Fedora is in the process of removing the
22+
selinuxfs "disable" node and once that is complete we will start the
23+
slow process of removing this code from the kernel.
24+
25+
More information on /sys/fs/selinux/disable can be found under the
26+
CONFIG_SECURITY_SELINUX_DISABLE Kconfig option.

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@
511511
1 -- check protection requested by application.
512512
Default value is set via a kernel config option.
513513
Value can be changed at runtime via
514-
/selinux/checkreqprot.
514+
/sys/fs/selinux/checkreqprot.
515515

516516
cio_ignore= [S390]
517517
See Documentation/s390/common_io.rst for details.
@@ -1245,7 +1245,8 @@
12451245
0 -- permissive (log only, no denials).
12461246
1 -- enforcing (deny and log).
12471247
Default value is 0.
1248-
Value can be changed at runtime via /selinux/enforce.
1248+
Value can be changed at runtime via
1249+
/sys/fs/selinux/enforce.
12491250

12501251
erst_disable [ACPI]
12511252
Disable Error Record Serialization Table (ERST)
@@ -4348,9 +4349,7 @@
43484349
See security/selinux/Kconfig help text.
43494350
0 -- disable.
43504351
1 -- enable.
4351-
Default value is set via kernel config option.
4352-
If enabled at boot time, /selinux/disable can be used
4353-
later to disable prior to initial policy load.
4352+
Default value is 1.
43544353

43554354
apparmor= [APPARMOR] Disable or enable AppArmor at boot time
43564355
Format: { "0" | "1" }

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14870,6 +14870,7 @@ F: include/uapi/linux/selinux_netlink.h
1487014870
F: security/selinux/
1487114871
F: scripts/selinux/
1487214872
F: Documentation/admin-guide/LSM/SELinux.rst
14873+
F: Documentation/ABI/obsolete/sysfs-selinux-disable
1487314874

1487414875
SENSABLE PHANTOM
1487514876
M: Jiri Slaby <[email protected]>

include/linux/lsm_audit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct common_audit_data {
7474
#define LSM_AUDIT_DATA_FILE 12
7575
#define LSM_AUDIT_DATA_IBPKEY 13
7676
#define LSM_AUDIT_DATA_IBENDPORT 14
77+
#define LSM_AUDIT_DATA_LOCKDOWN 15
7778
union {
7879
struct path path;
7980
struct dentry *dentry;
@@ -93,6 +94,7 @@ struct common_audit_data {
9394
struct file *file;
9495
struct lsm_ibpkey_audit *ibpkey;
9596
struct lsm_ibendport_audit *ibendport;
97+
int reason;
9698
} u;
9799
/* this union contains LSM specific data */
98100
union {

include/linux/security.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ enum lockdown_reason {
128128
LOCKDOWN_CONFIDENTIALITY_MAX,
129129
};
130130

131+
extern const char *const lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1];
132+
131133
/* These functions are in security/commoncap.c */
132134
extern int cap_capable(const struct cred *cred, struct user_namespace *ns,
133135
int cap, unsigned int opts);

security/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ obj-$(CONFIG_SECURITY) += security.o
2222
obj-$(CONFIG_SECURITYFS) += inode.o
2323
obj-$(CONFIG_SECURITY_SELINUX) += selinux/
2424
obj-$(CONFIG_SECURITY_SMACK) += smack/
25-
obj-$(CONFIG_AUDIT) += lsm_audit.o
25+
obj-$(CONFIG_SECURITY) += lsm_audit.o
2626
obj-$(CONFIG_SECURITY_TOMOYO) += tomoyo/
2727
obj-$(CONFIG_SECURITY_APPARMOR) += apparmor/
2828
obj-$(CONFIG_SECURITY_YAMA) += yama/

security/lockdown/lockdown.c

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,6 @@
1616

1717
static enum lockdown_reason kernel_locked_down;
1818

19-
static const char *const lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1] = {
20-
[LOCKDOWN_NONE] = "none",
21-
[LOCKDOWN_MODULE_SIGNATURE] = "unsigned module loading",
22-
[LOCKDOWN_DEV_MEM] = "/dev/mem,kmem,port",
23-
[LOCKDOWN_EFI_TEST] = "/dev/efi_test access",
24-
[LOCKDOWN_KEXEC] = "kexec of unsigned images",
25-
[LOCKDOWN_HIBERNATION] = "hibernation",
26-
[LOCKDOWN_PCI_ACCESS] = "direct PCI access",
27-
[LOCKDOWN_IOPORT] = "raw io port access",
28-
[LOCKDOWN_MSR] = "raw MSR access",
29-
[LOCKDOWN_ACPI_TABLES] = "modifying ACPI tables",
30-
[LOCKDOWN_PCMCIA_CIS] = "direct PCMCIA CIS storage",
31-
[LOCKDOWN_TIOCSSERIAL] = "reconfiguration of serial port IO",
32-
[LOCKDOWN_MODULE_PARAMETERS] = "unsafe module parameters",
33-
[LOCKDOWN_MMIOTRACE] = "unsafe mmio",
34-
[LOCKDOWN_DEBUGFS] = "debugfs access",
35-
[LOCKDOWN_XMON_WR] = "xmon write access",
36-
[LOCKDOWN_INTEGRITY_MAX] = "integrity",
37-
[LOCKDOWN_KCORE] = "/proc/kcore access",
38-
[LOCKDOWN_KPROBES] = "use of kprobes",
39-
[LOCKDOWN_BPF_READ] = "use of bpf to read kernel RAM",
40-
[LOCKDOWN_PERF] = "unsafe use of perf",
41-
[LOCKDOWN_TRACEFS] = "use of tracefs",
42-
[LOCKDOWN_XMON_RW] = "xmon read and write access",
43-
[LOCKDOWN_CONFIDENTIALITY_MAX] = "confidentiality",
44-
};
45-
4619
static const enum lockdown_reason lockdown_levels[] = {LOCKDOWN_NONE,
4720
LOCKDOWN_INTEGRITY_MAX,
4821
LOCKDOWN_CONFIDENTIALITY_MAX};

security/lsm_audit.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/dccp.h>
2828
#include <linux/sctp.h>
2929
#include <linux/lsm_audit.h>
30+
#include <linux/security.h>
3031

3132
/**
3233
* ipv4_skb_to_auditdata : fill auditdata from skb
@@ -425,6 +426,10 @@ static void dump_common_audit_data(struct audit_buffer *ab,
425426
a->u.ibendport->dev_name,
426427
a->u.ibendport->port);
427428
break;
429+
case LSM_AUDIT_DATA_LOCKDOWN:
430+
audit_log_format(ab, " lockdown_reason=");
431+
audit_log_string(ab, lockdown_reasons[a->u.reason]);
432+
break;
428433
} /* switch (a->type) */
429434
}
430435

security/security.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,39 @@
3535
#define LSM_COUNT (__end_lsm_info - __start_lsm_info)
3636
#define EARLY_LSM_COUNT (__end_early_lsm_info - __start_early_lsm_info)
3737

38+
/*
39+
* These are descriptions of the reasons that can be passed to the
40+
* security_locked_down() LSM hook. Placing this array here allows
41+
* all security modules to use the same descriptions for auditing
42+
* purposes.
43+
*/
44+
const char *const lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1] = {
45+
[LOCKDOWN_NONE] = "none",
46+
[LOCKDOWN_MODULE_SIGNATURE] = "unsigned module loading",
47+
[LOCKDOWN_DEV_MEM] = "/dev/mem,kmem,port",
48+
[LOCKDOWN_EFI_TEST] = "/dev/efi_test access",
49+
[LOCKDOWN_KEXEC] = "kexec of unsigned images",
50+
[LOCKDOWN_HIBERNATION] = "hibernation",
51+
[LOCKDOWN_PCI_ACCESS] = "direct PCI access",
52+
[LOCKDOWN_IOPORT] = "raw io port access",
53+
[LOCKDOWN_MSR] = "raw MSR access",
54+
[LOCKDOWN_ACPI_TABLES] = "modifying ACPI tables",
55+
[LOCKDOWN_PCMCIA_CIS] = "direct PCMCIA CIS storage",
56+
[LOCKDOWN_TIOCSSERIAL] = "reconfiguration of serial port IO",
57+
[LOCKDOWN_MODULE_PARAMETERS] = "unsafe module parameters",
58+
[LOCKDOWN_MMIOTRACE] = "unsafe mmio",
59+
[LOCKDOWN_DEBUGFS] = "debugfs access",
60+
[LOCKDOWN_XMON_WR] = "xmon write access",
61+
[LOCKDOWN_INTEGRITY_MAX] = "integrity",
62+
[LOCKDOWN_KCORE] = "/proc/kcore access",
63+
[LOCKDOWN_KPROBES] = "use of kprobes",
64+
[LOCKDOWN_BPF_READ] = "use of bpf to read kernel RAM",
65+
[LOCKDOWN_PERF] = "unsafe use of perf",
66+
[LOCKDOWN_TRACEFS] = "use of tracefs",
67+
[LOCKDOWN_XMON_RW] = "xmon read and write access",
68+
[LOCKDOWN_CONFIDENTIALITY_MAX] = "confidentiality",
69+
};
70+
3871
struct security_hook_heads security_hook_heads __lsm_ro_after_init;
3972
static BLOCKING_NOTIFIER_HEAD(blocking_lsm_notifier_chain);
4073

security/selinux/Kconfig

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ config SECURITY_SELINUX_DISABLE
4242
using the selinux=0 boot parameter instead of enabling this
4343
option.
4444

45+
WARNING: this option is deprecated and will be removed in a future
46+
kernel release.
47+
4548
If you are unsure how to answer this question, answer N.
4649

4750
config SECURITY_SELINUX_DEVELOP
@@ -55,15 +58,16 @@ config SECURITY_SELINUX_DEVELOP
5558
kernel will start in permissive mode (log everything, deny nothing)
5659
unless you specify enforcing=1 on the kernel command line. You
5760
can interactively toggle the kernel between enforcing mode and
58-
permissive mode (if permitted by the policy) via /selinux/enforce.
61+
permissive mode (if permitted by the policy) via
62+
/sys/fs/selinux/enforce.
5963

6064
config SECURITY_SELINUX_AVC_STATS
6165
bool "NSA SELinux AVC Statistics"
6266
depends on SECURITY_SELINUX
6367
default y
6468
help
6569
This option collects access vector cache statistics to
66-
/selinux/avc/cache_stats, which may be monitored via
70+
/sys/fs/selinux/avc/cache_stats, which may be monitored via
6771
tools such as avcstat.
6872

6973
config SECURITY_SELINUX_CHECKREQPROT_VALUE
@@ -82,6 +86,29 @@ config SECURITY_SELINUX_CHECKREQPROT_VALUE
8286
default to checking the protection requested by the application.
8387
The checkreqprot flag may be changed from the default via the
8488
'checkreqprot=' boot parameter. It may also be changed at runtime
85-
via /selinux/checkreqprot if authorized by policy.
89+
via /sys/fs/selinux/checkreqprot if authorized by policy.
8690

8791
If you are unsure how to answer this question, answer 0.
92+
93+
config SECURITY_SELINUX_SIDTAB_HASH_BITS
94+
int "NSA SELinux sidtab hashtable size"
95+
depends on SECURITY_SELINUX
96+
range 8 13
97+
default 9
98+
help
99+
This option sets the number of buckets used in the sidtab hashtable
100+
to 2^SECURITY_SELINUX_SIDTAB_HASH_BITS buckets. The number of hash
101+
collisions may be viewed at /sys/fs/selinux/ss/sidtab_hash_stats. If
102+
chain lengths are high (e.g. > 20) then selecting a higher value here
103+
will ensure that lookups times are short and stable.
104+
105+
config SECURITY_SELINUX_SID2STR_CACHE_SIZE
106+
int "NSA SELinux SID to context string translation cache size"
107+
depends on SECURITY_SELINUX
108+
default 256
109+
help
110+
This option defines the size of the internal SID -> context string
111+
cache, which improves the performance of context to string
112+
conversion. Setting this option to 0 disables the cache completely.
113+
114+
If unsure, keep the default value.

0 commit comments

Comments
 (0)