Skip to contentSkip to conversation

xsm: move the XSM_MAGIC value to Kconfig

PATCH In review Doug Goldstein 3 participants 10 messages Mar 7, 2016 – Mar 16, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 xsm: move the XSM_MAGIC value to Kconfig

Let Kconfig set the XSM_MAGIC value for us.

---
CC: Daniel De Graaf <[email protected]>

---
 xen/common/Kconfig       | 8 ++++++++
 xen/include/xen/config.h | 1 -
 xen/include/xsm/xsm.h    | 5 +----
 xen/xsm/xsm_core.c       | 4 ++--
 xen/xsm/xsm_policy.c     | 6 +++---
 5 files changed, 14 insertions(+), 10 deletions(-)
xen/common/Kconfig +8 -0
index 8fbc46d..d661da3 100644
@@ -113,6 +113,14 @@ config XSM
 
 	  If unsure, say N.
 
+# XSM magic for policy detection
+config XSM_MAGIC
+    hex
+    default 0xf97cff8c if FLASK
+    default 0 if !FLASK
+    ---help---
+      Identifies a FLASK XSM policy start point
+
 # Enable schedulers
 menu "Schedulers"
 	visible if EXPERT = "y"
xen/include/xen/config.h +0 -1
index 96f5539..3f8c53d 100644
@@ -79,7 +79,6 @@
 #define STR(...) __STR(__VA_ARGS__)
 
 #ifdef CONFIG_FLASK
-#define XSM_MAGIC 0xf97cff8c
 /* Maintain statistics on the access vector cache */
 #define FLASK_AVC_STATS 1
 #endif
xen/include/xsm/xsm.h +1 -4
index 3afed70..7f313ad 100644
@@ -21,11 +21,8 @@
 typedef void xsm_op_t;
 DEFINE_XEN_GUEST_HANDLE(xsm_op_t);
 
-/* policy magic number (defined by XSM_MAGIC) */
+/* policy magic number (defined by CONFIG_XSM_MAGIC) */
 typedef u32 xsm_magic_t;
-#ifndef XSM_MAGIC
-#define XSM_MAGIC 0x00000000
-#endif
 
 /* These annotations are used by callers and in dummy.h to document the
  * default actions of XSM hooks. They should be compiled out otherwise.
xen/xsm/xsm_core.c +2 -2
index 5e432de..d6965ba 100644
@@ -67,7 +67,7 @@ int __init xsm_multiboot_init(unsigned long *module_map,
 
     printk("XSM Framework v" XSM_FRAMEWORK_VERSION " initialized\n");
 
-    if ( XSM_MAGIC )
+    if ( CONFIG_XSM_MAGIC )
     {
         ret = xsm_multiboot_policy_init(module_map, mbi, bootstrap_map);
         if ( ret )
@@ -92,7 +92,7 @@ int __init xsm_dt_init(void)
 
     printk("XSM Framework v" XSM_FRAMEWORK_VERSION " initialized\n");
 
-    if ( XSM_MAGIC )
+    if ( CONFIG_XSM_MAGIC )
     {
         ret = xsm_dt_policy_init();
         if ( ret )
xen/xsm/xsm_policy.c +3 -3
index b60d822..52aa4a9 100644
@@ -54,7 +54,7 @@ int __init xsm_multiboot_policy_init(unsigned long *module_map,
         _policy_start = bootstrap_map(mod + i);
         _policy_len   = mod[i].mod_end;
 
-        if ( (xsm_magic_t)(*_policy_start) == XSM_MAGIC )
+        if ( (xsm_magic_t)(*_policy_start) == CONFIG_XSM_MAGIC )
         {
             policy_buffer = (char *)_policy_start;
             policy_size = _policy_len;
@@ -89,10 +89,10 @@ int __init xsm_dt_policy_init(void)
 
     copy_from_paddr(&magic, paddr, sizeof(magic));
 
-    if ( magic != XSM_MAGIC )
+    if ( magic != CONFIG_XSM_MAGIC )
     {
         printk(XENLOG_ERR "xsm: Invalid magic for XSM blob got 0x%x "
-               "expected 0x%x\n", magic, XSM_MAGIC);
+               "expected 0x%x\n", magic, CONFIG_XSM_MAGIC);
         return -EINVAL;
     }
 
Signature · 7 lines
2.4.10


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#1 lore raw

PATCH 2/2 xsm: move FLASK_AVC_STATS to Kconfig

Have Kconfig set CONFIG_FLASK_AVC_STATS and prefix all uses with CONFIG_ to use the Kconfig variable.

---
CC: Daniel De Graaf <[email protected]>

---
 xen/common/Kconfig          | 8 +++++++-
 xen/include/xen/config.h    | 5 -----
 xen/xsm/flask/avc.c         | 4 ++--
 xen/xsm/flask/flask_op.c    | 4 ++--
 xen/xsm/flask/include/avc.h | 2 +-
 5 files changed, 12 insertions(+), 11 deletions(-)
xen/common/Kconfig +7 -1
index d661da3..db23edc 100644
@@ -23,6 +23,12 @@ config FLASK
 
 	  If unsure, say N.
 
+config FLASK_AVC_STATS
+    def_bool y if FLASK
+    depends on FLASK
+    ---help---
+      Maintain statistics on the access vector cache
+
 # Select HAS_DEVICE_TREE if device tree is supported
 config HAS_DEVICE_TREE
 	bool
@@ -117,7 +123,7 @@ config XSM
 config XSM_MAGIC
     hex
     default 0xf97cff8c if FLASK
-    default 0 if !FLASK
+    default 0
     ---help---
       Identifies a FLASK XSM policy start point
 
xen/include/xen/config.h +0 -5
index 3f8c53d..ef6e5ee 100644
@@ -78,11 +78,6 @@
 #define __STR(...) #__VA_ARGS__
 #define STR(...) __STR(__VA_ARGS__)
 
-#ifdef CONFIG_FLASK
-/* Maintain statistics on the access vector cache */
-#define FLASK_AVC_STATS 1
-#endif
-
 /* allow existing code to work with Kconfig variable */
 #define NR_CPUS CONFIG_NR_CPUS
 
