From patchwork Thu Jul 7 15:35:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel De Graaf X-Patchwork-Id: 9219127 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 59BCA6048B for ; Thu, 7 Jul 2016 15:37:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 492A427FA8 for ; Thu, 7 Jul 2016 15:37:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3DF3C27FAB; Thu, 7 Jul 2016 15:37:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EFC0927FA8 for ; Thu, 7 Jul 2016 15:37:41 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bLBKu-0003KZ-11; Thu, 07 Jul 2016 15:35:32 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bLBKs-0003KD-La for xen-devel@lists.xenproject.org; Thu, 07 Jul 2016 15:35:30 +0000 Received: from [85.158.139.211] by server-5.bemta-5.messagelabs.com id FF/65-29837-1C67E775; Thu, 07 Jul 2016 15:35:29 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrELMWRWlGSWpSXmKPExsXCoZPKoXuwrC7 c4HW3sMX3LZOZHBg9Dn+4whLAGMWamZeUX5HAmtFyw6BgvX3F7jd7GRsYVxt0MXJySAj4SUx+ 28vUxcjFwSlwgkXi8Ybz7BCJbYwSp9cag9hCAu2MEh/vlYAUCQlsZZTo3PqcCSTBJqArseDgS jBbREBJ4t6qyWCTmAUeMko82XSYBSQhLGAp0XbiLlsXIwcHi4CqRMNhJZAwr4CrRPvDaVDL5C RunutknsDIs4CRYRWjRnFqUVlqka6RsV5SUWZ6RkluYmaOrqGBqV5uanFxYnpqTmJSsV5yfu4 mRqDf6xkYGHcw7mj3O8QoycGkJMqr4F8XLsSXlJ9SmZFYnBFfVJqTWnyIUYaDQ0mC93opUE6w KDU9tSItMwcYgDBpCQ4eJRHeJSBp3uKCxNzizHSI1ClGRSlx3iiQhABIIqM0D64NFvSXGGWlh HkZGRgYhHgKUotyM0tQ5V8xinMwKgnzTgSZwpOZVwI3/RXQYiagxT9dqkEWlyQipKQaGF1vlr GnRCdc3HDqcfAZZ61QdalzrhujNmmwSly2VF2rJHLl1PE+yRnHrixayfsvPeR1ssu7uoJ5L+I Dquw+H5yszfn51vm9gWZyZlKLa4UCAyY7mB8yjXTQOrZvoccju6j560pmf1vRb3dzdlLuyTNN STuv3DB2t9uY8eOsiPuX0/18WavFpiixFGckGmoxFxUnAgC+hj+cdQIAAA== X-Env-Sender: dgdegra@tycho.nsa.gov X-Msg-Ref: server-5.tower-206.messagelabs.com!1467905727!48989557!1 X-Originating-IP: [8.44.101.8] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 17318 invoked from network); 7 Jul 2016 15:35:29 -0000 Received: from smtp.nsa.gov (HELO emsm-gh1-uea10.nsa.gov) (8.44.101.8) by server-5.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 7 Jul 2016 15:35:29 -0000 X-IronPort-AV: E=Sophos;i="5.28,324,1464652800"; d="scan'208";a="15349321" IronPort-PHdr: =?us-ascii?q?9a23=3A2g1z/BMZUP/1+YXUUf8l6mtUPXoX/o7sNwtQ0KIM?= =?us-ascii?q?zox0KPT4rarrMEGX3/hxlliBBdydsKMczbCG+PC9EUU7or+5+EgYd5JNUxJXwe?= =?us-ascii?q?43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6anHS+4HYoFwnlMkIt?= =?us-ascii?q?f6KuS9aU1ZT8h7360qaQSj0AvCC6b7J2IUf+hiTqne5Sv7FfLL0swADCuHpCdr?= =?us-ascii?q?ce72ppIVWOg0S0vZ/or9ZLuh5dsPM59sNGTb6yP+FhFeQZXwk8NygJwOGj9VyZ?= =?us-ascii?q?FUrcrkcbB3UblF9EDhbI6Dn+X4ztqW3qu+xlwi6YMMbqC7cuVmeM9aBuHTPhji?= =?us-ascii?q?YKM3YV/Sn4kMV5guoPrB2tqhNlyqbIcYqVM7x4ZaqbctQEEzkSFv1NXjBMV9vv?= =?us-ascii?q?J7AECPAMaKMB9dHw?= X-IPAS-Result: =?us-ascii?q?A2EgBQDHdX5X/wHyM5BcHAEBgyCBUrcAhAoShgaBLEwBAQE?= =?us-ascii?q?BAQECAmIngjKCSFIogSmIML0DATCVDwWIGos/hTqORwKJYIVISI9CVIIJHIFoI?= =?us-ascii?q?DKIfAEBAQ?= Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea10.nsa.gov with ESMTP; 07 Jul 2016 15:35:24 +0000 Received: from moss-nexus.infosec.tycho.ncsc.mil (moss-nexus [192.168.25.48]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u67FZKBs021236; Thu, 7 Jul 2016 11:35:21 -0400 From: Daniel De Graaf To: xen-devel@lists.xenproject.org Date: Thu, 7 Jul 2016 11:35:11 -0400 Message-Id: <1467905712-21538-1-git-send-email-dgdegra@tycho.nsa.gov> X-Mailer: git-send-email 2.7.4 Cc: Doug Goldstein , Daniel De Graaf , Ian Jackson , Jan Beulich Subject: [Xen-devel] [PATCH v5 1/2] xsm: rework policy_buffer globals X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP This makes the buffers function parameters instead of globals, in preparation for adding alternate locations for the policy. Signed-off-by: Daniel De Graaf Reviewed-by: Jan Beulich --- This patch is new in v5. xen/include/xsm/xsm.h | 13 ++++++------- xen/xsm/flask/hooks.c | 2 +- xen/xsm/flask/include/security.h | 2 +- xen/xsm/flask/ss/policydb.h | 2 +- xen/xsm/flask/ss/services.c | 2 +- xen/xsm/xsm_core.c | 17 +++++++++++------ xen/xsm/xsm_policy.c | 21 ++++++++++----------- 7 files changed, 31 insertions(+), 28 deletions(-) diff --git a/xen/include/xsm/xsm.h b/xen/include/xsm/xsm.h index 4b8843d..e83dca2 100644 --- a/xen/include/xsm/xsm.h +++ b/xen/include/xsm/xsm.h @@ -43,9 +43,6 @@ enum xsm_default { }; typedef enum xsm_default xsm_default_t; -extern char *policy_buffer; -extern u32 policy_size; - struct xsm_operations { void (*security_domaininfo) (struct domain *d, struct xen_domctl_getdomaininfo *info); @@ -740,12 +737,14 @@ extern int xsm_multiboot_init(unsigned long *module_map, void *(*bootstrap_map)(const module_t *)); extern int xsm_multiboot_policy_init(unsigned long *module_map, const multiboot_info_t *mbi, - void *(*bootstrap_map)(const module_t *)); + void *(*bootstrap_map)(const module_t *), + void **policy_buffer, + size_t *policy_size); #endif #ifdef CONFIG_HAS_DEVICE_TREE extern int xsm_dt_init(void); -extern int xsm_dt_policy_init(void); +extern int xsm_dt_policy_init(void **policy_buffer, size_t *policy_size); extern bool has_xsm_magic(paddr_t); #endif @@ -755,9 +754,9 @@ extern struct xsm_operations dummy_xsm_ops; extern void xsm_fixup_ops(struct xsm_operations *ops); #ifdef CONFIG_FLASK -extern void flask_init(void); +extern void flask_init(const void *policy_buffer, size_t policy_size); #else -static inline void flask_init(void) +static inline void flask_init(const void *policy_buffer, size_t policy_size) { } #endif diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c index 2692a6f..3555907 100644 --- a/xen/xsm/flask/hooks.c +++ b/xen/xsm/flask/hooks.c @@ -1815,7 +1815,7 @@ static struct xsm_operations flask_ops = { .xen_version = flask_xen_version, }; -__init void flask_init(void) +__init void flask_init(const void *policy_buffer, size_t policy_size) { int ret = -ENOENT; diff --git a/xen/xsm/flask/include/security.h b/xen/xsm/flask/include/security.h index 1da020d..ec8b442 100644 --- a/xen/xsm/flask/include/security.h +++ b/xen/xsm/flask/include/security.h @@ -52,7 +52,7 @@ enum flask_bootparam_t { extern enum flask_bootparam_t flask_bootparam; extern int flask_mls_enabled; -int security_load_policy(void * data, size_t len); +int security_load_policy(const void *data, size_t len); struct av_decision { u32 allowed; diff --git a/xen/xsm/flask/ss/policydb.h b/xen/xsm/flask/ss/policydb.h index 238a042..d3b409a 100644 --- a/xen/xsm/flask/ss/policydb.h +++ b/xen/xsm/flask/ss/policydb.h @@ -277,7 +277,7 @@ extern int policydb_read(struct policydb *p, void *fp); #define TARGET_XEN_OLD 0 struct policy_file { - char *data; + const char *data; size_t len; }; diff --git a/xen/xsm/flask/ss/services.c b/xen/xsm/flask/ss/services.c index 86f94c9..b2c5c44 100644 --- a/xen/xsm/flask/ss/services.c +++ b/xen/xsm/flask/ss/services.c @@ -1353,7 +1353,7 @@ static int security_preserve_bools(struct policydb *p); * This function will flush the access vector cache after * loading the new policy. */ -int security_load_policy(void *data, size_t len) +int security_load_policy(const void *data, size_t len) { struct policydb oldpolicydb, newpolicydb; struct sidtab oldsidtab, newsidtab; diff --git a/xen/xsm/xsm_core.c b/xen/xsm/xsm_core.c index 8df1a3c..3d132be 100644 --- a/xen/xsm/xsm_core.c +++ b/xen/xsm/xsm_core.c @@ -36,7 +36,7 @@ static inline int verify(struct xsm_operations *ops) return 0; } -static int __init xsm_core_init(void) +static int __init xsm_core_init(const void *policy_buffer, size_t policy_size) { if ( verify(&dummy_xsm_ops) ) { @@ -46,7 +46,7 @@ static int __init xsm_core_init(void) } xsm_ops = &dummy_xsm_ops; - flask_init(); + flask_init(policy_buffer, policy_size); return 0; } @@ -57,12 +57,15 @@ int __init xsm_multiboot_init(unsigned long *module_map, void *(*bootstrap_map)(const module_t *)) { int ret = 0; + void *policy_buffer = NULL; + size_t policy_size = 0; printk("XSM Framework v" XSM_FRAMEWORK_VERSION " initialized\n"); if ( XSM_MAGIC ) { - ret = xsm_multiboot_policy_init(module_map, mbi, bootstrap_map); + ret = xsm_multiboot_policy_init(module_map, mbi, bootstrap_map, + &policy_buffer, &policy_size); if ( ret ) { bootstrap_map(NULL); @@ -71,7 +74,7 @@ int __init xsm_multiboot_init(unsigned long *module_map, } } - ret = xsm_core_init(); + ret = xsm_core_init(policy_buffer, policy_size); bootstrap_map(NULL); return 0; @@ -82,12 +85,14 @@ int __init xsm_multiboot_init(unsigned long *module_map, int __init xsm_dt_init(void) { int ret = 0; + void *policy_buffer = NULL; + size_t policy_size = 0; printk("XSM Framework v" XSM_FRAMEWORK_VERSION " initialized\n"); if ( XSM_MAGIC ) { - ret = xsm_dt_policy_init(); + ret = xsm_dt_policy_init(&policy_buffer, &policy_size); if ( ret ) { printk("%s: Error initializing policy (rc = %d).\n", @@ -96,7 +101,7 @@ int __init xsm_dt_init(void) } } - ret = xsm_core_init(); + ret = xsm_core_init(policy_buffer, policy_size); xfree(policy_buffer); diff --git a/xen/xsm/xsm_policy.c b/xen/xsm/xsm_policy.c index bde8015..5e76824 100644 --- a/xen/xsm/xsm_policy.c +++ b/xen/xsm/xsm_policy.c @@ -28,13 +28,12 @@ # include #endif -char *__initdata policy_buffer = NULL; -u32 __initdata policy_size = 0; - #ifdef CONFIG_MULTIBOOT int __init xsm_multiboot_policy_init(unsigned long *module_map, const multiboot_info_t *mbi, - void *(*bootstrap_map)(const module_t *)) + void *(*bootstrap_map)(const module_t *), + void **policy_buffer, + size_t *policy_size) { int i; module_t *mod = (module_t *)__va(mbi->mods_addr); @@ -56,8 +55,8 @@ int __init xsm_multiboot_policy_init(unsigned long *module_map, if ( (xsm_magic_t)(*_policy_start) == XSM_MAGIC ) { - policy_buffer = (char *)_policy_start; - policy_size = _policy_len; + *policy_buffer = (char *)_policy_start; + *policy_size = _policy_len; printk("Policy len %#lx, start at %p.\n", _policy_len,_policy_start); @@ -75,7 +74,7 @@ int __init xsm_multiboot_policy_init(unsigned long *module_map, #endif #ifdef CONFIG_HAS_DEVICE_TREE -int __init xsm_dt_policy_init(void) +int __init xsm_dt_policy_init(void **policy_buffer, size_t *policy_size) { struct bootmodule *mod = boot_module_find_by_kind(BOOTMOD_XSM); paddr_t paddr, len; @@ -95,12 +94,12 @@ int __init xsm_dt_policy_init(void) printk("xsm: Policy len = 0x%"PRIpaddr" start at 0x%"PRIpaddr"\n", len, paddr); - policy_buffer = xmalloc_bytes(len); - if ( !policy_buffer ) + *policy_buffer = xmalloc_bytes(len); + if ( !*policy_buffer ) return -ENOMEM; - copy_from_paddr(policy_buffer, paddr, len); - policy_size = len; + copy_from_paddr(*policy_buffer, paddr, len); + *policy_size = len; return 0; }