Skip to content

Commit 8a6f83a

Browse files
KaiGai Koheixjamesmorris
authored andcommitted
Permissive domain in userspace object manager
This patch enables applications to handle permissive domain correctly. Since the v2.6.26 kernel, SELinux has supported an idea of permissive domain which allows certain processes to work as if permissive mode, even if the global setting is enforcing mode. However, we don't have an application program interface to inform what domains are permissive one, and what domains are not. It means applications focuses on SELinux (XACE/SELinux, SE-PostgreSQL and so on) cannot handle permissive domain correctly. This patch add the sixth field (flags) on the reply of the /selinux/access interface which is used to make an access control decision from userspace. If the first bit of the flags field is positive, it means the required access control decision is on permissive domain, so application should allow any required actions, as the kernel doing. This patch also has a side benefit. The av_decision.flags is set at context_struct_compute_av(). It enables to check required permissions without read_lock(&policy_rwlock). Signed-off-by: KaiGai Kohei <kaigai@ak.jp.nec.com> Acked-by: Stephen Smalley <sds@tycho.nsa.gov> Acked-by: Eric Paris <eparis@redhat.com> -- security/selinux/avc.c | 2 +- security/selinux/include/security.h | 4 +++- security/selinux/selinuxfs.c | 4 ++-- security/selinux/ss/services.c | 30 +++++------------------------- 4 files changed, 11 insertions(+), 29 deletions(-) Signed-off-by: James Morris <jmorris@namei.org>
1 parent c31f403 commit 8a6f83a

4 files changed

Lines changed: 11 additions & 29 deletions

File tree

‎security/selinux/avc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,
927927
if (denied) {
928928
if (flags & AVC_STRICT)
929929
rc = -EACCES;
930-
else if (!selinux_enforcing || security_permissive_sid(ssid))
930+
else if (!selinux_enforcing || (avd->flags & AVD_FLAGS_PERMISSIVE))
931931
avc_update_node(AVC_CALLBACK_GRANT, requested, ssid,
932932
tsid, tclass, avd->seqno);
933933
else

‎security/selinux/include/security.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,11 @@ struct av_decision {
9191
u32 auditallow;
9292
u32 auditdeny;
9393
u32 seqno;
94+
u32 flags;
9495
};
9596

96-
int security_permissive_sid(u32 sid);
97+
/* definitions of av_decision.flags */
98+
#define AVD_FLAGS_PERMISSIVE 0x0001
9799

98100
int security_compute_av(u32 ssid, u32 tsid,
99101
u16 tclass, u32 requested,

‎security/selinux/selinuxfs.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,10 +527,10 @@ static ssize_t sel_write_access(struct file *file, char *buf, size_t size)
527527
goto out2;
528528

529529
length = scnprintf(buf, SIMPLE_TRANSACTION_LIMIT,
530-
"%x %x %x %x %u",
530+
"%x %x %x %x %u %x",
531531
avd.allowed, 0xffffffff,
532532
avd.auditallow, avd.auditdeny,
533-
avd.seqno);
533+
avd.seqno, avd.flags);
534534
out2:
535535
kfree(tcon);
536536
out:

‎security/selinux/ss/services.c‎

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ static int context_struct_compute_av(struct context *scontext,
410410
avd->auditallow = 0;
411411
avd->auditdeny = 0xffffffff;
412412
avd->seqno = latest_granting;
413+
avd->flags = 0;
413414

414415
/*
415416
* Check for all the invalid cases.
@@ -528,31 +529,6 @@ static int context_struct_compute_av(struct context *scontext,
528529
return 0;
529530
}
530531

531-
/*
532-
* Given a sid find if the type has the permissive flag set
533-
*/
534-
int security_permissive_sid(u32 sid)
535-
{
536-
struct context *context;
537-
u32 type;
538-
int rc;
539-
540-
read_lock(&policy_rwlock);
541-
542-
context = sidtab_search(&sidtab, sid);
543-
BUG_ON(!context);
544-
545-
type = context->type;
546-
/*
547-
* we are intentionally using type here, not type-1, the 0th bit may
548-
* someday indicate that we are globally setting permissive in policy.
549-
*/
550-
rc = ebitmap_get_bit(&policydb.permissive_map, type);
551-
552-
read_unlock(&policy_rwlock);
553-
return rc;
554-
}
555-
556532
static int security_validtrans_handle_fail(struct context *ocontext,
557533
struct context *ncontext,
558534
struct context *tcontext,
@@ -767,6 +743,10 @@ int security_compute_av(u32 ssid,
767743

768744
rc = context_struct_compute_av(scontext, tcontext, tclass,
769745
requested, avd);
746+
747+
/* permissive domain? */
748+
if (ebitmap_get_bit(&policydb.permissive_map, scontext->type))
749+
avd->flags |= AVD_FLAGS_PERMISSIVE;
770750
out:
771751
read_unlock(&policy_rwlock);
772752
return rc;

0 commit comments

Comments
 (0)