Skip to content

Commit 9f9310b

Browse files
committed
Merge tag 'selinux-pr-20240105' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux
Pull selinux updates from Paul Moore: - Add a new SELinux initial SID, SECINITSID_INIT, to represent userspace processes started before the SELinux policy is loaded in early boot. Prior to this patch all processes were marked as SECINITSID_KERNEL before the SELinux policy was loaded, making it difficult to distinquish early boot userspace processes from the kernel in the SELinux policy. For most users this will be a non-issue as the policy is loaded early enough during boot, but for users who load their SELinux policy relatively late, this should make it easier to construct meaningful security policies. - Cleanups to the selinuxfs code by Al, mostly on VFS related issues during a policy reload. The commit description has more detail, but the quick summary is that we are replacing a disconnected directory approach with a temporary directory that we swapover at the end of the reload. - Fix an issue where the input sanity checking on socket bind() operations was slightly different depending on the presence of SELinux. This is caused by the placement of the LSM hooks in the generic socket layer as opposed to the protocol specific bind() handler where the protocol specific sanity checks are performed. Mickaël has mentioned that he is working to fix this, but in the meantime we just ensure that we are replicating the checks properly. We need to balance the placement of the LSM hooks with the number of LSM hooks; pushing the hooks down into the protocol layers is likely not the right answer. - Update the avc_has_perm_noaudit() prototype to better match the function definition. - Migrate from using partial_name_hash() to full_name_hash() the filename transition hash table. This improves the quality of the code and has the potential for a minor performance bump. - Consolidate some open coded SELinux access vector comparisions into a single new function, avtab_node_cmp(), and use that instead. A small, but nice win for code quality and maintainability. - Updated the SELinux MAINTAINERS entry with additional information around process, bug reporting, etc. We're also updating some of our "official" roles: dropping Eric Paris and adding Ondrej as a reviewer. - Cleanup the coding style crimes in security/selinux/include. While I'm not a fan of code churn, I am pushing for more automated code checks that can be done at the developer level and one of the obvious things to check for is coding style. In an effort to start from a "good" base I'm slowly working through our source files cleaning them up with the help of clang-format and good ol' fashioned human eyeballs; this has the first batch of these changes. I've been splitting the changes up per-file to help reduce the impact if backports are required (either for LTS or distro kernels), and I expect the some of the larger files, e.g. hooks.c and ss/services.c, will likely need to be split even further. - Cleanup old, outdated comments. * tag 'selinux-pr-20240105' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux: (24 commits) selinux: Fix error priority for bind with AF_UNSPEC on PF_INET6 socket selinux: fix style issues in security/selinux/include/initial_sid_to_string.h selinux: fix style issues in security/selinux/include/xfrm.h selinux: fix style issues in security/selinux/include/security.h selinux: fix style issues with security/selinux/include/policycap_names.h selinux: fix style issues in security/selinux/include/policycap.h selinux: fix style issues in security/selinux/include/objsec.h selinux: fix style issues with security/selinux/include/netlabel.h selinux: fix style issues in security/selinux/include/netif.h selinux: fix style issues in security/selinux/include/ima.h selinux: fix style issues in security/selinux/include/conditional.h selinux: fix style issues in security/selinux/include/classmap.h selinux: fix style issues in security/selinux/include/avc_ss.h selinux: align avc_has_perm_noaudit() prototype with definition selinux: fix style issues in security/selinux/include/avc.h selinux: fix style issues in security/selinux/include/audit.h MAINTAINERS: drop Eric Paris from his SELinux role MAINTAINERS: add Ondrej Mosnacek as a SELinux reviewer selinux: remove the wrong comment about multithreaded process handling selinux: introduce an initial SID for early boot processes ...
2 parents eab23bc + bbf5a1d commit 9f9310b

20 files changed

+543
-603
lines changed

MAINTAINERS

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19465,12 +19465,14 @@ X: security/selinux/
1946519465
SELINUX SECURITY MODULE
1946619466
M: Paul Moore <paul@paul-moore.com>
1946719467
M: Stephen Smalley <stephen.smalley.work@gmail.com>
19468-
M: Eric Paris <eparis@parisplace.org>
19468+
R: Ondrej Mosnacek <omosnace@redhat.com>
1946919469
L: selinux@vger.kernel.org
1947019470
S: Supported
19471-
W: https://selinuxproject.org
1947219471
W: https://github.com/SELinuxProject
19473-
T: git git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux.git
19472+
Q: https://patchwork.kernel.org/project/selinux/list
19473+
B: mailto:selinux@vger.kernel.org
19474+
P: https://github.com/SELinuxProject/selinux-kernel/blob/main/README.md
19475+
T: git https://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux.git
1947419476
F: Documentation/ABI/removed/sysfs-selinux-checkreqprot
1947519477
F: Documentation/ABI/removed/sysfs-selinux-disable
1947619478
F: Documentation/admin-guide/LSM/SELinux.rst

