All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH for-4.16 v3] gnttab: allow setting max version per-domain
@ 2021-10-28  9:59 Roger Pau Monne
  2021-10-28 12:12 ` Ian Jackson
  0 siblings, 1 reply; 4+ messages in thread
From: Roger Pau Monne @ 2021-10-28  9:59 UTC (permalink / raw)
  To: xen-devel
  Cc: Roger Pau Monne, Wei Liu, Andrew Cooper, George Dunlap,
	Jan Beulich, Julien Grall, Stefano Stabellini, Anthony PERARD,
	Juergen Gross, Christian Lindig, David Scott, Volodymyr Babchuk,
	Ian Jackson

Introduce a new domain create field so that toolstack can specify the
maximum grant table version usable by the domain. This is plumbed into
xl and settable by the user as max_grant_version.

Previously this was only settable on a per host basis using the
gnttab command line option.

Note the version is specified using 4 bits, which leaves room to
specify up to grant table version 14 (15 is used to signal default max
version). Given that we only have 2 grant table versions right now,
and a new version is unlikely in the near future using 4 bits seems
more than enough.

Note that when using the default grant version the specific max
version in use by the domain is not migrated. Any guests should be
able to cope with the max grant version changing across migrations,
and if a specific guest relies on a maximum grant version being
unconditionally available it should be specified on the configuration
file.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Christian Lindig <christian.lindig@citrix.com>
---
NB: the stubdom max grant version is cloned from the domain one. Not
sure whether long term we might want to use different options for the
stubdom and the domain. In any case the attack surface will always be
max(stubdom, domain), so maybe it's just pointless to allow more fine
grained settings.
---
Changes since v2:
 - Drop XEN_DOMCTLGRANT_MAX - it's unused.
 - Rename max_grant_version field to max_version in the grant table
   struct.
 - Print domain on log messages.
 - Print a message if host has more than 16Tb of RAM and grant v2 is
   disabled.
 - Add a TB macro.

Changes since v1:
 - Introduce a grant_opts field and use the low 4 bits to specify the
   version. Remaining bits will be used for other purposes.
---
Cc: Ian Jackson <iwj@xenproject.org>
---
Posting this patch alone as I think allowing to control transient
grants on a per-domain basis will require a bit more of work.

Release rationale:

We have had a bunch of security issues involving grant table v2 (382,
379, 268, 255) which could have been avoided by limiting the grant
table version available to guests. This can be currently done using a
global host parameter, but it's certainly more helpful to be able to
do it on a per domain basis from the toolstack.

Changes to the hypervisor by this patch are fairly minimal, as there
are already checks for the max grant table version allowed, so the
main change there is moving the max grant table version limit inside
the domain struct and plumbing it through the toolstrack.

I think the risk here is quite low for libxl/xl, because it's
extensively tested by osstest, so the main risk would be breaking the
Ocaml stubs, which could go unnoticed as those are not actually tested
by osstest.
---
 docs/man/xl.cfg.5.pod.in             |  6 ++++++
 docs/man/xl.conf.5.pod.in            |  7 +++++++
 tools/helpers/init-xenstore-domain.c |  1 +
 tools/include/libxl.h                |  7 +++++++
 tools/libs/light/libxl_create.c      |  3 +++
 tools/libs/light/libxl_dm.c          |  1 +
 tools/libs/light/libxl_types.idl     |  1 +
 tools/ocaml/libs/xc/xenctrl.ml       |  1 +
 tools/ocaml/libs/xc/xenctrl.mli      |  1 +
 tools/ocaml/libs/xc/xenctrl_stubs.c  |  7 ++++++-
 tools/xl/xl.c                        |  8 ++++++++
 tools/xl/xl.h                        |  1 +
 tools/xl/xl_parse.c                  |  9 +++++++++
 xen/arch/arm/domain_build.c          |  2 ++
 xen/arch/x86/setup.c                 |  1 +
 xen/common/domain.c                  |  3 ++-
 xen/common/grant_table.c             | 28 ++++++++++++++++++++++++++--
 xen/include/public/domctl.h          | 10 ++++++++--
 xen/include/xen/config.h             |  1 +
 xen/include/xen/grant_table.h        |  5 +++--
 20 files changed, 95 insertions(+), 8 deletions(-)

diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in
index 55c4881205..21a39adb70 100644
--- a/docs/man/xl.cfg.5.pod.in
+++ b/docs/man/xl.cfg.5.pod.in
@@ -580,6 +580,12 @@ to have. This value controls how many pages of foreign domains can be accessed
 via the grant mechanism by this domain. The default value is settable via
 L<xl.conf(5)>.
 
+=item B<max_grant_version=NUMBER>
+
+Specify the maximum grant table version the domain is allowed to use. Current
+supported versions are 1 and 2. The default value is settable via
+L<xl.conf(5)>.
+
 =item B<nomigrate=BOOLEAN>
 
 Disable migration of this domain.  This enables certain other features
diff --git a/docs/man/xl.conf.5.pod.in b/docs/man/xl.conf.5.pod.in
index b48e99131a..0a70698a7c 100644
--- a/docs/man/xl.conf.5.pod.in
+++ b/docs/man/xl.conf.5.pod.in
@@ -101,6 +101,13 @@ Sets the default value for the C<max_maptrack_frames> domain config value.
 Default: value of Xen command line B<gnttab_max_maptrack_frames>
 parameter (or its default value if unspecified).
 
+=item B<max_grant_version=NUMBER>
+
+Sets the default value for the C<max_grant_version> domain config value.
+
+Default: value of Xen command line B<gnttab> parameter (or its default value if
+unspecified).
+
 =item B<vif.default.script="PATH">
 
 Configures the default hotplug script used by virtual network devices.
diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-xenstore-domain.c
index 6836002f0b..7cd1aa8f7c 100644
--- a/tools/helpers/init-xenstore-domain.c
+++ b/tools/helpers/init-xenstore-domain.c
@@ -88,6 +88,7 @@ static int build(xc_interface *xch)
          */
         .max_grant_frames = 4,
         .max_maptrack_frames = 128,
+        .grant_opts = 1,
     };
 
     xs_fd = open("/dev/xen/xenbus_backend", O_RDWR);
diff --git a/tools/include/libxl.h b/tools/include/libxl.h
index 2e8679dbcb..8621161845 100644
--- a/tools/include/libxl.h
+++ b/tools/include/libxl.h
@@ -514,6 +514,13 @@
  */
 #define LIBXL_HAVE_VPMU 1
 
+/*
+ * LIBXL_HAVE_MAX_GRANT_VERSION indicates libxl_domain_build_info has a
+ * max_grant_version field for setting the max grant table version per
+ * domain.
+ */
+#define LIBXL_HAVE_MAX_GRANT_VERSION 1
+
 /*
  * libxl ABI compatibility
  *
diff --git a/tools/libs/light/libxl_create.c b/tools/libs/light/libxl_create.c
index 5a61d01722..431c569dd2 100644
--- a/tools/libs/light/libxl_create.c
+++ b/tools/libs/light/libxl_create.c
@@ -607,6 +607,9 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config,
             .max_evtchn_port = b_info->event_channels,
             .max_grant_frames = b_info->max_grant_frames,
             .max_maptrack_frames = b_info->max_maptrack_frames,
+            .grant_opts = b_info->max_grant_version == -1
+                          ? XEN_DOMCTL_GRANT_version_default
+                          : b_info->max_grant_version,
             .vmtrace_size = ROUNDUP(b_info->vmtrace_buf_kb << 10, XC_PAGE_SHIFT),
         };
 
diff --git a/tools/libs/light/libxl_dm.c b/tools/libs/light/libxl_dm.c
index 9d93056b5c..9a8ddbe188 100644
--- a/tools/libs/light/libxl_dm.c
+++ b/tools/libs/light/libxl_dm.c
@@ -2320,6 +2320,7 @@ void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state *sdss)
 
     dm_config->b_info.max_grant_frames = guest_config->b_info.max_grant_frames;
     dm_config->b_info.max_maptrack_frames = guest_config->b_info.max_maptrack_frames;
+    dm_config->b_info.max_grant_version = guest_config->b_info.max_grant_version;
 
     dm_config->b_info.u.pv.features = "";
 
diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_types.idl
index 608d55a456..ce856febe5 100644
--- a/tools/libs/light/libxl_types.idl
+++ b/tools/libs/light/libxl_types.idl
@@ -519,6 +519,7 @@ libxl_domain_build_info = Struct("domain_build_info",[
 
     ("max_grant_frames",    uint32, {'init_val': 'LIBXL_MAX_GRANT_DEFAULT'}),
     ("max_maptrack_frames", uint32, {'init_val': 'LIBXL_MAX_GRANT_DEFAULT'}),
+    ("max_grant_version",   integer, {'init_val': '-1'}),
     
     ("device_model_version", libxl_device_model_version),
     ("device_model_stubdomain", libxl_defbool),
diff --git a/tools/ocaml/libs/xc/xenctrl.ml b/tools/ocaml/libs/xc/xenctrl.ml
index addcf4cc59..d3eacfba6e 100644
--- a/tools/ocaml/libs/xc/xenctrl.ml
+++ b/tools/ocaml/libs/xc/xenctrl.ml
@@ -84,6 +84,7 @@ type domctl_create_config =
 	max_evtchn_port: int;
 	max_grant_frames: int;
 	max_maptrack_frames: int;
+	max_grant_version: int;
 	arch: arch_domainconfig;
 }
 
diff --git a/tools/ocaml/libs/xc/xenctrl.mli b/tools/ocaml/libs/xc/xenctrl.mli
index 0a5ce529e9..96e5d14643 100644
--- a/tools/ocaml/libs/xc/xenctrl.mli
+++ b/tools/ocaml/libs/xc/xenctrl.mli
@@ -76,6 +76,7 @@ type domctl_create_config = {
   max_evtchn_port: int;
   max_grant_frames: int;
   max_maptrack_frames: int;
+  max_grant_version: int;
   arch: arch_domainconfig;
 }
 
diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenctrl_stubs.c
index ad953d36bd..1e60925069 100644
--- a/tools/ocaml/libs/xc/xenctrl_stubs.c
+++ b/tools/ocaml/libs/xc/xenctrl_stubs.c
@@ -188,7 +188,8 @@ CAMLprim value stub_xc_domain_create(value xch, value wanted_domid, value config
 #define VAL_MAX_EVTCHN_PORT     Field(config, 5)
 #define VAL_MAX_GRANT_FRAMES    Field(config, 6)
 #define VAL_MAX_MAPTRACK_FRAMES Field(config, 7)
-#define VAL_ARCH                Field(config, 8)
+#define VAL_MAX_GRANT_VERSION   Field(config, 8)
+#define VAL_ARCH                Field(config, 9)
 
 	uint32_t domid = Int_val(wanted_domid);
 	int result;
@@ -198,6 +199,9 @@ CAMLprim value stub_xc_domain_create(value xch, value wanted_domid, value config
 		.max_evtchn_port = Int_val(VAL_MAX_EVTCHN_PORT),
 		.max_grant_frames = Int_val(VAL_MAX_GRANT_FRAMES),
 		.max_maptrack_frames = Int_val(VAL_MAX_MAPTRACK_FRAMES),
+		.grant_opts = Int_val(VAL_MAX_GRANT_VERSION) == -1
+			      ? XEN_DOMCTL_GRANT_version_default
+			      : Int_val(VAL_MAX_GRANT_VERSION),
 	};
 
 	domain_handle_of_uuid_string(cfg.handle, String_val(VAL_HANDLE));
@@ -251,6 +255,7 @@ CAMLprim value stub_xc_domain_create(value xch, value wanted_domid, value config
 	}
 
 #undef VAL_ARCH
+#undef VAL_MAX_GRANT_VERSION
 #undef VAL_MAX_MAPTRACK_FRAMES
 #undef VAL_MAX_GRANT_FRAMES
 #undef VAL_MAX_EVTCHN_PORT
diff --git a/tools/xl/xl.c b/tools/xl/xl.c
index f422f9fed5..7564ff323b 100644
--- a/tools/xl/xl.c
+++ b/tools/xl/xl.c
@@ -55,6 +55,7 @@ bool progress_use_cr = 0;
 bool timestamps = 0;
 int max_grant_frames = -1;
 int max_maptrack_frames = -1;
+int max_grant_version = -1;
 libxl_domid domid_policy = INVALID_DOMID;
 
 xentoollog_level minmsglevel = minmsglevel_default;
@@ -219,6 +220,13 @@ static void parse_global_config(const char *configfile,
     else if (e != ESRCH)
         exit(1);
 
+    e = xlu_cfg_get_bounded_long (config, "max_grant_version", 0,
+                                  INT_MAX, &l, 1);
+    if (!e)
+        max_grant_version = l;
+    else if (e != ESRCH)
+        exit(1);
+
     libxl_cpu_bitmap_alloc(ctx, &global_vm_affinity_mask, 0);
     libxl_cpu_bitmap_alloc(ctx, &global_hvm_affinity_mask, 0);
     libxl_cpu_bitmap_alloc(ctx, &global_pv_affinity_mask, 0);
diff --git a/tools/xl/xl.h b/tools/xl/xl.h
index 7e23f30192..cf12c79a9b 100644
--- a/tools/xl/xl.h
+++ b/tools/xl/xl.h
@@ -282,6 +282,7 @@ extern char *default_colo_proxy_script;
 extern char *blkdev_start;
 extern int max_grant_frames;
 extern int max_maptrack_frames;
+extern int max_grant_version;
 extern libxl_bitmap global_vm_affinity_mask;
 extern libxl_bitmap global_hvm_affinity_mask;
 extern libxl_bitmap global_pv_affinity_mask;
diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c
index c503b9be00..117fcdcb2b 100644
--- a/tools/xl/xl_parse.c
+++ b/tools/xl/xl_parse.c
@@ -1431,6 +1431,15 @@ void parse_config_data(const char *config_source,
     else
         exit(1);
 
+    e = xlu_cfg_get_bounded_long (config, "max_grant_version", 0,
+                                  INT_MAX, &l, 1);
+    if (e == ESRCH) /* not specified */
+        b_info->max_grant_version = max_grant_version;
+    else if (!e)
+        b_info->max_grant_version = l;
+    else
+        exit(1);
+
     libxl_defbool_set(&b_info->claim_mode, claim_mode);
 
     if (xlu_cfg_get_string (config, "on_poweroff", &buf, 0))
diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 0167731ab0..faeb3eba76 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -2967,6 +2967,7 @@ void __init create_domUs(void)
             .max_evtchn_port = -1,
             .max_grant_frames = -1,
             .max_maptrack_frames = -1,
+            .grant_opts = XEN_DOMCTL_GRANT_version_default,
         };
 
         if ( !dt_device_is_compatible(node, "xen,domain") )
@@ -3074,6 +3075,7 @@ void __init create_dom0(void)
         .max_evtchn_port = -1,
         .max_grant_frames = gnttab_dom0_frames(),
         .max_maptrack_frames = -1,
+        .grant_opts = XEN_DOMCTL_GRANT_version_default,
     };
 
     /* The vGIC for DOM0 is exactly emulating the hardware GIC */
diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index b101565f14..b5b6c75447 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -750,6 +750,7 @@ static struct domain *__init create_dom0(const module_t *image,
         .max_evtchn_port = -1,
         .max_grant_frames = -1,
         .max_maptrack_frames = -1,
+        .grant_opts = XEN_DOMCTL_GRANT_version_default,
         .max_vcpus = dom0_max_vcpus(),
         .arch = {
             .misc_flags = opt_dom0_msr_relaxed ? XEN_X86_MSR_RELAXED : 0,
diff --git a/xen/common/domain.c b/xen/common/domain.c
index 8b53c49d1e..0c7052c770 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -678,7 +678,8 @@ struct domain *domain_create(domid_t domid,
         init_status |= INIT_evtchn;
 
         if ( (err = grant_table_init(d, config->max_grant_frames,
-                                     config->max_maptrack_frames)) != 0 )
+                                     config->max_maptrack_frames,
+                                     config->grant_opts)) != 0 )
             goto fail;
         init_status |= INIT_gnttab;
 
diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c
index e510395d08..f94f0f272c 100644
--- a/xen/common/grant_table.c
+++ b/xen/common/grant_table.c
@@ -53,6 +53,7 @@ struct grant_table {
     percpu_rwlock_t       lock;
     /* Lock protecting the maptrack limit */
     spinlock_t            maptrack_lock;
+    unsigned int          max_version;
     /*
      * Defaults to v1.  May be changed with GNTTABOP_set_version.  All other
      * values are invalid.
@@ -1917,11 +1918,33 @@ active_alloc_failed:
 }
 
 int grant_table_init(struct domain *d, int max_grant_frames,
-                     int max_maptrack_frames)
+                     int max_maptrack_frames, unsigned int options)
 {
     struct grant_table *gt;
+    unsigned int max_grant_version = options & XEN_DOMCTL_GRANT_version_mask;
     int ret = -ENOMEM;
 
+    if ( max_grant_version == XEN_DOMCTL_GRANT_version_default )
+        max_grant_version = opt_gnttab_max_version;
+    if ( !max_grant_version )
+    {
+        dprintk(XENLOG_INFO, "%pd: invalid grant table version 0 requested\n",
+                d);
+        return -EINVAL;
+    }
+    if ( max_grant_version > opt_gnttab_max_version )
+    {
+        dprintk(XENLOG_INFO,
+                "%pd: requested grant version (%u) greater than supported (%u)\n",
+                d, max_grant_version, opt_gnttab_max_version);
+        return -EINVAL;
+    }
+    if ( unlikely(max_page >= PFN_DOWN(TB(16))) && is_pv_domain(d) &&
+         max_grant_version < 2 )
+        dprintk(XENLOG_INFO,
+                "%pd: host memory above 16Tb and grant table v2 disabled\n",
+                d);
+
     /* Default to maximum value if no value was specified */
     if ( max_grant_frames < 0 )
         max_grant_frames = opt_max_grant_frames;
@@ -1947,6 +1970,7 @@ int grant_table_init(struct domain *d, int max_grant_frames,
     gt->gt_version = 1;
     gt->max_grant_frames = max_grant_frames;
     gt->max_maptrack_frames = max_maptrack_frames;
+    gt->max_version = max_grant_version;
 
     /* Install the structure early to simplify the error path. */
     gt->domain = d;
@@ -3076,7 +3100,7 @@ gnttab_set_version(XEN_GUEST_HANDLE_PARAM(gnttab_set_version_t) uop)
         goto out;
 
     res = -ENOSYS;
-    if ( op.version == 2 && opt_gnttab_max_version == 1 )
+    if ( op.version == 2 && gt->max_version == 1 )
         goto out; /* Behave as before set_version was introduced. */
 
     res = 0;
diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h
index 51017b47bc..0ec57614bd 100644
--- a/xen/include/public/domctl.h
+++ b/xen/include/public/domctl.h
@@ -89,14 +89,20 @@ struct xen_domctl_createdomain {
     /*
      * Various domain limits, which impact the quantity of resources
      * (global mapping space, xenheap, etc) a guest may consume.  For
-     * max_grant_frames and max_maptrack_frames, < 0 means "use the
-     * default maximum value in the hypervisor".
+     * max_grant_frames, max_maptrack_frames and max_gnttab_version < 0
+     * means "use the default maximum value in the hypervisor".
      */
     uint32_t max_vcpus;
     uint32_t max_evtchn_port;
     int32_t max_grant_frames;
     int32_t max_maptrack_frames;
 
+/* Grant version, use low 4 bits. */
+#define XEN_DOMCTL_GRANT_version_mask    0xf
+#define XEN_DOMCTL_GRANT_version_default 0xf
+
+    uint32_t grant_opts;
+
     /* Per-vCPU buffer size in bytes.  0 to disable. */
     uint32_t vmtrace_size;
 
diff --git a/xen/include/xen/config.h b/xen/include/xen/config.h
index b76222ecf6..37b42c756a 100644
--- a/xen/include/xen/config.h
+++ b/xen/include/xen/config.h
@@ -81,6 +81,7 @@
 #define KB(_kb)     (_AC(_kb, ULL) << 10)
 #define MB(_mb)     (_AC(_mb, ULL) << 20)
 #define GB(_gb)     (_AC(_gb, ULL) << 30)
+#define TB(_tb)     (_AC(_tb, ULL) << 40)
 
 #define IS_ALIGNED(val, align) (((val) & ((align) - 1)) == 0)
 
diff --git a/xen/include/xen/grant_table.h b/xen/include/xen/grant_table.h
index 41713e2726..fe6225346f 100644
--- a/xen/include/xen/grant_table.h
+++ b/xen/include/xen/grant_table.h
@@ -36,7 +36,7 @@ extern unsigned int opt_max_grant_frames;
 
 /* Create/destroy per-domain grant table context. */
 int grant_table_init(struct domain *d, int max_grant_frames,
-                     int max_maptrack_frames);
+                     int max_maptrack_frames, unsigned int options);
 void grant_table_destroy(
     struct domain *d);
 void grant_table_init_vcpu(struct vcpu *v);
@@ -67,7 +67,8 @@ int gnttab_acquire_resource(
 
 static inline int grant_table_init(struct domain *d,
                                    int max_grant_frames,
-                                   int max_maptrack_frames)
+                                   int max_maptrack_frames,
+                                   unsigned int options)
 {
     return 0;
 }
-- 
2.33.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH for-4.16 v3] gnttab: allow setting max version per-domain
  2021-10-28  9:59 [PATCH for-4.16 v3] gnttab: allow setting max version per-domain Roger Pau Monne
@ 2021-10-28 12:12 ` Ian Jackson
  2021-10-28 13:03   ` Roger Pau Monné
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Jackson @ 2021-10-28 12:12 UTC (permalink / raw)
  To: Roger Pau Monne
  Cc: xen-devel, Wei Liu, Andrew Cooper, George Dunlap, Jan Beulich,
	Julien Grall, Stefano Stabellini, Anthony PERARD, Juergen Gross,
	Christian Lindig, David Scott, Volodymyr Babchuk

Roger Pau Monne writes ("[PATCH for-4.16 v3] gnttab: allow setting max version per-domain"):
> diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in
> index 55c4881205..21a39adb70 100644
> --- a/docs/man/xl.cfg.5.pod.in
> +++ b/docs/man/xl.cfg.5.pod.in
> @@ -580,6 +580,12 @@ to have. This value controls how many pages of foreign domains can be accessed
>  via the grant mechanism by this domain. The default value is settable via
>  L<xl.conf(5)>.
>  
> +=item B<max_grant_version=NUMBER>
> +
> +Specify the maximum grant table version the domain is allowed to use. Current
> +supported versions are 1 and 2. The default value is settable via
> +L<xl.conf(5)>.


Firstly, review from my maintainer hat:

In the lower levels of this stack, I'm not sure why you chose -1 for
"default", when 0 is not (and never will be) used ?

> diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-xenstore-domain.c
> index 6836002f0b..7cd1aa8f7c 100644
> --- a/tools/helpers/init-xenstore-domain.c
> +++ b/tools/helpers/init-xenstore-domain.c
> @@ -88,6 +88,7 @@ static int build(xc_interface *xch)
>           */
>          .max_grant_frames = 4,
>          .max_maptrack_frames = 128,
> +        .grant_opts = 1,
>      };

I think this sets the max gnttab version for xenstore stub domains to
1 ?  That's not mentioned in your commit message or your release
discussion.


Secondly, the release question:

> Release rationale:
> 
> We have had a bunch of security issues involving grant table v2 (382,
> 379, 268, 255) which could have been avoided by limiting the grant
> table version available to guests. This can be currently done using a
> global host parameter, but it's certainly more helpful to be able to
> do it on a per domain basis from the toolstack.

Let me think this through.

Upside:

So the advantage is to have a mitigation for possible (but, perhaps,
likely) future security bugs.  We don't change the default here, so
the default configuration is still vulnerable.

We have this mitigation already but only on a per-host command line
basis, so you (1) have to reboot (2) can't use it if you have any
guests that need v2.  (2) is less of a problem than it sounds because
even with the selective mitigation you will remain vulnerable to those
guests.  So the main advantage is having to reboot the guests but not
the hosts.

Downside:

> Changes to the hypervisor by this patch are fairly minimal, as there
> are already checks for the max grant table version allowed, so the
> main change there is moving the max grant table version limit inside
> the domain struct and plumbing it through the toolstrack.

Right.

> I think the risk here is quite low for libxl/xl, because it's
> extensively tested by osstest, so the main risk would be breaking the
> Ocaml stubs, which could go unnoticed as those are not actually tested
> by osstest.

I will want a review by ocaml folks.  Christian ?

In particular, I would like an opinion from the ocaml tooling
maintainers about whether there is a risk of this feature breaking
things *if it's not used*.


I am not sure about the implications for migration.  Might using this
cause migration to fail for some guests ?

   Note that when using the default grant version the specific max
   version in use by the domain is not migrated. Any guests should be
   able to cope with the max grant version changing across migrations,
   and if a specific guest relies on a maximum grant version being
   unconditionally available it should be specified on the configuration
   file.

Only if the feature is *not* used, I guess.  Ie, this is the status
quo.   So I don't think there is any release risk there.


If this change does cause problems, it is deep throughout the stack,
but not entangled with anything else, so I think we could revert it ?


If we can get good answers to all of this, ideally I would like to see
this committed by the end of tomorrow.  I plan to cut RC1 on Monday.

I don't currently want to rule out allowing this to go in early next
week but that is getting considerably less desirable.


Thanks,
Ian.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH for-4.16 v3] gnttab: allow setting max version per-domain
  2021-10-28 12:12 ` Ian Jackson
