Skip to content

Commit

Permalink
xsm: add device tree labeling support
Browse files Browse the repository at this point in the history
This adds support in the hypervisor and policy build toolchain for
Xen/Flask policy version 30, which adds the ability to label ARM device
tree nodes and expands the IOMEM ocontext entries to 64 bits.

Signed-off-by: Daniel De Graaf <[email protected]>
Tested-by: Julien Grall <[email protected]>
Acked-by: Ian Campbell <[email protected]>
  • Loading branch information
dgdegraaf authored and jbeulich committed Mar 17, 2015
1 parent 55d8c9c commit 525ee49
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 42 deletions.
20 changes: 14 additions & 6 deletions tools/flask/policy/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ MLS_CATS ?= 256
CHECKPOLICY ?= checkpolicy
M4 ?= m4

# Output security policy version. Leave unset to autodetect.
OUTPUT_POLICY ?= $(BEST_POLICY_VER)

########################################
#
# End of configuration options
#
########################################

# Policy version
# By default, checkpolicy creates the highest version policy it supports. Force
# the use of version 24 which is the highest that Xen supports, and the first to
# include the Xen policy type (needed for static device policy).
OUTPUT_POLICY = 24

POLICY_FILENAME = xenpolicy-$(shell $(MAKE) -C $(XEN_ROOT)/xen xenversion --no-print-directory)
POLICY_LOADPATH = /boot

# List of policy versions supported by the hypervisor
POLICY_VER_LIST_HV = 24 30

# policy source layout
POLDIR := policy
MODDIR := $(POLDIR)/modules
Expand Down Expand Up @@ -63,6 +63,14 @@ MOD_CONF := $(POLDIR)/modules.conf

# checkpolicy can use the #line directives provided by -s for error reporting:
M4PARAM := -D self_contained_policy -s

# The output of checkpolicy -V is "30 (compatibility range 30-15)", and the
# first word of the output is the maximum policy version supported.
CHECKPOLICY_VER_MAX := $(firstword $(shell $(CHECKPOLICY) -V))

# Find the highest version supported by both the hypervisor and checkpolicy
BEST_POLICY_VER := $(shell best=24; for ver in $(POLICY_VER_LIST_HV); do if test $$ver -le $(CHECKPOLICY_VER_MAX); then best=$$ver; fi; done; echo $$best)

CHECKPOLICY_PARAM := -t Xen -c $(OUTPUT_POLICY)

# enable MLS if requested.
Expand Down
9 changes: 9 additions & 0 deletions xen/include/public/xsm/flask_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ struct xen_flask_relabel {
uint32_t sid;
};

struct xen_flask_devicetree_label {
/* IN */
uint32_t sid;
uint32_t length;
XEN_GUEST_HANDLE(char) path;
};

struct xen_flask_op {
uint32_t cmd;
#define FLASK_LOAD 1
Expand All @@ -176,6 +183,7 @@ struct xen_flask_op {
#define FLASK_DEL_OCONTEXT 22
#define FLASK_GET_PEER_SID 23
#define FLASK_RELABEL_DOMAIN 24
#define FLASK_DEVICETREE_LABEL 25
uint32_t interface_version; /* XEN_FLASK_INTERFACE_VERSION */
union {
struct xen_flask_load load;
Expand All @@ -195,6 +203,7 @@ struct xen_flask_op {
struct xen_flask_ocontext ocontext;
struct xen_flask_peersid peersid;
struct xen_flask_relabel relabel;
struct xen_flask_devicetree_label devicetree_label;
} u;
};
typedef struct xen_flask_op xen_flask_op_t;
Expand Down
28 changes: 28 additions & 0 deletions xen/xsm/flask/flask_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,27 @@ static int flask_security_load(struct xen_flask_load *load)
return ret;
}

static int flask_devicetree_label(struct xen_flask_devicetree_label *arg)
{
int rv;
char *buf;
u32 sid = arg->sid;
u32 perm = sid ? SECURITY__ADD_OCONTEXT : SECURITY__DEL_OCONTEXT;

rv = domain_has_security(current->domain, perm);
if ( rv )
return rv;

rv = flask_copyin_string(arg->path, &buf, arg->length, PAGE_SIZE);
if ( rv )
return rv;

/* buf is consumed or freed by this function */
rv = security_devicetree_setlabel(buf, sid);

return rv;
}

#ifndef COMPAT

static int flask_ocontext_del(struct xen_flask_ocontext *arg)
Expand Down Expand Up @@ -790,6 +811,10 @@ ret_t do_flask_op(XEN_GUEST_HANDLE_PARAM(xsm_op_t) u_flask_op)
rv = flask_relabel_domain(&op.u.relabel);
break;

case FLASK_DEVICETREE_LABEL:
rv = flask_devicetree_label(&op.u.devicetree_label);
break;

default:
rv = -ENOSYS;
}
Expand Down Expand Up @@ -848,6 +873,9 @@ CHECK_flask_transition;
#define flask_security_get_bool compat_security_get_bool
#define flask_security_set_bool compat_security_set_bool

#define xen_flask_devicetree_label compat_flask_devicetree_label
#define flask_devicetree_label compat_devicetree_label

#define xen_flask_op_t compat_flask_op_t
#undef ret_t
#define ret_t int
Expand Down
14 changes: 12 additions & 2 deletions xen/xsm/flask/include/security.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@
#define POLICYDB_VERSION_POLCAP 22
#define POLICYDB_VERSION_PERMISSIVE 23
#define POLICYDB_VERSION_BOUNDARY 24
#define POLICYDB_VERSION_FILENAME_TRANS 25
#define POLICYDB_VERSION_ROLETRANS 26
#define POLICYDB_VERSION_NEW_OBJECT_DEFAULTS 27
#define POLICYDB_VERSION_DEFAULT_TYPE 28
#define POLICYDB_VERSION_CONSTRAINT_NAMES 29
#define POLICYDB_VERSION_XEN_DEVICETREE 30

/* Range of policy versions we understand*/
#define POLICYDB_VERSION_MIN POLICYDB_VERSION_BASE
#define POLICYDB_VERSION_MAX POLICYDB_VERSION_BOUNDARY
#define POLICYDB_VERSION_MAX POLICYDB_VERSION_XEN_DEVICETREE

enum flask_bootparam_t {
FLASK_BOOTPARAM_PERMISSIVE,
Expand Down Expand Up @@ -82,6 +88,8 @@ int security_ioport_sid(u32 ioport, u32 *out_sid);

int security_device_sid(u32 device, u32 *out_sid);

int security_devicetree_sid(const char *path, u32 *out_sid);

int security_validate_transition(u32 oldsid, u32 newsid, u32 tasksid,
u16 tclass);

Expand All @@ -96,5 +104,7 @@ int security_iterate_ioport_sids(u32 start, u32 end,
int security_ocontext_add(u32 ocontext, unsigned long low,
unsigned long high, u32 sid);

int security_ocontext_del(u32 ocontext, unsigned int low, unsigned int high);
int security_ocontext_del(u32 ocontext, unsigned long low, unsigned long high);

int security_devicetree_setlabel(char *path, u32 sid);
#endif /* _FLASK_SECURITY_H_ */
Loading

0 comments on commit 525ee49

Please sign in to comment.