Skip to content

Commit 817199e

Browse files
committed
selinux: revert SECINITSID_INIT support
This commit reverts 5b0eea8 ("selinux: introduce an initial SID for early boot processes") as it was found to cause problems on distros with old SELinux userspace tools/libraries, specifically Ubuntu 16.04. Hopefully we will be able to re-add this functionality at a later date, but let's revert this for now to help ensure a stable and backwards compatible SELinux tree. Link: https://lore.kernel.org/selinux/87edkseqf8.fsf@mail.lhotse Acked-by: Ondrej Mosnacek <omosnace@redhat.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 2b86e04 commit 817199e

6 files changed

Lines changed: 1 addition & 64 deletions

File tree

security/selinux/hooks.c

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,19 +2313,6 @@ 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-
23292316
if (old_tsec->exec_sid) {
23302317
new_tsec->sid = old_tsec->exec_sid;
23312318
/* Reset exec SID on execve. */
@@ -4542,21 +4529,6 @@ static int sock_has_perm(struct sock *sk, u32 perms)
45424529
if (sksec->sid == SECINITSID_KERNEL)
45434530
return 0;
45444531

4545-
/*
4546-
* Before POLICYDB_CAP_USERSPACE_INITIAL_CONTEXT, sockets that
4547-
* inherited the kernel context from early boot used to be skipped
4548-
* here, so preserve that behavior unless the capability is set.
4549-
*
4550-
* By setting the capability the policy signals that it is ready
4551-
* for this quirk to be fixed. Note that sockets created by a kernel
4552-
* thread or a usermode helper executed without a transition will
4553-
* still be skipped in this check regardless of the policycap
4554-
* setting.
4555-
*/
4556-
if (!selinux_policycap_userspace_initial_context() &&
4557-
sksec->sid == SECINITSID_INIT)
4558-
return 0;
4559-
45604532
ad_net_init_from_sk(&ad, &net, sk);
45614533

45624534
return avc_has_perm(current_sid(), sksec->sid, sksec->sclass, perms,

security/selinux/include/initial_sid_to_string.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ static const char *const initial_sid_to_string[] = {
1010
NULL,
1111
"file",
1212
NULL,
13-
"init",
13+
NULL,
1414
"any_socket",
1515
"port",
1616
"netif",

security/selinux/include/policycap.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ enum {
1212
POLICYDB_CAP_NNP_NOSUID_TRANSITION,
1313
POLICYDB_CAP_GENFS_SECLABEL_SYMLINKS,
1414
POLICYDB_CAP_IOCTL_SKIP_CLOEXEC,
15-
POLICYDB_CAP_USERSPACE_INITIAL_CONTEXT,
1615
__POLICYDB_CAP_MAX
1716
};
1817
#define POLICYDB_CAP_MAX (__POLICYDB_CAP_MAX - 1)

security/selinux/include/policycap_names.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const char *const selinux_policycap_names[__POLICYDB_CAP_MAX] = {
1414
"nnp_nosuid_transition",
1515
"genfs_seclabel_symlinks",
1616
"ioctl_skip_cloexec",
17-
"userspace_initial_context",
1817
};
1918

2019
#endif /* _SELINUX_POLICYCAP_NAMES_H_ */

security/selinux/include/security.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,6 @@ static inline bool selinux_policycap_ioctl_skip_cloexec(void)
189189
selinux_state.policycap[POLICYDB_CAP_IOCTL_SKIP_CLOEXEC]);
190190
}
191191

192-
static inline bool selinux_policycap_userspace_initial_context(void)
193-
{
194-
return READ_ONCE(
195-
selinux_state.policycap[POLICYDB_CAP_USERSPACE_INITIAL_CONTEXT]);
196-
}
197-
198192
struct selinux_policy_convert_data;
199193

200194
struct selinux_load_state {

security/selinux/ss/policydb.c

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -864,8 +864,6 @@ void policydb_destroy(struct policydb *p)
864864
int policydb_load_isids(struct policydb *p, struct sidtab *s)
865865
{
866866
struct ocontext *head, *c;
867-
bool isid_init_supported = ebitmap_get_bit(&p->policycaps,
868-
POLICYDB_CAP_USERSPACE_INITIAL_CONTEXT);
869867
int rc;
870868

871869
rc = sidtab_init(s);
@@ -889,38 +887,13 @@ int policydb_load_isids(struct policydb *p, struct sidtab *s)
889887
if (!name)
890888
continue;
891889

892-
/*
893-
* Also ignore SECINITSID_INIT if the policy doesn't declare
894-
* support for it
895-
*/
896-
if (sid == SECINITSID_INIT && !isid_init_supported)
897-
continue;
898-
899890
rc = sidtab_set_initial(s, sid, &c->context[0]);
900891
if (rc) {
901892
pr_err("SELinux: unable to load initial SID %s.\n",
902893
name);
903894
sidtab_destroy(s);
904895
return rc;
905896
}
906-
907-
/*
908-
* If the policy doesn't support the "userspace_initial_context"
909-
* capability, set SECINITSID_INIT to the same context as
910-
* SECINITSID_KERNEL. This ensures the same behavior as before
911-
* the reintroduction of SECINITSID_INIT, where all tasks
912-
* started before policy load would initially get the context
913-
* corresponding to SECINITSID_KERNEL.
914-
*/
915-
if (sid == SECINITSID_KERNEL && !isid_init_supported) {
916-
rc = sidtab_set_initial(s, SECINITSID_INIT, &c->context[0]);
917-
if (rc) {
918-
pr_err("SELinux: unable to load initial SID %s.\n",
919-
name);
920-
sidtab_destroy(s);
921-
return rc;
922-
}
923-
}
924897
}
925898
return 0;
926899
}

0 commit comments

Comments
 (0)