@ 2021-10-28 13:03   ` Roger Pau Monné
  2021-10-28 14:11     ` Ian Jackson
  0 siblings, 1 reply; 4+ messages in thread
From: Roger Pau Monné @ 2021-10-28 13:03 UTC (permalink / raw)
  To: Ian Jackson
  Cc: xen-devel, Wei Liu, Andrew Cooper, George Dunlap, Jan Beulich,
	Julien Grall, Stefano Stabellini, Anthony PERARD, Juergen Gross,
	Christian Lindig, David Scott, Volodymyr Babchuk

On Thu, Oct 28, 2021 at 01:12:31PM +0100, Ian Jackson wrote:
> Roger Pau Monne writes ("[PATCH for-4.16 v3] gnttab: allow setting max version per-domain"):
> > diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in
> > index 55c4881205..21a39adb70 100644
> > --- a/docs/man/xl.cfg.5.pod.in
> > +++ b/docs/man/xl.cfg.5.pod.in
> > @@ -580,6 +580,12 @@ to have. This value controls how many pages of foreign domains can be accessed
> >  via the grant mechanism by this domain. The default value is settable via
> >  L<xl.conf(5)>.
> >  
> > +=item B<max_grant_version=NUMBER>
> > +
> > +Specify the maximum grant table version the domain is allowed to use. Current
> > +supported versions are 1 and 2. The default value is settable via
> > +L<xl.conf(5)>.
> 
> 
> Firstly, review from my maintainer hat:
> 
> In the lower levels of this stack, I'm not sure why you chose -1 for
> "default", when 0 is not (and never will be) used ?

