selinux: introduce unconfined as a first class concept
Stephen Smalley
maintainerRFC PATCH 1/1 selinux: introduce unconfined as a first class concept
Introduce unconfined as a first class concept to SELinux. Previously, SELinux had no such concept and unconfined domains were solely defined by policy.
Advantages of elevating to a first class concept:
1. Explicit allow rules for unconfined domains can be omitted, shrinking the policy.
2. The kernel can leverage this knowledge to further optimize checking on unconfined processes.
Disadvantages:
1. Yet another juicy target for exploit writers, similar to permissive types.
2. Requires a new policy version/format and bitmap.
This change just introduces the basic support but does not yet leverage it to optimize the AVC or hook function logic.
--- security/selinux/include/security.h | 4 +++- security/selinux/ss/policydb.c | 19 +++++++++++++++++++ security/selinux/ss/policydb.h | 2 ++ security/selinux/ss/services.c | 12 ++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-)
security/selinux/include/security.h +3 -1
@@ -47,10 +47,11 @@#define POLICYDB_VERSION_GLBLUB 32#define POLICYDB_VERSION_COMP_FTRANS 33/* compressed filename transitions */ #define POLICYDB_VERSION_COND_XPERMS 34/* extended permissions in conditional policies */ +#define POLICYDB_VERSION_UNCONFINED 35/* unconfined types */ /* Range of policy versions we understand*/ #define POLICYDB_VERSION_MIN POLICYDB_VERSION_BASE -#define POLICYDB_VERSION_MAX POLICYDB_VERSION_COND_XPERMS +#define POLICYDB_VERSION_MAX POLICYDB_VERSION_UNCONFINED/* Mask for just the mount related flags */ #define SE_MNTMASK 0x0f
@@ -260,6 +261,7 @@ struct extended_perms {/* definitions of av_decision.flags */ #define AVD_FLAGS_PERMISSIVE 0x0001 +#define AVD_FLAGS_UNCONFINED 0x0002 void security_compute_av(u32 ssid, u32 tsid, u16 tclass, struct av_decision *avd,
security/selinux/ss/policydb.c +19 -0
@@ -160,6 +160,11 @@ static const struct policydb_compat_info policydb_compat[] = { .sym_num = SYM_NUM, .ocon_num = OCON_NUM, }, + { + .version = POLICYDB_VERSION_UNCONFINED, + .sym_num = SYM_NUM, + .ocon_num = OCON_NUM, + }, }; static const struct policydb_compat_info *
@@ -531,6 +536,7 @@ static void policydb_init(struct policydb *p)ebitmap_init (&p->filename_trans_ttypes);ebitmap_init (&p->policycaps);ebitmap_init (&p->permissive_map); +ebitmap_init (&p->unconfined_map); }/*
@@ -852,6 +858,7 @@ void policydb_destroy(struct policydb *p)ebitmap_destroy (&p->filename_trans_ttypes);ebitmap_destroy (&p->policycaps);ebitmap_destroy (&p->permissive_map); +ebitmap_destroy (&p->unconfined_map); }/*
@@ -2538,6 +2545,12 @@ int policydb_read(struct policydb *p, struct policy_file *fp) goto bad; } +if (p->policyvers >=POLICYDB_VERSION_UNCONFINED ) { + rc =ebitmap_read (&p->unconfined_map, fp); +if (rc) + goto bad; + } + rc = -EINVAL ; info =policydb_lookup_compat (p->policyvers);if (!info) {
@@ -3723,6 +3736,12 @@ int policydb_write(struct policydb *p, struct policy_file *fp)return rc; } +if (p->policyvers >=POLICYDB_VERSION_UNCONFINED ) { + rc =ebitmap_write (&p->unconfined_map, fp); +if (rc) +return rc; + } + num_syms = info->sym_num;for (i =0 ; i < num_syms; i++) {struct policy_data pd;
security/selinux/ss/policydb.h +2 -0
@@ -300,6 +300,8 @@ struct policydb {struct ebitmap permissive_map; +struct ebitmap unconfined_map; +/* length of this policy when it was loaded */ size_t len;
security/selinux/ss/services.c +12 -0
@@ -1153,6 +1153,12 @@ void security_compute_av(u32 ssid,if (ebitmap_get_bit (&policydb->permissive_map, scontext->type)) avd->flags |=AVD_FLAGS_PERMISSIVE ; +/* unconfined domain? */ +if (ebitmap_get_bit (&policydb->unconfined_map, scontext->type)) { + avd->flags |=AVD_FLAGS_UNCONFINED ; + goto allow; + } + tcontext =sidtab_search (sidtab, tsid);if (!tcontext) { pr_err("SELinux: %s: unrecognized SID %d\n",
@@ -1208,6 +1214,12 @@ void security_compute_av_user(u32 ssid,if (ebitmap_get_bit (&policydb->permissive_map, scontext->type)) avd->flags |=AVD_FLAGS_PERMISSIVE ; +/* unconfined domain? */ +if (ebitmap_get_bit (&policydb->unconfined_map, scontext->type)) { + avd->flags |=AVD_FLAGS_UNCONFINED ; + goto allow; + } + tcontext =sidtab_search (sidtab, tsid);if (!tcontext) { pr_err("SELinux: %s: unrecognized SID %d\n",
Signature · 1 line
2.49.0
Paul Moore
maintainerQuoted 21 lines · Stephen Smalley
Introduce unconfined as a first class concept to SELinux. Previously, SELinux had no such concept and unconfined domains were solely defined by policy.
Advantages of elevating to a first class concept:
1. Explicit allow rules for unconfined domains can be omitted, shrinking the policy.
2. The kernel can leverage this knowledge to further optimize checking on unconfined processes.Disadvantages:
1. Yet another juicy target for exploit writers, similar to permissive types.
2. Requires a new policy version/format and bitmap.This change just introduces the basic support but does not yet leverage it to optimize the AVC or hook function logic.
Quoted 7 lines
Signed-off-by Stephen Smalley <[email protected]>--- security/selinux/include/security.h | 4 +++- security/selinux/ss/policydb.c | 19 +++++++++++++++++++ security/selinux/ss/policydb.h | 2 ++ security/selinux/ss/services.c | 12 ++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-)
Maybe I'll warm up to this idea, but my first reaction is not positive, I really don't like the idea of special domains with an inherent set of policy rules. Yes, we can mark individual domains as permissive, which I realize at a high enough level it looks very similar, but to me the important distinction is that marking a domain as permissive does not imply a set of policy rules, it simply ignores any denials. A minor difference, but one that I think is important.
I want to think on this some more.
I'd probably be a bit more open to the idea of a AVD_FLAGS_DONTAUDIT flag that could be used in conjunction with the _PERMISSIVE flag to both ignore the policy access decision and squelch any resulting audit events (even the first one). Admittedly, that likely wouldn't present quite as many possibilities for future kernel optimizations as the _UNCONFINED flag.
Signature · 1 line
paul-moore.com
Paul Moore
maintainerQuoted 3 lines · Paul Moore
... Admittedly, that likely wouldn't present
quite as many possibilities for future kernel optimizations as the_UNCONFINEDflag.
Now that I'm thinking a bit more about it, maybe it would allow for the same types of optimizations? One could simply treat AVD_FLAGS_PERMISSIVE|AVD_FLAGS_DONTAUDIT the same as we would an _UNCONFINED flag ... I think.
Signature · 1 line
paul-moore.com
Stephen Smalley
maintainerQuoted 10 lines · Paul Moore
Quoted 3 lines · Paul Moore
... Admittedly, that likely wouldn't present
quite as many possibilities for future kernel optimizations as the_UNCONFINEDflag.Now that I'm thinking a bit more about it, maybe it would allow for the same types of optimizations? One could simply treat AVD_FLAGS_PERMISSIVE|AVD_FLAGS_DONTAUDIT the same as we would an
_UNCONFINEDflag ... I think.
I'm not sure that's quite correct. dontaudit suppresses auditing of permission denials, but otherwise still requires computing the full allowed+auditallow vectors during security_compute_av() and wouldn't normally be checked until avc_audit_required() in the AVC, long after we've already paid the cost of the avc_lookup() and/or security_compute_av(). If we made it a new "neveraudit" or similar construct that also disables auditallow, then we could possibly treat the combination of permissive|neveraudit as the same as unconfined types in this patch, although it seems less intuitive for users and means we have to check two different ebitmaps in security_compute_av(), or precompute an unconfined ebitmap at policy load time when a type is set in both ebitmaps. Is there an actual use case for such a neveraudit type _without_ also making it permissive? If not, then it's just wasted effort.