From 12f17f0022784a7b57aa355dc8c4e5c8d4b9a99d Mon Sep 17 00:00:00 2001 From: Richard Haines Date: Fri, 20 Mar 2015 14:18:31 +0000 Subject: [PATCH] libsepol: Fix reading Xen policy with devicetreecon Policy failed to read with devicetreecon statement. Added devicetreecon statement to CIL policy.cil and updated the CIL Reference Guide. Signed-off-by: Richard Haines --- libsepol/cil/docs/cil_xen_statements.xml | 44 ++++++++++++++++++++++++++++++++ libsepol/cil/test/policy.cil | 1 + libsepol/src/policydb.c | 4 ++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/libsepol/cil/docs/cil_xen_statements.xml b/libsepol/cil/docs/cil_xen_statements.xml index 1035b68..45865c6 100644 --- a/libsepol/cil/docs/cil_xen_statements.xml +++ b/libsepol/cil/docs/cil_xen_statements.xml @@ -3,6 +3,7 @@ Xen Statements + Policy version 30 introduced the context statement and also expanded the existing I/O memory range to 64 bits in order to support hardware with more than 44 bits of physical address space (32-bit count of 4K pages). See the "XSM/FLASK Configuration" document for further information () iomemcon @@ -180,4 +181,47 @@ + + devicetreecon + Label device tree nodes. + Statement definition: + + Where: + + + + + + + + devicetreecon + + + The devicetreecon keyword. + + + + + path + + + The device tree path. If this contains spaces enclose within "". + + + + + context_id + + + A previously declared context identifier or an anonymous security context (user role type levelrange), the range MUST be defined whether the policy is MLS/MCS enabled or not. + + + + + + Example: + An anonymous context for the specified path: + + + diff --git a/libsepol/cil/test/policy.cil b/libsepol/cil/test/policy.cil index 9c76cad..25c8545 100644 --- a/libsepol/cil/test/policy.cil +++ b/libsepol/cil/test/policy.cil @@ -250,6 +250,7 @@ (iomemcon (0 255) system_u_bin_t_l2h) (ioportcon (22 22) system_u_bin_t_l2h) (pcidevicecon 345 system_u_bin_t_l2h) + (devicetreecon "/this is/a/path" system_u_bin_t_l2h) (constrain (files (read)) (not (or (and (eq t1 exec_t) (eq t2 bin_t)) (eq r1 r2)))) (constrain char_w (not (or (and (eq t1 exec_t) (eq t2 bin_t)) (eq r1 r2)))) diff --git a/libsepol/src/policydb.c b/libsepol/src/policydb.c index b45b662..ceac33d 100644 --- a/libsepol/src/policydb.c +++ b/libsepol/src/policydb.c @@ -2559,11 +2559,13 @@ static int ocontext_read_xen(struct policydb_compat_info *info, rc = next_entry(buf, fp, sizeof(uint32_t)); if (rc < 0) return -1; - len = le32_to_cpu(buf[1]); + len = le32_to_cpu(buf[0]); c->u.name = malloc(len + 1); if (!c->u.name) return -1; rc = next_entry(c->u.name, fp, len); + if (rc < 0) + return -1; c->u.name[len] = 0; if (context_read_and_validate (&c->context[0], p, fp)) -- 2.1.0