xen/xsm/flask/avc.c +2 -2
index 31bc702..7764379 100644
@@ -56,7 +56,7 @@ const struct selinux_class_perm selinux_class_perm = {
 #define AVC_DEF_CACHE_THRESHOLD        512
 #define AVC_CACHE_RECLAIM        16
 
-#ifdef FLASK_AVC_STATS
+#ifdef CONFIG_FLASK_AVC_STATS
 #define avc_cache_stats_incr(field)                 \
 do {                                \
     __get_cpu_var(avc_cache_stats).field++;        \
@@ -101,7 +101,7 @@ struct avc_callback_node {
 /* Exported via Flask hypercall */
 unsigned int avc_cache_threshold = AVC_DEF_CACHE_THRESHOLD;
 
-#ifdef FLASK_AVC_STATS
+#ifdef CONFIG_FLASK_AVC_STATS
 DEFINE_PER_CPU(struct avc_cache_stats, avc_cache_stats);
 #endif
 
xen/xsm/flask/flask_op.c +2 -2
index f4f5dd1..3c9c99e 100644
@@ -469,7 +469,7 @@ static int flask_security_make_bools(void)
     return ret;
 }
 
-#ifdef FLASK_AVC_STATS
+#ifdef CONFIG_FLASK_AVC_STATS
 
 static int flask_security_avc_cachestats(struct xen_flask_cache_stats *arg)
 {
@@ -761,7 +761,7 @@ ret_t do_flask_op(XEN_GUEST_HANDLE_PARAM(xsm_op_t) u_flask_op)
         rv = avc_get_hash_stats(&op.u.hash_stats);
         break;
 
-#ifdef FLASK_AVC_STATS
+#ifdef CONFIG_FLASK_AVC_STATS
     case FLASK_AVC_CACHESTATS:
         rv = flask_security_avc_cachestats(&op.u.cache_stats);
         break;
xen/xsm/flask/include/avc.h +1 -1
index 4283562..729856e 100644
@@ -108,7 +108,7 @@ struct xen_flask_hash_stats;
 int avc_get_hash_stats(struct xen_flask_hash_stats *arg);
 extern unsigned int avc_cache_threshold;
 
-#ifdef FLASK_AVC_STATS
+#ifdef CONFIG_FLASK_AVC_STATS
 DECLARE_PER_CPU(struct avc_cache_stats, avc_cache_stats);
 #endif
 
Signature · 7 lines
2.4.10


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#2 lore raw

Re: [PATCH 2/2] xsm: move FLASK_AVC_STATS to Kconfig

Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 07.03.16 at 19:42, <[email protected]> wrote:

Have Kconfig set CONFIG_FLASK_AVC_STATS and prefix all uses with CONFIG_ to use the Kconfig variable.

Same question here: What's the benefit of doing it this way?

xen/common/Kconfig config FLASK · line 28

Quoted 9 lines
xen/common/Kconfig +3 -0
@@ -23,6 +23,12 @@ config FLASK
 
 	  If unsure, say N.
 
+config FLASK_AVC_STATS
+    def_bool y if FLASK
+    depends on FLASK

With this "depends" the "if FLASK" is pointless.

Also (again) - indentation.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw

Re: [PATCH 2/2] xsm: move FLASK_AVC_STATS to Kconfig

Quoted 5 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 07.03.16 at 19:42, <[email protected]> wrote:

Have Kconfig set CONFIG_FLASK_AVC_STATS and prefix all uses with CONFIG_ to use the Kconfig variable.

Same question here: What's the benefit of doing it this way?

This removes the stats tracking, which might (I have not tested) speed up the security server by avoiding the __get_cpu_var call and increment. The corresponding SELinux knob is a Kconfig option in Linux.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#4 lore raw

Re: [PATCH 2/2] xsm: move FLASK_AVC_STATS to Kconfig

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 08.03.16 at 17:22, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 07.03.16 at 19:42, <[email protected]> wrote:

Have Kconfig set CONFIG_FLASK_AVC_STATS and prefix all uses with CONFIG_ to use the Kconfig variable.

Same question here: What's the benefit of doing it this way?

This removes the stats tracking, which might (I have not tested) speed up the security server by avoiding the __get_cpu_var call and increment.

No, I don not think the patch removes anything. The Kconfig option doesn't have a prompt. But anyway, ...

Quoted 4 lines

The
corresponding SELinux knob is a Kconfig option in Linux.

... if you're fine with it, we'll put it in (once the mechanical issues got addressed).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#5 lore raw

Re: [PATCH 2/2] xsm: move FLASK_AVC_STATS to Kconfig

Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 08.03.16 at 17:22, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 07.03.16 at 19:42, <[email protected]> wrote:

Have Kconfig set CONFIG_FLASK_AVC_STATS and prefix all uses with CONFIG_ to use the Kconfig variable.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Same question here: What's the benefit of doing it this way?

This removes the stats tracking, which might (I have not tested) speed up the security server by avoiding the __get_cpu_var call and increment.

No, I don not think the patch removes anything. The Kconfig option doesn't have a prompt. But anyway, ...

Ah, I missed that: I saw the --help-- line and assumed it was the prompt. Either way, this #define is a configuration-like knob that doesn't need to be hard-coded in a header as it currently is.

Quoted 8 lines
Quoted 5 lines

The
corresponding SELinux knob is a Kconfig option in Linux.

... if you're fine with it, we'll put it in (once the mechanical issues got addressed).

Signature · 7 lines
Daniel De Graaf
National Security Agency

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#6 lore raw

Re: [PATCH 2/2] xsm: move FLASK_AVC_STATS to Kconfig

Quoted 14 lines · Daniel De Graaf
Quoted 13 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 08.03.16 at 17:22, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 07.03.16 at 19:42, <[email protected]> wrote:

Have Kconfig set CONFIG_FLASK_AVC_STATS and prefix all uses with CONFIG_
to use the Kconfig variable.

Same question here: What's the benefit of doing it this way?

This removes the stats tracking, which might (I have not tested) speed up
the security server by avoiding the __get_cpu_var call and increment.

Quoted 16 lines
Quoted 2 lines

No, I don not think the patch removes anything. The Kconfig option doesn't have a prompt. But anyway, ...

Ah, I missed that: I saw the --help-- line and assumed it was the prompt. Either way, this #define is a configuration-like knob that doesn't need to be hard-coded in a header as it currently is.

Quoted 8 lines
Quoted 5 lines

The
corresponding SELinux knob is a Kconfig option in Linux.

... if you're fine with it, we'll put it in (once the mechanical issues got addressed).

Daniel,

Would you like me to make this a real configuration option? Or proceed with the current path and we can make a configuration option later?

Signature · 1 line
Doug Goldstein

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#7 lore raw

Re: [PATCH 2/2] xsm: move FLASK_AVC_STATS to Kconfig

Quoted 28 lines · Doug Goldstein
Quoted 27 lines · Daniel De Graaf
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 08.03.16 at 17:22, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 07.03.16 at 19:42, <[email protected]> wrote:

Have Kconfig set CONFIG_FLASK_AVC_STATS and prefix all uses with CONFIG_
to use the Kconfig variable.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Same question here: What's the benefit of doing it this way?

This removes the stats tracking, which might (I have not tested) speed up
the security server by avoiding the __get_cpu_var call and increment.

No, I don not think the patch removes anything. The Kconfig option doesn't have a prompt. But anyway, ...

Ah, I missed that: I saw the --help-- line and assumed it was the prompt. Either way, this #define is a configuration-like knob that doesn't need to be hard-coded in a header as it currently is.

Quoted 6 lines
Quoted 5 lines

The
corresponding SELinux knob is a Kconfig option in Linux.

Quoted 9 lines
Quoted 3 lines
Quoted 2 lines

... if you're fine with it, we'll put it in (once the mechanical issues got addressed).

Daniel,

Would you like me to make this a real configuration option? Or proceed with the current path and we can make a configuration option later?

I'll resubmit as is and we can address making that a user facing option in a follow on.

Signature · 1 line
Doug Goldstein

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#8 lore raw
In reply to Doug Goldstein
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 07.03.16 at 19:42, <[email protected]> wrote:

Let Kconfig set the XSM_MAGIC value for us.

What's the benefit of doing this at the Kconfig layer?

xen/common/Kconfig config XSM · line 120

Quoted 11 lines
xen/common/Kconfig +5 -0
@@ -113,6 +113,14 @@ config XSM
 
 	  If unsure, say N.
 
+# XSM magic for policy detection
+config XSM_MAGIC
+    hex
+    default 0xf97cff8c if FLASK
+    default 0 if !FLASK

This second "if" is pointless.

Also note the broken indentation (using spaces instead of a tab).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#9 lore raw
In reply to Doug Goldstein
Quoted 3 lines · Doug Goldstein

Let Kconfig set the XSM_MAGIC value for us.

This is not the best place to define this constant: it doesn't make sense for it to be user-configurable. If you want to move it out of config.h, I think the best solution is to define XSM_MAGIC inside xsm/xsm.h depending on the value of CONFIG_FLASK.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel