mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 10:11:27 +01:00
tmem: add XSM hooks
This adds a pair of XSM hooks for tmem operations: xsm_tmem_op which controls any use of tmem, and xsm_tmem_control which allows use of the TMEM_CONTROL operations. By default, all domains can use tmem while only IS_PRIV domains can use control operations. Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov> Acked-by: Dan Magenheimer <dan.magenheimer@oracle.com> Committed-by: Keir Fraser <keir@xen.org>
This commit is contained in:
1 parent
0d7f18b01f
commit
a655abfd8a
8 files changed
+54
-2
No files matched your search
@@ -56,7 +56,7 @@ type device_t, resource_type;
|
||||
################################################################################
|
||||
allow dom0_t xen_t:xen { kexec readapic writeapic mtrr_read mtrr_add mtrr_del
|
||||
scheduler physinfo heap quirk readconsole writeconsole settime getcpuinfo
|
||||
microcode cpupool_op sched_op pm_op };
|
||||
microcode cpupool_op sched_op pm_op tmem_control };
|
||||
allow dom0_t xen_t:mmu { memorymap };
|
||||
allow dom0_t security_t:security { check_context compute_av compute_create
|
||||
compute_member load_policy compute_relabel compute_user setenforce
|
||||
@@ -74,6 +74,9 @@ domain_comms(dom0_t, dom0_t)
|
||||
|
||||
auditallow dom0_t security_t:security { load_policy setenforce setbool };
|
||||
|
||||
# Allow all domains to use (unprivileged parts of) the tmem hypercall
|
||||
allow domain_type xen_t:xen tmem_op;
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Domain creation
|
||||
|
||||
@@ -2644,6 +2644,9 @@ EXPORT long do_tmem_op(tmem_cli_op_t uops)
|
||||
if ( !tmem_initialized )
|
||||
return -ENODEV;
|
||||
|
||||
if ( !tmh_current_permitted() )
|
||||
return -EPERM;
|
||||
|
||||
total_tmem_ops++;
|
||||
|
||||
if ( tmh_lock_all )
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <xen/guest_access.h> /* copy_from_guest */
|
||||
#include <xen/hash.h> /* hash_long */
|
||||
#include <xen/domain_page.h> /* __map_domain_page */
|
||||
#include <xsm/xsm.h> /* xsm_tmem_control */
|
||||
#include <public/tmem.h>
|
||||
#ifdef CONFIG_COMPAT
|
||||
#include <compat/tmem.h>
|
||||
@@ -326,9 +327,14 @@ static inline bool_t tmh_set_client_from_id(
|
||||
return rc;
|
||||
}
|
||||
|
||||
static inline bool_t tmh_current_permitted(void)
|
||||
{
|
||||
return !xsm_tmem_op(XSM_HOOK);
|
||||
}
|
||||
|
||||
static inline bool_t tmh_current_is_privileged(void)
|
||||
{
|
||||
return IS_PRIV(current->domain);
|
||||
return !xsm_tmem_control(XSM_PRIV);
|
||||
}
|
||||
|
||||
static inline uint8_t tmh_get_first_byte(pfp_t *pfp)
|
||||
|
||||
@@ -371,6 +371,18 @@ static XSM_INLINE int xsm_page_offline(XSM_DEFAULT_ARG uint32_t cmd)
|
||||
return xsm_default_action(action, current->domain, NULL);
|
||||
}
|
||||
|
||||
static XSM_INLINE int xsm_tmem_op(XSM_DEFAULT_VOID)
|
||||
{
|
||||
XSM_ASSERT_ACTION(XSM_HOOK);
|
||||
return xsm_default_action(action, current->domain, NULL);
|
||||
}
|
||||
|
||||
static XSM_INLINE int xsm_tmem_control(XSM_DEFAULT_VOID)
|
||||
{
|
||||
XSM_ASSERT_ACTION(XSM_PRIV);
|
||||
return xsm_default_action(action, current->domain, NULL);
|
||||
}
|
||||
|
||||
static XSM_INLINE long xsm_do_xsm_op(XEN_GUEST_HANDLE_PARAM(xsm_op_t) op)
|
||||
{
|
||||
return -ENOSYS;
|
||||
|
||||
@@ -119,6 +119,8 @@ struct xsm_operations {
|
||||
int (*resource_setup_misc) (void);
|
||||
|
||||
int (*page_offline)(uint32_t cmd);
|
||||
int (*tmem_op)(void);
|
||||
int (*tmem_control)(void);
|
||||
|
||||
long (*do_xsm_op) (XEN_GUEST_HANDLE_PARAM(xsm_op_t) op);
|
||||
|
||||
@@ -441,6 +443,16 @@ static inline int xsm_page_offline(xsm_default_t def, uint32_t cmd)
|
||||
return xsm_ops->page_offline(cmd);
|
||||
}
|
||||
|
||||
static inline int xsm_tmem_op(xsm_default_t def)
|
||||
{
|
||||
return xsm_ops->tmem_op();
|
||||
}
|
||||
|
||||
static inline int xsm_tmem_control(xsm_default_t def)
|
||||
{
|
||||
return xsm_ops->tmem_control();
|
||||
}
|
||||
|
||||
static inline long xsm_do_xsm_op (XEN_GUEST_HANDLE_PARAM(xsm_op_t) op)
|
||||
{
|
||||
return xsm_ops->do_xsm_op(op);
|
||||
|
||||
@@ -94,6 +94,8 @@ void xsm_fixup_ops (struct xsm_operations *ops)
|
||||
set_to_dummy_if_null(ops, resource_setup_misc);
|
||||
|
||||
set_to_dummy_if_null(ops, page_offline);
|
||||
set_to_dummy_if_null(ops, tmem_op);
|
||||
set_to_dummy_if_null(ops, tmem_control);
|
||||
|
||||
set_to_dummy_if_null(ops, do_xsm_op);
|
||||
|
||||
|
||||
@@ -1017,6 +1017,16 @@ static inline int flask_page_offline(uint32_t cmd)
|
||||
}
|
||||
}
|
||||
|
||||
static inline int flask_tmem_op(void)
|
||||
{
|
||||
return domain_has_xen(current->domain, XEN__TMEM_OP);
|
||||
}
|
||||
|
||||
static inline int flask_tmem_control(void)
|
||||
{
|
||||
return domain_has_xen(current->domain, XEN__TMEM_CONTROL);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_X86
|
||||
static int flask_shadow_control(struct domain *d, uint32_t op)
|
||||
{
|
||||
@@ -1456,6 +1466,8 @@ static struct xsm_operations flask_ops = {
|
||||
.resource_setup_misc = flask_resource_setup_misc,
|
||||
|
||||
.page_offline = flask_page_offline,
|
||||
.tmem_op = flask_tmem_op,
|
||||
.tmem_control = flask_tmem_control,
|
||||
|
||||
.do_xsm_op = do_flask_op,
|
||||
|
||||
|
||||
@@ -35,6 +35,8 @@ class xen
|
||||
lockprof
|
||||
cpupool_op
|
||||
sched_op
|
||||
tmem_op
|
||||
tmem_control
|
||||
}
|
||||
|
||||
class domain
|
||||
|
||||