Skip to content

Commit 1dbae18

Browse files
committed
Merge tag 'selinux-pr-20230829' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux
Pull selinux updates from Paul Moore: "Thirty three SELinux patches, which is a pretty big number for us, but there isn't really anything scary in here; in fact we actually manage to remove 10 lines of code with this :) - Promote the SELinux DEBUG_HASHES macro to CONFIG_SECURITY_SELINUX_DEBUG The DEBUG_HASHES macro was a buried SELinux specific preprocessor debug macro that was a problem waiting to happen. Promoting the debug macro to a proper Kconfig setting should help both improve the visibility of the feature as well enable improved test coverage. We've moved some additional debug functions under the CONFIG_SECURITY_SELINUX_DEBUG flag and we may see more work in the future. - Emit a pr_notice() message if virtual memory is executable by default As this impacts the SELinux access control policy enforcement, if the system's configuration is such that virtual memory is executable by default we print a single line notice to the console. - Drop avtab_search() in favor of avtab_search_node() Both functions are nearly identical so we removed avtab_search() and converted the callers to avtab_search_node(). - Add some SELinux network auditing helpers The helpers not only reduce a small amount of code duplication, but they provide an opportunity to improve UDP flood performance slightly by delaying initialization of the audit data in some cases. - Convert GFP_ATOMIC allocators to GFP_KERNEL when reading SELinux policy There were two SELinux policy load helper functions that were allocating memory using GFP_ATOMIC, they have been converted to GFP_KERNEL. - Quiet a KMSAN warning in selinux_inet_conn_request() A one-line error path (re)set patch that resolves a KMSAN warning. It is important to note that this doesn't represent a real bug in the current code, but it quiets KMSAN and arguably hardens the code against future changes. - Cleanup the policy capability accessor functions This is a follow-up to the patch which reverted SELinux to using a global selinux_state pointer. This patch cleans up some artifacts of that change and turns each accessor into a one-line READ_ONCE() call into the policy capabilities array. - A number of patches from Christian Göttsche Christian submitted almost two-thirds of the patches in this pull request as he worked to harden the SELinux code against type differences, variable overflows, etc. - Support for separating early userspace from the kernel in policy, with a later revert We did have a patch that added a new userspace initial SID which would allow SELinux to distinguish between early user processes created before the initial policy load and the kernel itself. Unfortunately additional post-merge testing revealed a problematic interaction with an old SELinux userspace on an old version of Ubuntu so we've reverted the patch until we can resolve the compatibility issue. - Remove some outdated comments dealing with LSM hook registration When we removed the runtime disable functionality we forgot to remove some old comments discussing the importance of LSM hook registration ordering. - Minor administrative changes Stephen Smalley updated his email address and "debranded" SELinux from "NSA SELinux" to simply "SELinux". We've come a long way from the original NSA submission and I would consider SELinux a true community project at this point so removing the NSA branding just makes sense" * tag 'selinux-pr-20230829' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux: (33 commits) selinux: prevent KMSAN warning in selinux_inet_conn_request() selinux: use unsigned iterator in nlmsgtab code selinux: avoid implicit conversions in policydb code selinux: avoid implicit conversions in selinuxfs code selinux: make left shifts well defined selinux: update type for number of class permissions in services code selinux: avoid implicit conversions in avtab code selinux: revert SECINITSID_INIT support selinux: use GFP_KERNEL while reading binary policy selinux: update comment on selinux_hooks[] selinux: avoid implicit conversions in services code selinux: avoid implicit conversions in mls code selinux: use identical iterator type in hashtab_duplicate() selinux: move debug functions into debug configuration selinux: log about VM being executable by default selinux: fix a 0/NULL mistmatch in ad_net_init_from_iif() selinux: introduce SECURITY_SELINUX_DEBUG configuration selinux: introduce and use lsm_ad_net_init*() helpers selinux: update my email address selinux: add missing newlines in pr_err() statements ...
2 parents 3ea67c4 + 1df83cb commit 1dbae18

34 files changed

Lines changed: 276 additions & 286 deletions

security/selinux/Kconfig

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22
config SECURITY_SELINUX
3-
bool "NSA SELinux Support"
3+
bool "SELinux Support"
44
depends on SECURITY_NETWORK && AUDIT && NET && INET
55
select NETWORK_SECMARK
66
default n
77
help
8-
This selects NSA Security-Enhanced Linux (SELinux).
8+
This selects Security-Enhanced Linux (SELinux).
99
You will also need a policy configuration and a labeled filesystem.
1010
If you are unsure how to answer this question, answer N.
1111

1212
config SECURITY_SELINUX_BOOTPARAM
13-
bool "NSA SELinux boot parameter"
13+
bool "SELinux boot parameter"
1414
depends on SECURITY_SELINUX
1515
default n
1616
help
@@ -24,11 +24,11 @@ config SECURITY_SELINUX_BOOTPARAM
2424
If you are unsure how to answer this question, answer N.
2525

2626
config SECURITY_SELINUX_DEVELOP
27-
bool "NSA SELinux Development Support"
27+
bool "SELinux Development Support"
2828
depends on SECURITY_SELINUX
2929
default y
3030
help
31-
This enables the development support option of NSA SELinux,
31+
This enables the development support option of SELinux,
3232
which is useful for experimenting with SELinux and developing
3333
policies. If unsure, say Y. With this option enabled, the
3434
kernel will start in permissive mode (log everything, deny nothing)
@@ -38,7 +38,7 @@ config SECURITY_SELINUX_DEVELOP
3838
/sys/fs/selinux/enforce.
3939