No, I actually had plans to use 0 to signal no grant table support for
the guest, see:

https://lore.kernel.org/xen-devel/20210922082123.54374-7-roger.pau@citrix.com/

> > diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-xenstore-domain.c
> > index 6836002f0b..7cd1aa8f7c 100644
> > --- a/tools/helpers/init-xenstore-domain.c
> > +++ b/tools/helpers/init-xenstore-domain.c
> > @@ -88,6 +88,7 @@ static int build(xc_interface *xch)
> >           */
> >          .max_grant_frames = 4,
> >          .max_maptrack_frames = 128,
> > +        .grant_opts = 1,
> >      };
> 
> I think this sets the max gnttab version for xenstore stub domains to
> 1 ?  That's not mentioned in your commit message or your release
> discussion.

Indeed. AFAICT MiniOS only supports grant table v1, and the grant
related parameters max_maptrack_frames and max_grant_frames are
already set based on DEFAULT_MAX_GRANTS and NR_GRANT_FRAMES
respectively as defined in MiniOS code.

Would you like me to this to the commit message:

"xenstored stubdomains are limited to grant table v1 because the
current MiniOS code used to build them only has support for grants v1.
There are existing limits set for xenstored stubdomains at creation
time that already match the defaults in MiniOS."

> 
> Secondly, the release question:
> 
> > Release rationale:
> > 
> > We have had a bunch of security issues involving grant table v2 (382,
> > 379, 268, 255) which could have been avoided by limiting the grant
> > table version available to guests. This can be currently done using a
> > global host parameter, but it's certainly more helpful to be able to
> > do it on a per domain basis from the toolstack.
> 
> Let me think this through.
> 
> Upside:
> 
> So the advantage is to have a mitigation for possible (but, perhaps,
> likely) future security bugs.  We don't change the default here, so
> the default configuration is still vulnerable.
> 
> We have this mitigation already but only on a per-host command line
> basis, so you (1) have to reboot (2) can't use it if you have any
> guests that need v2.  (2) is less of a problem than it sounds because
> even with the selective mitigation you will remain vulnerable to those
> guests.  So the main advantage is having to reboot the guests but not
> the hosts.
> 
> Downside:
> 
> > Changes to the hypervisor by this patch are fairly minimal, as there
> > are already checks for the max grant table version allowed, so the
> > main change there is moving the max grant table version limit inside
> > the domain struct and plumbing it through the toolstrack.
> 
> Right.
> 
> > I think the risk here is quite low for libxl/xl, because it's
> > extensively tested by osstest, so the main risk would be breaking the
> > Ocaml stubs, which could go unnoticed as those are not actually tested
> > by osstest.
> 
> I will want a review by ocaml folks.  Christian ?
> 
> In particular, I would like an opinion from the ocaml tooling
> maintainers about whether there is a risk of this feature breaking
> things *if it's not used*.
> 
> 
> I am not sure about the implications for migration.  Might using this
> cause migration to fail for some guests ?
> 
>    Note that when using the default grant version the specific max
>    version in use by the domain is not migrated. Any guests should be
>    able to cope with the max grant version changing across migrations,
>    and if a specific guest relies on a maximum grant version being
>    unconditionally available it should be specified on the configuration
>    file.
> 
> Only if the feature is *not* used, I guess.  Ie, this is the status
> quo.   So I don't think there is any release risk there.