security/selinux/hooks.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2313,6 +2313,19 @@ static int selinux_bprm_creds_for_exec(struct linux_binprm *bprm)
23132313
new_tsec->keycreate_sid = 0;
23142314
new_tsec->sockcreate_sid = 0;
23152315

2316+
/*
2317+
* Before policy is loaded, label any task outside kernel space
2318+
* as SECINITSID_INIT, so that any userspace tasks surviving from
2319+
* early boot end up with a label different from SECINITSID_KERNEL
2320+
* (if the policy chooses to set SECINITSID_INIT != SECINITSID_KERNEL).
2321+
*/
2322+
if (!selinux_initialized()) {
2323+
new_tsec->sid = SECINITSID_INIT;
2324+
/* also clear the exec_sid just in case */
2325+
new_tsec->exec_sid = 0;
2326+
return 0;
2327+
}
2328+
23162329
if (old_tsec->exec_sid) {
23172330
new_tsec->sid = old_tsec->exec_sid;
23182331
/* Reset exec SID on execve. */
@@ -4547,6 +4560,21 @@ static int sock_has_perm(struct sock *sk, u32 perms)
45474560
if (sksec->sid == SECINITSID_KERNEL)
45484561
return 0;
45494562

4563+
/*
4564+
* Before POLICYDB_CAP_USERSPACE_INITIAL_CONTEXT, sockets that
4565+
* inherited the kernel context from early boot used to be skipped
4566+
* here, so preserve that behavior unless the capability is set.
4567+
*
4568+
* By setting the capability the policy signals that it is ready
4569+
* for this quirk to be fixed. Note that sockets created by a kernel
4570+
* thread or a usermode helper executed without a transition will
4571+
* still be skipped in this check regardless of the policycap
4572+
* setting.
4573+
*/
4574+
if (!selinux_policycap_userspace_initial_context() &&
4575+
sksec->sid == SECINITSID_INIT)
4576+
return 0;
4577+
45504578
ad_net_init_from_sk(&ad, &net, sk);
45514579

45524580
return avc_has_perm(current_sid(), sksec->sid, sksec->sclass, perms,
@@ -4661,6 +4689,13 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
46614689
return -EINVAL;
46624690
addr4 = (struct sockaddr_in *)address;
46634691
if (family_sa == AF_UNSPEC) {
4692+
if (family == PF_INET6) {
4693+
/* Length check from inet6_bind_sk() */
4694+
if (addrlen < SIN6_LEN_RFC2133)
4695+
return -EINVAL;
4696+
/* Family check from __inet6_bind() */
4697+
goto err_af;
4698+
}
46644699
/* see __inet_bind(), we only want to allow
46654700
* AF_UNSPEC if the address is INADDR_ANY
46664701
*/
@@ -6425,7 +6460,6 @@ static int selinux_setprocattr(const char *name, void *value, size_t size)
64256460
if (sid == 0)
64266461
goto abort_change;
64276462

6428-
/* Only allow single threaded processes to change context */
64296463
if (!current_is_single_threaded()) {
64306464
error = security_bounded_transition(tsec->sid, sid);
64316465
if (error)

security/selinux/include/audit.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,3 @@ int selinux_audit_rule_match(u32 sid, u32 field, u32 op, void *rule);
5757
int selinux_audit_rule_known(struct audit_krule *rule);
5858

5959
#endif /* _SELINUX_AUDIT_H */
60-

security/selinux/include/avc.h

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
* Author : Stephen Smalley, <stephen.smalley.work@gmail.com>
66
*/
7+
78
#ifndef _SELINUX_AVC_H_
89
#define _SELINUX_AVC_H_
910

@@ -60,11 +61,8 @@ struct selinux_audit_data {
6061

6162
void __init avc_init(void);
6263

63-
static inline u32 avc_audit_required(u32 requested,
64-
struct av_decision *avd,
65-
int result,
66-
u32 auditdeny,
67-
u32 *deniedp)
64+
static inline u32 avc_audit_required(u32 requested, struct av_decision *avd,
65+
int result, u32 auditdeny, u32 *deniedp)
6866
{
6967
u32 denied, audited;
7068
denied = requested & ~avd->allowed;
@@ -96,9 +94,8 @@ static inline u32 avc_audit_required(u32 requested,
9694
return audited;
9795
}
9896

99-
int slow_avc_audit(u32 ssid, u32 tsid, u16 tclass,
100-
u32 requested, u32 audited, u32 denied, int result,
101-
struct common_audit_data *a);
97+
int slow_avc_audit(u32 ssid, u32 tsid, u16 tclass, u32 requested, u32 audited,
98+
u32 denied, int result, struct common_audit_data *a);
10299

103100
/**
104101
* avc_audit - Audit the granting or denial of permissions.
@@ -119,44 +116,37 @@ int slow_avc_audit(u32 ssid, u32 tsid, u16 tclass,
119116
* be performed under a lock, to allow the lock to be released
120117
* before calling the auditing code.
121118
*/
122-
static inline int avc_audit(u32 ssid, u32 tsid,
123-
u16 tclass, u32 requested,
124-
struct av_decision *avd,
125-
int result,
119+
static inline int avc_audit(u32 ssid, u32 tsid, u16 tclass, u32 requested,
120+
struct av_decision *avd, int result,
126121
struct common_audit_data *a)
127122
{
128123
u32 audited, denied;
129124
audited = avc_audit_required(requested, avd, result, 0, &denied);
130125
if (likely(!audited))
131126
return 0;
132-
return slow_avc_audit(ssid, tsid, tclass,
133-
requested, audited, denied, result,
134-
a);
127+
return slow_avc_audit(ssid, tsid, tclass, requested, audited, denied,
128+
result, a);
135129
}
136130

137-
#define AVC_STRICT 1 /* Ignore permissive mode. */
138-
#define AVC_EXTENDED_PERMS 2 /* update extended permissions */
139-
int avc_has_perm_noaudit(u32 ssid, u32 tsid,
140-
u16 tclass, u32 requested,
141-
unsigned flags,
142-
struct av_decision *avd);
131+
#define AVC_STRICT 1 /* Ignore permissive mode. */
132+
#define AVC_EXTENDED_PERMS 2 /* update extended permissions */
133+
int avc_has_perm_noaudit(u32 ssid, u32 tsid, u16 tclass, u32 requested,
134+
unsigned int flags, struct av_decision *avd);
143135

144-
int avc_has_perm(u32 ssid, u32 tsid,
145-
u16 tclass, u32 requested,
136+
int avc_has_perm(u32 ssid, u32 tsid, u16 tclass, u32 requested,
146137
struct common_audit_data *auditdata);
147138

148139
int avc_has_extended_perms(u32 ssid, u32 tsid, u16 tclass, u32 requested,
149140
u8 driver, u8 perm, struct common_audit_data *ad);
150141

151-
152142
u32 avc_policy_seqno(void);
153143

154144
#define AVC_CALLBACK_GRANT 1
155145
#define AVC_CALLBACK_TRY_REVOKE 2
156146
#define AVC_CALLBACK_REVOKE 4
157147
#define AVC_CALLBACK_RESET 8
158148
#define AVC_CALLBACK_AUDITALLOW_ENABLE 16
159-
#define AVC_CALLBACK_AUDITALLOW_DISABLE 32
149+
#define AVC_CALLBACK_AUDITALLOW_DISABLE 32
160150
#define AVC_CALLBACK_AUDITDENY_ENABLE 64
161151
#define AVC_CALLBACK_AUDITDENY_DISABLE 128
162152
#define AVC_CALLBACK_ADD_XPERMS 256
@@ -173,4 +163,3 @@ DECLARE_PER_CPU(struct avc_cache_stats, avc_cache_stats);
173163
#endif
174164

175165
#endif /* _SELINUX_AVC_H_ */
176-

security/selinux/include/avc_ss.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
* Author : Stephen Smalley, <stephen.smalley.work@gmail.com>
66
*/
7+
78
#ifndef _SELINUX_AVC_SS_H_
89
#define _SELINUX_AVC_SS_H_
910

@@ -20,4 +21,3 @@ struct security_class_mapping {
2021
extern const struct security_class_mapping secclass_map[];
2122

2223
#endif /* _SELINUX_AVC_SS_H_ */
23-

0 commit comments

Comments
 (0)