4040
config SECURITY_SELINUX_AVC_STATS
41-
bool "NSA SELinux AVC Statistics"
41+
bool "SELinux AVC Statistics"
4242
depends on SECURITY_SELINUX
4343
default y
4444
help
@@ -47,7 +47,7 @@ config SECURITY_SELINUX_AVC_STATS
4747
tools such as avcstat.
4848

4949
config SECURITY_SELINUX_SIDTAB_HASH_BITS
50-
int "NSA SELinux sidtab hashtable size"
50+
int "SELinux sidtab hashtable size"
5151
depends on SECURITY_SELINUX
5252
range 8 13
5353
default 9
@@ -59,7 +59,7 @@ config SECURITY_SELINUX_SIDTAB_HASH_BITS
5959
will ensure that lookups times are short and stable.
6060

6161
config SECURITY_SELINUX_SID2STR_CACHE_SIZE
62-
int "NSA SELinux SID to context string translation cache size"
62+
int "SELinux SID to context string translation cache size"
6363
depends on SECURITY_SELINUX
6464
default 256
6565
help
@@ -68,3 +68,12 @@ config SECURITY_SELINUX_SID2STR_CACHE_SIZE
6868
conversion. Setting this option to 0 disables the cache completely.
6969

7070
If unsure, keep the default value.
71+
72+
config SECURITY_SELINUX_DEBUG
73+
bool "SELinux kernel debugging support"
74+
depends on SECURITY_SELINUX
75+
default n
76+
help
77+
This enables debugging code designed to help SELinux kernel
78+
developers, unless you know what this does in the kernel code you
79+
should leave this disabled.

security/selinux/avc.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*
33
* Implementation of the kernel access vector cache (AVC).
44
*
5-
* Authors: Stephen Smalley, <sds@tycho.nsa.gov>
5+
* Authors: Stephen Smalley, <stephen.smalley.work@gmail.com>
66
* James Morris <jmorris@redhat.com>
77
*
88
* Update: KaiGai, Kohei <kaigai@ak.jp.nec.com>
@@ -122,7 +122,7 @@ static struct kmem_cache *avc_xperms_data_cachep __ro_after_init;
122122
static struct kmem_cache *avc_xperms_decision_cachep __ro_after_init;
123123
static struct kmem_cache *avc_xperms_cachep __ro_after_init;
124124

125-
static inline int avc_hash(u32 ssid, u32 tsid, u16 tclass)
125+
static inline u32 avc_hash(u32 ssid, u32 tsid, u16 tclass)
126126
{
127127
return (ssid ^ (tsid<<2) ^ (tclass<<4)) & (AVC_CACHE_SLOTS - 1);
128128
}
@@ -523,7 +523,7 @@ static void avc_node_populate(struct avc_node *node, u32 ssid, u32 tsid, u16 tcl
523523
static inline struct avc_node *avc_search_node(u32 ssid, u32 tsid, u16 tclass)
524524
{
525525
struct avc_node *node, *ret = NULL;
526-
int hvalue;
526+
u32 hvalue;
527527
struct hlist_head *head;
528528

529529
hvalue = avc_hash(ssid, tsid, tclass);
@@ -566,7 +566,7 @@ static struct avc_node *avc_lookup(u32 ssid, u32 tsid, u16 tclass)
566566
return NULL;
567567
}
568568

569-
static int avc_latest_notif_update(int seqno, int is_insert)
569+
static int avc_latest_notif_update(u32 seqno, int is_insert)
570570
{
571571
int ret = 0;
572572
static DEFINE_SPINLOCK(notif_lock);
@@ -609,7 +609,7 @@ static void avc_insert(u32 ssid, u32 tsid, u16 tclass,
609609
struct av_decision *avd, struct avc_xperms_node *xp_node)
610610
{
611611
struct avc_node *pos, *node = NULL;
612-
int hvalue;
612+
u32 hvalue;
613613
unsigned long flag;
614614
spinlock_t *lock;
615615
struct hlist_head *head;
@@ -654,9 +654,9 @@ static void avc_audit_pre_callback(struct audit_buffer *ab, void *a)
654654
{
655655
struct common_audit_data *ad = a;
656656
struct selinux_audit_data *sad = ad->selinux_audit_data;
657-
u32 av = sad->audited;
657+
u32 av = sad->audited, perm;
658658
const char *const *perms;
659-
int i, perm;
659+
u32 i;
660660

661661
audit_log_format(ab, "avc: %s ", sad->denied ? "denied" : "granted");
662662

@@ -833,7 +833,8 @@ static int avc_update_node(u32 event, u32 perms, u8 driver, u8 xperm, u32 ssid,
833833
struct extended_perms_decision *xpd,
834834
u32 flags)
835835
{
836-
int hvalue, rc = 0;
836+
u32 hvalue;
837+
int rc = 0;
837838
unsigned long flag;
838839
struct avc_node *pos, *node, *orig = NULL;
839840
struct hlist_head *head;

0 commit comments

Comments
 (0)