This was raised by Jan in a previous version, the discussion can be
found here:

https://lore.kernel.org/xen-devel/0b58667f-b6bc-d5b5-2dd1-0c8996367319@suse.com/

The issue could arise if a guest that strictly needs grant v2 is
migrated from a host that has v2 as the default max version to another
box that has v1 as the max version. If the guest config file doesn't
explicitly specify that the guest requires grant v2 migration will
succeed, but the guest will likely fail to resume properly.

This is already the current behavior if a guest is migrated from a
host not having gnttab=max-ver set to one having gnttab=max-ver:1.

> 
> If this change does cause problems, it is deep throughout the stack,
> but not entangled with anything else, so I think we could revert it ?

I think so, unless we start piling a lot of other toolstack changes on
top it's unlikely to be a problem to revert.

> If we can get good answers to all of this, ideally I would like to see
> this committed by the end of tomorrow.  I plan to cut RC1 on Monday.

Thanks, Roger.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH for-4.16 v3] gnttab: allow setting max version per-domain
  2021-10-28 13:03   ` Roger Pau Monné
@ 2021-10-28 14:11     ` Ian Jackson
  0 siblings, 0 replies; 4+ messages in thread
From: Ian Jackson @ 2021-10-28 14:11 UTC (permalink / raw)
  To: Roger Pau Monné
  Cc: xen-devel, Wei Liu, Andrew Cooper, George Dunlap, Jan Beulich,
	Julien Grall, Stefano Stabellini, Anthony PERARD, Juergen Gross,
	Christian Lindig, David Scott, Volodymyr Babchuk

Roger Pau Monné writes ("Re: [PATCH for-4.16 v3] gnttab: allow setting max version per-domain"):
> Would you like me to this to the commit message:
> 
> "xenstored stubdomains are limited to grant table v1 because the
> current MiniOS code used to build them only has support for grants v1.
> There are existing limits set for xenstored stubdomains at creation
> time that already match the defaults in MiniOS."

Yes, please.

> > I am not sure about the implications for migration.  Might using this
> > cause migration to fail for some guests ?
> > 
> >    Note that when using the default grant version the specific max
> >    version in use by the domain is not migrated. Any guests should be
> >    able to cope with the max grant version changing across migrations,
> >    and if a specific guest relies on a maximum grant version being
> >    unconditionally available it should be specified on the configuration
> >    file.
> > 
> > Only if the feature is *not* used, I guess.  Ie, this is the status
> > quo.   So I don't think there is any release risk there.
> 
> This was raised by Jan in a previous version, the discussion can be
> found here:
> 
> https://lore.kernel.org/xen-devel/0b58667f-b6bc-d5b5-2dd1-0c8996367319@suse.com/
> 
> The issue could arise if a guest that strictly needs grant v2 is
> migrated from a host that has v2 as the default max version to another
> box that has v1 as the max version. If the guest config file doesn't
> explicitly specify that the guest requires grant v2 migration will
> succeed, but the guest will likely fail to resume properly.
> 
> This is already the current behavior if a guest is migrated from a
> host not having gnttab=max-ver set to one having gnttab=max-ver:1.

Right.  I don't think this is the correct behaviour but the patch is
moving in the right direction.

> > If we can get good answers to all of this, ideally I would like to see
> > this committed by the end of tomorrow.  I plan to cut RC1 on Monday.

Thanks.


Tools ack: with the commit message change discussed above,

Reviewed-by: Ian Jackson <iwj@xenproject.org>


I have no further release concerns but a formal release-ack will have
to wait for review of the ocaml parts.

Ian.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-10-28 14:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-28  9:59 [PATCH for-4.16 v3] gnttab: allow setting max version per-domain Roger Pau Monne
2021-10-28 12:12 ` Ian Jackson
2021-10-28 13:03   ` Roger Pau Monné
2021-10-28 14:11     ` Ian Jackson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.