* Re: [PATCH 2/2] x86/hvm: honor guest's option when updating secondary system time for guest
2014-07-07 23:18 ` [PATCH 2/2] x86/hvm: honor guest's option when updating secondary system time for guest Feng Wu
@ 2014-07-08 10:08 ` Andrew Cooper
2014-07-09 1:39 ` Wu, Feng
2014-07-08 16:13 ` Konrad Rzeszutek Wilk
` (2 subsequent siblings)
3 siblings, 1 reply; 26+ messages in thread
From: Andrew Cooper @ 2014-07-08 10:08 UTC (permalink / raw)
To: Feng Wu, xen-devel; +Cc: linux, keir, tim, jbeulich
On 08/07/14 00:18, Feng Wu wrote:
> In this patch, we add a new hypervisor which allows guests to enable
> SMAP check when Xen is updating the secondary system time for guest.
> The SMAP check for this update is disabled by default.
>
> Reported-by: Sander Eikelenboom <linux@eikelenboom.it>
> Signed-off-by: Feng Wu <feng.wu@intel.com>
This patch uses the same v->arch.smap_check_policy variable as the
previous patch, meaning its value is unconditionally
SMAP_CHECK_HONOR_CPL_AC other than the short window while the runstate
area is being updated.
As a result, there appears to be no way for this to cause working
updates to a system time living in guest userspace.
~Andrew
> ---
> xen/arch/x86/domain.c | 6 ++++++
> xen/arch/x86/hvm/hvm.c | 2 ++
> xen/arch/x86/time.c | 12 +++++++++++-
> xen/include/asm-x86/domain.h | 9 ++++++++-
> xen/include/public/vcpu.h | 10 ++++++++++
> 5 files changed, 37 insertions(+), 2 deletions(-)
>
> diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
> index b0c8810..a787c46 100644
> --- a/xen/arch/x86/domain.c
> +++ b/xen/arch/x86/domain.c
> @@ -1053,6 +1053,12 @@ arch_do_vcpu_op(
> break;
> }
>
> + case VCPUOP_enable_smap_check_vcpu_time_memory_area:
> + {
> + v->arch.enable_smap_check = 1;
> + break;
> + }
> +
> case VCPUOP_get_physid:
> {
> struct vcpu_get_physid cpu_id;
> diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
> index ef2411c..a922711 100644
> --- a/xen/arch/x86/hvm/hvm.c
> +++ b/xen/arch/x86/hvm/hvm.c
> @@ -4629,6 +4629,7 @@ static long hvm_vcpu_op(
> case VCPUOP_stop_singleshot_timer:
> case VCPUOP_register_vcpu_info:
> case VCPUOP_register_vcpu_time_memory_area:
> + case VCPUOP_enable_smap_check_vcpu_time_memory_area:
> rc = do_vcpu_op(cmd, vcpuid, arg);
> break;
> default:
> @@ -4688,6 +4689,7 @@ static long hvm_vcpu_op_compat32(
> case VCPUOP_stop_singleshot_timer:
> case VCPUOP_register_vcpu_info:
> case VCPUOP_register_vcpu_time_memory_area:
> + case VCPUOP_enable_smap_check_vcpu_time_memory_area:
> rc = compat_vcpu_op(cmd, vcpuid, arg);
> break;
> default:
> diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c
> index a4e1656..338381e 100644
> --- a/xen/arch/x86/time.c
> +++ b/xen/arch/x86/time.c
> @@ -821,7 +821,7 @@ static void __update_vcpu_system_time(struct vcpu *v, int force)
> v->arch.pv_vcpu.pending_system_time = _u;
> }
>
> -bool_t update_secondary_system_time(const struct vcpu *v,
> +bool_t update_secondary_system_time(struct vcpu *v,
> struct vcpu_time_info *u)
> {
> XEN_GUEST_HANDLE(vcpu_time_info_t) user_u = v->arch.time_info_guest;
> @@ -829,9 +829,16 @@ bool_t update_secondary_system_time(const struct vcpu *v,
> if ( guest_handle_is_null(user_u) )
> return 1;
>
> + if ( v->arch.enable_smap_check )
> + v->arch.smap_check_policy = SMAP_CHECK_ENABLED;
> +
> /* 1. Update userspace version. */
> if ( __copy_field_to_guest(user_u, u, version) == sizeof(u->version) )
> + {
> + if ( v->arch.enable_smap_check )
> + v->arch.smap_check_policy = SMAP_CHECK_HONOR_CPL_AC;
> return 0;
> + }
> wmb();
> /* 2. Update all other userspace fields. */
> __copy_to_guest(user_u, u, 1);
> @@ -840,6 +847,9 @@ bool_t update_secondary_system_time(const struct vcpu *v,
> u->version = version_update_end(u->version);
> __copy_field_to_guest(user_u, u, version);
>
> + if ( v->arch.enable_smap_check )
> + v->arch.smap_check_policy = SMAP_CHECK_HONOR_CPL_AC;
> +
> return 1;
> }
>
> diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h
> index d7cac4f..051fed0 100644
> --- a/xen/include/asm-x86/domain.h
> +++ b/xen/include/asm-x86/domain.h
> @@ -455,6 +455,13 @@ struct arch_vcpu
> * SMAP_CHECK_DISABLED - disable the check
> */
> uint8_t smap_check_policy;
> +
> + /*
> + * This is a flag to indicate that whether the guest wants to enable
> + * SMAP check when Xen is updating the secondary system time from it.
> + */
> + bool_t enable_smap_check;
> + uint16_t pad;
> } __cacheline_aligned;
>
> #define SMAP_CHECK_HONOR_CPL_AC 0
> @@ -466,7 +473,7 @@ struct arch_vcpu
> #define hvm_svm hvm_vcpu.u.svm
>
> bool_t update_runstate_area(struct vcpu *);
> -bool_t update_secondary_system_time(const struct vcpu *,
> +bool_t update_secondary_system_time(struct vcpu *,
> struct vcpu_time_info *);
>
> void vcpu_show_execution_state(struct vcpu *);
> diff --git a/xen/include/public/vcpu.h b/xen/include/public/vcpu.h
> index e888daf..d348395 100644
> --- a/xen/include/public/vcpu.h
> +++ b/xen/include/public/vcpu.h
> @@ -227,6 +227,16 @@ struct vcpu_register_time_memory_area {
> typedef struct vcpu_register_time_memory_area vcpu_register_time_memory_area_t;
> DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t);
>
> +/*
> + * Flags to tell Xen whether we need to do the SMAP check when updating
> + * the secondary copy of the vcpu time when SMAP is enabled. Since the
> + * memory location for the secondary copy of the vcpu time may be mapped
> + * into userspace by guests intendedly, we let the guest to determine
> + * whether the check is needed. The default behavior of hypevisor is
> + * not doing the check.
> + */
> +#define VCPUOP_enable_smap_check_vcpu_time_memory_area 14
> +
> #endif /* __XEN_PUBLIC_VCPU_H__ */
>
> /*
^ permalink raw reply [flat|nested] 26+ messages in thread* Re: [PATCH 2/2] x86/hvm: honor guest's option when updating secondary system time for guest
2014-07-08 10:08 ` Andrew Cooper
@ 2014-07-09 1:39 ` Wu, Feng
0 siblings, 0 replies; 26+ messages in thread
From: Wu, Feng @ 2014-07-09 1:39 UTC (permalink / raw)
To: Andrew Cooper, xen-devel@lists.xen.org
Cc: linux@eikelenboom.it, keir@xen.org, tim@xen.org,
jbeulich@suse.com
> -----Original Message-----
> From: Andrew Cooper [mailto:andrew.cooper3@citrix.com]
> Sent: Tuesday, July 08, 2014 6:08 PM
> To: Wu, Feng; xen-devel@lists.xen.org
> Cc: tim@xen.org; linux@eikelenboom.it; jbeulich@suse.com; keir@xen.org
> Subject: Re: [Xen-devel] [PATCH 2/2] x86/hvm: honor guest's option when
> updating secondary system time for guest
>
> On 08/07/14 00:18, Feng Wu wrote:
> > In this patch, we add a new hypervisor which allows guests to enable
> > SMAP check when Xen is updating the secondary system time for guest.
> > The SMAP check for this update is disabled by default.
> >
> > Reported-by: Sander Eikelenboom <linux@eikelenboom.it>
> > Signed-off-by: Feng Wu <feng.wu@intel.com>
>
> This patch uses the same v->arch.smap_check_policy variable as the
> previous patch, meaning its value is unconditionally
> SMAP_CHECK_HONOR_CPL_AC other than the short window while the
> runstate
> area is being updated.
Guests can enable it by hypercall ' VCPUOP_enable_smap_check_vcpu_time_memory_area ',
If the guest calls this hypercall, v->arch.enable_smap_check will be set to 1, so when updating
the secondary system time for guest, v->arch.smap_check_policy will be set to SMAP_CHECK_ENABLED.
Thanks,
Feng
>
> As a result, there appears to be no way for this to cause working
> updates to a system time living in guest userspace.
>
> ~Andrew
>
> > ---
> > xen/arch/x86/domain.c | 6 ++++++
> > xen/arch/x86/hvm/hvm.c | 2 ++
> > xen/arch/x86/time.c | 12 +++++++++++-
> > xen/include/asm-x86/domain.h | 9 ++++++++-
> > xen/include/public/vcpu.h | 10 ++++++++++
> > 5 files changed, 37 insertions(+), 2 deletions(-)
> >
> > diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
> > index b0c8810..a787c46 100644
> > --- a/xen/arch/x86/domain.c
> > +++ b/xen/arch/x86/domain.c
> > @@ -1053,6 +1053,12 @@ arch_do_vcpu_op(
> > break;
> > }
> >
> > + case VCPUOP_enable_smap_check_vcpu_time_memory_area:
> > + {
> > + v->arch.enable_smap_check = 1;
> > + break;
> > + }
> > +
> > case VCPUOP_get_physid:
> > {
> > struct vcpu_get_physid cpu_id;
> > diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
> > index ef2411c..a922711 100644
> > --- a/xen/arch/x86/hvm/hvm.c
> > +++ b/xen/arch/x86/hvm/hvm.c
> > @@ -4629,6 +4629,7 @@ static long hvm_vcpu_op(
> > case VCPUOP_stop_singleshot_timer:
> > case VCPUOP_register_vcpu_info:
> > case VCPUOP_register_vcpu_time_memory_area:
> > + case VCPUOP_enable_smap_check_vcpu_time_memory_area:
> > rc = do_vcpu_op(cmd, vcpuid, arg);
> > break;
> > default:
> > @@ -4688,6 +4689,7 @@ static long hvm_vcpu_op_compat32(
> > case VCPUOP_stop_singleshot_timer:
> > case VCPUOP_register_vcpu_info:
> > case VCPUOP_register_vcpu_time_memory_area:
> > + case VCPUOP_enable_smap_check_vcpu_time_memory_area:
> > rc = compat_vcpu_op(cmd, vcpuid, arg);
> > break;
> > default:
> > diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c
> > index a4e1656..338381e 100644
> > --- a/xen/arch/x86/time.c
> > +++ b/xen/arch/x86/time.c
> > @@ -821,7 +821,7 @@ static void __update_vcpu_system_time(struct vcpu
> *v, int force)
> > v->arch.pv_vcpu.pending_system_time = _u;
> > }
> >
> > -bool_t update_secondary_system_time(const struct vcpu *v,
> > +bool_t update_secondary_system_time(struct vcpu *v,
> > struct vcpu_time_info *u)
> > {
> > XEN_GUEST_HANDLE(vcpu_time_info_t) user_u =
> v->arch.time_info_guest;
> > @@ -829,9 +829,16 @@ bool_t update_secondary_system_time(const
> struct vcpu *v,
> > if ( guest_handle_is_null(user_u) )
> > return 1;
> >
> > + if ( v->arch.enable_smap_check )
> > + v->arch.smap_check_policy = SMAP_CHECK_ENABLED;
> > +
> > /* 1. Update userspace version. */
> > if ( __copy_field_to_guest(user_u, u, version) == sizeof(u->version) )
> > + {
> > + if ( v->arch.enable_smap_check )
> > + v->arch.smap_check_policy =
> SMAP_CHECK_HONOR_CPL_AC;
> > return 0;
> > + }
> > wmb();
> > /* 2. Update all other userspace fields. */
> > __copy_to_guest(user_u, u, 1);
> > @@ -840,6 +847,9 @@ bool_t update_secondary_system_time(const struct
> vcpu *v,
> > u->version = version_update_end(u->version);
> > __copy_field_to_guest(user_u, u, version);
> >
> > + if ( v->arch.enable_smap_check )
> > + v->arch.smap_check_policy = SMAP_CHECK_HONOR_CPL_AC;
> > +
> > return 1;
> > }
> >
> > diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h
> > index d7cac4f..051fed0 100644
> > --- a/xen/include/asm-x86/domain.h
> > +++ b/xen/include/asm-x86/domain.h
> > @@ -455,6 +455,13 @@ struct arch_vcpu
> > * SMAP_CHECK_DISABLED - disable the check
> > */
> > uint8_t smap_check_policy;
> > +
> > + /*
> > + * This is a flag to indicate that whether the guest wants to enable
> > + * SMAP check when Xen is updating the secondary system time from
> it.
> > + */
> > + bool_t enable_smap_check;
> > + uint16_t pad;
> > } __cacheline_aligned;
> >
> > #define SMAP_CHECK_HONOR_CPL_AC 0
> > @@ -466,7 +473,7 @@ struct arch_vcpu
> > #define hvm_svm hvm_vcpu.u.svm
> >
> > bool_t update_runstate_area(struct vcpu *);
> > -bool_t update_secondary_system_time(const struct vcpu *,
> > +bool_t update_secondary_system_time(struct vcpu *,
> > struct vcpu_time_info *);
> >
> > void vcpu_show_execution_state(struct vcpu *);
> > diff --git a/xen/include/public/vcpu.h b/xen/include/public/vcpu.h
> > index e888daf..d348395 100644
> > --- a/xen/include/public/vcpu.h
> > +++ b/xen/include/public/vcpu.h
> > @@ -227,6 +227,16 @@ struct vcpu_register_time_memory_area {
> > typedef struct vcpu_register_time_memory_area
> vcpu_register_time_memory_area_t;
> > DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t);
> >
> > +/*
> > + * Flags to tell Xen whether we need to do the SMAP check when updating
> > + * the secondary copy of the vcpu time when SMAP is enabled. Since the
> > + * memory location for the secondary copy of the vcpu time may be mapped
> > + * into userspace by guests intendedly, we let the guest to determine
> > + * whether the check is needed. The default behavior of hypevisor is
> > + * not doing the check.
> > + */
> > +#define VCPUOP_enable_smap_check_vcpu_time_memory_area 14
> > +
> > #endif /* __XEN_PUBLIC_VCPU_H__ */
> >
> > /*
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH 2/2] x86/hvm: honor guest's option when updating secondary system time for guest
2014-07-07 23:18 ` [PATCH 2/2] x86/hvm: honor guest's option when updating secondary system time for guest Feng Wu
2014-07-08 10:08 ` Andrew Cooper
@ 2014-07-08 16:13 ` Konrad Rzeszutek Wilk
2014-07-09 1:52 ` Wu, Feng
2014-07-10 11:00 ` Tim Deegan
2014-07-23 12:19 ` Jan Beulich
3 siblings, 1 reply; 26+ messages in thread
From: Konrad Rzeszutek Wilk @ 2014-07-08 16:13 UTC (permalink / raw)
To: Feng Wu; +Cc: tim, linux, keir, jbeulich, xen-devel
On Tue, Jul 08, 2014 at 07:18:18AM +0800, Feng Wu wrote:
> In this patch, we add a new hypervisor which allows guests to enable
> SMAP check when Xen is updating the secondary system time for guest.
> The SMAP check for this update is disabled by default.
>
> Reported-by: Sander Eikelenboom <linux@eikelenboom.it>
> Signed-off-by: Feng Wu <feng.wu@intel.com>
> ---
> xen/arch/x86/domain.c | 6 ++++++
> xen/arch/x86/hvm/hvm.c | 2 ++
> xen/arch/x86/time.c | 12 +++++++++++-
> xen/include/asm-x86/domain.h | 9 ++++++++-
> xen/include/public/vcpu.h | 10 ++++++++++
> 5 files changed, 37 insertions(+), 2 deletions(-)
>
> diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
> index b0c8810..a787c46 100644
> --- a/xen/arch/x86/domain.c
> +++ b/xen/arch/x86/domain.c
> @@ -1053,6 +1053,12 @@ arch_do_vcpu_op(
> break;
> }
>
> + case VCPUOP_enable_smap_check_vcpu_time_memory_area:
> + {
> + v->arch.enable_smap_check = 1;
> + break;
> + }
> +
> case VCPUOP_get_physid:
> {
> struct vcpu_get_physid cpu_id;
> diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
> index ef2411c..a922711 100644
> --- a/xen/arch/x86/hvm/hvm.c
> +++ b/xen/arch/x86/hvm/hvm.c
> @@ -4629,6 +4629,7 @@ static long hvm_vcpu_op(
> case VCPUOP_stop_singleshot_timer:
> case VCPUOP_register_vcpu_info:
> case VCPUOP_register_vcpu_time_memory_area:
> + case VCPUOP_enable_smap_check_vcpu_time_memory_area:
> rc = do_vcpu_op(cmd, vcpuid, arg);
> break;
> default:
> @@ -4688,6 +4689,7 @@ static long hvm_vcpu_op_compat32(
> case VCPUOP_stop_singleshot_timer:
> case VCPUOP_register_vcpu_info:
> case VCPUOP_register_vcpu_time_memory_area:
> + case VCPUOP_enable_smap_check_vcpu_time_memory_area:
> rc = compat_vcpu_op(cmd, vcpuid, arg);
> break;
> default:
> diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c
> index a4e1656..338381e 100644
> --- a/xen/arch/x86/time.c
> +++ b/xen/arch/x86/time.c
> @@ -821,7 +821,7 @@ static void __update_vcpu_system_time(struct vcpu *v, int force)
> v->arch.pv_vcpu.pending_system_time = _u;
> }
>
> -bool_t update_secondary_system_time(const struct vcpu *v,
> +bool_t update_secondary_system_time(struct vcpu *v,
> struct vcpu_time_info *u)
> {
> XEN_GUEST_HANDLE(vcpu_time_info_t) user_u = v->arch.time_info_guest;
> @@ -829,9 +829,16 @@ bool_t update_secondary_system_time(const struct vcpu *v,
> if ( guest_handle_is_null(user_u) )
> return 1;
>
> + if ( v->arch.enable_smap_check )
> + v->arch.smap_check_policy = SMAP_CHECK_ENABLED;
> +
> /* 1. Update userspace version. */
> if ( __copy_field_to_guest(user_u, u, version) == sizeof(u->version) )
> + {
> + if ( v->arch.enable_smap_check )
> + v->arch.smap_check_policy = SMAP_CHECK_HONOR_CPL_AC;
> return 0;
> + }
> wmb();
> /* 2. Update all other userspace fields. */
> __copy_to_guest(user_u, u, 1);
> @@ -840,6 +847,9 @@ bool_t update_secondary_system_time(const struct vcpu *v,
> u->version = version_update_end(u->version);
> __copy_field_to_guest(user_u, u, version);
>
> + if ( v->arch.enable_smap_check )
> + v->arch.smap_check_policy = SMAP_CHECK_HONOR_CPL_AC;
> +
> return 1;
> }
>
> diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h
> index d7cac4f..051fed0 100644
> --- a/xen/include/asm-x86/domain.h
> +++ b/xen/include/asm-x86/domain.h
> @@ -455,6 +455,13 @@ struct arch_vcpu
> * SMAP_CHECK_DISABLED - disable the check
> */
> uint8_t smap_check_policy;
> +
> + /*
> + * This is a flag to indicate that whether the guest wants to enable
> + * SMAP check when Xen is updating the secondary system time from it.
> + */
> + bool_t enable_smap_check;
> + uint16_t pad;
> } __cacheline_aligned;
>
> #define SMAP_CHECK_HONOR_CPL_AC 0
> @@ -466,7 +473,7 @@ struct arch_vcpu
> #define hvm_svm hvm_vcpu.u.svm
>
> bool_t update_runstate_area(struct vcpu *);
> -bool_t update_secondary_system_time(const struct vcpu *,
> +bool_t update_secondary_system_time(struct vcpu *,
> struct vcpu_time_info *);
>
> void vcpu_show_execution_state(struct vcpu *);
> diff --git a/xen/include/public/vcpu.h b/xen/include/public/vcpu.h
> index e888daf..d348395 100644
> --- a/xen/include/public/vcpu.h
> +++ b/xen/include/public/vcpu.h
> @@ -227,6 +227,16 @@ struct vcpu_register_time_memory_area {
> typedef struct vcpu_register_time_memory_area vcpu_register_time_memory_area_t;
> DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t);
>
> +/*
> + * Flags to tell Xen whether we need to do the SMAP check when updating
> + * the secondary copy of the vcpu time when SMAP is enabled. Since the
> + * memory location for the secondary copy of the vcpu time may be mapped
> + * into userspace by guests intendedly, we let the guest to determine
What is 'intendedly'?
> + * whether the check is needed. The default behavior of hypevisor is
> + * not doing the check.
Under what conditions do we want the guest to do the check? What is
the impact (performance) if we do the check?
Why don't we want by default do the check?
> + */
> +#define VCPUOP_enable_smap_check_vcpu_time_memory_area 14
> +
> #endif /* __XEN_PUBLIC_VCPU_H__ */
>
> /*
> --
> 1.8.3.1
>
^ permalink raw reply [flat|nested] 26+ messages in thread* Re: [PATCH 2/2] x86/hvm: honor guest's option when updating secondary system time for guest
2014-07-08 16:13 ` Konrad Rzeszutek Wilk
@ 2014-07-09 1:52 ` Wu, Feng
0 siblings, 0 replies; 26+ messages in thread
From: Wu, Feng @ 2014-07-09 1:52 UTC (permalink / raw)
To: Konrad Rzeszutek Wilk
Cc: tim@xen.org, linux@eikelenboom.it, keir@xen.org,
jbeulich@suse.com, xen-devel@lists.xen.org
> -----Original Message-----
> From: Konrad Rzeszutek Wilk [mailto:konrad.wilk@oracle.com]
> Sent: Wednesday, July 09, 2014 12:14 AM
> To: Wu, Feng
> Cc: xen-devel@lists.xen.org; keir@xen.org; jbeulich@suse.com; tim@xen.org;
> linux@eikelenboom.it
> Subject: Re: [PATCH 2/2] x86/hvm: honor guest's option when updating
> secondary system time for guest
>
> On Tue, Jul 08, 2014 at 07:18:18AM +0800, Feng Wu wrote:
> > In this patch, we add a new hypervisor which allows guests to enable
> > SMAP check when Xen is updating the secondary system time for guest.
> > The SMAP check for this update is disabled by default.
> >
> > Reported-by: Sander Eikelenboom <linux@eikelenboom.it>
> > Signed-off-by: Feng Wu <feng.wu@intel.com>
> > ---
> > xen/arch/x86/domain.c | 6 ++++++
> > xen/arch/x86/hvm/hvm.c | 2 ++
> > xen/arch/x86/time.c | 12 +++++++++++-
> > xen/include/asm-x86/domain.h | 9 ++++++++-
> > xen/include/public/vcpu.h | 10 ++++++++++
> > 5 files changed, 37 insertions(+), 2 deletions(-)
> >
> > diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
> > index b0c8810..a787c46 100644
> > --- a/xen/arch/x86/domain.c
> > +++ b/xen/arch/x86/domain.c
> > @@ -1053,6 +1053,12 @@ arch_do_vcpu_op(
> > break;
> > }
> >
> > + case VCPUOP_enable_smap_check_vcpu_time_memory_area:
> > + {
> > + v->arch.enable_smap_check = 1;
> > + break;
> > + }
> > +
> > case VCPUOP_get_physid:
> > {
> > struct vcpu_get_physid cpu_id;
> > diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
> > index ef2411c..a922711 100644
> > --- a/xen/arch/x86/hvm/hvm.c
> > +++ b/xen/arch/x86/hvm/hvm.c
> > @@ -4629,6 +4629,7 @@ static long hvm_vcpu_op(
> > case VCPUOP_stop_singleshot_timer:
> > case VCPUOP_register_vcpu_info:
> > case VCPUOP_register_vcpu_time_memory_area:
> > + case VCPUOP_enable_smap_check_vcpu_time_memory_area:
> > rc = do_vcpu_op(cmd, vcpuid, arg);
> > break;
> > default:
> > @@ -4688,6 +4689,7 @@ static long hvm_vcpu_op_compat32(
> > case VCPUOP_stop_singleshot_timer:
> > case VCPUOP_register_vcpu_info:
> > case VCPUOP_register_vcpu_time_memory_area:
> > + case VCPUOP_enable_smap_check_vcpu_time_memory_area:
> > rc = compat_vcpu_op(cmd, vcpuid, arg);
> > break;
> > default:
> > diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c
> > index a4e1656..338381e 100644
> > --- a/xen/arch/x86/time.c
> > +++ b/xen/arch/x86/time.c
> > @@ -821,7 +821,7 @@ static void __update_vcpu_system_time(struct vcpu
> *v, int force)
> > v->arch.pv_vcpu.pending_system_time = _u;
> > }
> >
> > -bool_t update_secondary_system_time(const struct vcpu *v,
> > +bool_t update_secondary_system_time(struct vcpu *v,
> > struct vcpu_time_info *u)
> > {
> > XEN_GUEST_HANDLE(vcpu_time_info_t) user_u =
> v->arch.time_info_guest;
> > @@ -829,9 +829,16 @@ bool_t update_secondary_system_time(const
> struct vcpu *v,
> > if ( guest_handle_is_null(user_u) )
> > return 1;
> >
> > + if ( v->arch.enable_smap_check )
> > + v->arch.smap_check_policy = SMAP_CHECK_ENABLED;
> > +
> > /* 1. Update userspace version. */
> > if ( __copy_field_to_guest(user_u, u, version) == sizeof(u->version) )
> > + {
> > + if ( v->arch.enable_smap_check )
> > + v->arch.smap_check_policy =
> SMAP_CHECK_HONOR_CPL_AC;
> > return 0;
> > + }
> > wmb();
> > /* 2. Update all other userspace fields. */
> > __copy_to_guest(user_u, u, 1);
> > @@ -840,6 +847,9 @@ bool_t update_secondary_system_time(const struct
> vcpu *v,
> > u->version = version_update_end(u->version);
> > __copy_field_to_guest(user_u, u, version);
> >
> > + if ( v->arch.enable_smap_check )
> > + v->arch.smap_check_policy = SMAP_CHECK_HONOR_CPL_AC;
> > +
> > return 1;
> > }
> >
> > diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h
> > index d7cac4f..051fed0 100644
> > --- a/xen/include/asm-x86/domain.h
> > +++ b/xen/include/asm-x86/domain.h
> > @@ -455,6 +455,13 @@ struct arch_vcpu
> > * SMAP_CHECK_DISABLED - disable the check
> > */
> > uint8_t smap_check_policy;
> > +
> > + /*
> > + * This is a flag to indicate that whether the guest wants to enable
> > + * SMAP check when Xen is updating the secondary system time from
> it.
> > + */
> > + bool_t enable_smap_check;
> > + uint16_t pad;
> > } __cacheline_aligned;
> >
> > #define SMAP_CHECK_HONOR_CPL_AC 0
> > @@ -466,7 +473,7 @@ struct arch_vcpu
> > #define hvm_svm hvm_vcpu.u.svm
> >
> > bool_t update_runstate_area(struct vcpu *);
> > -bool_t update_secondary_system_time(const struct vcpu *,
> > +bool_t update_secondary_system_time(struct vcpu *,
> > struct vcpu_time_info *);
> >
> > void vcpu_show_execution_state(struct vcpu *);
> > diff --git a/xen/include/public/vcpu.h b/xen/include/public/vcpu.h
> > index e888daf..d348395 100644
> > --- a/xen/include/public/vcpu.h
> > +++ b/xen/include/public/vcpu.h
> > @@ -227,6 +227,16 @@ struct vcpu_register_time_memory_area {
> > typedef struct vcpu_register_time_memory_area
> vcpu_register_time_memory_area_t;
> > DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t);
> >
> > +/*
> > + * Flags to tell Xen whether we need to do the SMAP check when updating
> > + * the secondary copy of the vcpu time when SMAP is enabled. Since the
> > + * memory location for the secondary copy of the vcpu time may be mapped
> > + * into userspace by guests intendedly, we let the guest to determine
>
> What is 'intendedly'?
>
> > + * whether the check is needed. The default behavior of hypevisor is
> > + * not doing the check.
>
> Under what conditions do we want the guest to do the check? What is
> the impact (performance) if we do the check?
>
> Why don't we want by default do the check?
If SMAP is enabled, supervisor mode accesses to user-accessible pages are not
allowed when CPL=0 & EFLAGS.AC=0.
- If the address passed to hypervisor is in guest kernel space, we need to do
the check. If the check fails, it means some abnormal happened.
- If the address passed to hypervisor is in guest user space, which means guest
wants hypervisor to put the information to its user-space address. In this case,
We shouldn't do the check, or a SMAP violation will be triggered and this is not
what the guest wants.
Thanks,
Feng
>
> > + */
> > +#define VCPUOP_enable_smap_check_vcpu_time_memory_area 14
> > +
> > #endif /* __XEN_PUBLIC_VCPU_H__ */
> >
> > /*
> > --
> > 1.8.3.1
> >
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH 2/2] x86/hvm: honor guest's option when updating secondary system time for guest
2014-07-07 23:18 ` [PATCH 2/2] x86/hvm: honor guest's option when updating secondary system time for guest Feng Wu
2014-07-08 10:08 ` Andrew Cooper
2014-07-08 16:13 ` Konrad Rzeszutek Wilk
@ 2014-07-10 11:00 ` Tim Deegan
2014-07-23 12:16 ` Jan Beulich
2014-07-23 12:19 ` Jan Beulich
3 siblings, 1 reply; 26+ messages in thread
From: Tim Deegan @ 2014-07-10 11:00 UTC (permalink / raw)
To: Feng Wu; +Cc: linux, keir, jbeulich, xen-devel
At 07:18 +0800 on 08 Jul (1404800298), Feng Wu wrote:
> In this patch, we add a new hypervisor which allows guests to enable
> SMAP check when Xen is updating the secondary system time for guest.
> The SMAP check for this update is disabled by default.
Again, it seems like we should never do SMAP checks here, since (a)
this is a hypervisor operation, totally independent of whether the
vcpu is in user mode or not, (b) this happens asynchronously to the
guest so we can't raise a fault, an (c) this is explicitly _supposed_
to access a user-space mapping.
Tim.
> Reported-by: Sander Eikelenboom <linux@eikelenboom.it>
> Signed-off-by: Feng Wu <feng.wu@intel.com>
> ---
> xen/arch/x86/domain.c | 6 ++++++
> xen/arch/x86/hvm/hvm.c | 2 ++
> xen/arch/x86/time.c | 12 +++++++++++-
> xen/include/asm-x86/domain.h | 9 ++++++++-
> xen/include/public/vcpu.h | 10 ++++++++++
> 5 files changed, 37 insertions(+), 2 deletions(-)
>
> diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
> index b0c8810..a787c46 100644
> --- a/xen/arch/x86/domain.c
> +++ b/xen/arch/x86/domain.c
> @@ -1053,6 +1053,12 @@ arch_do_vcpu_op(
> break;
> }
>
> + case VCPUOP_enable_smap_check_vcpu_time_memory_area:
> + {
> + v->arch.enable_smap_check = 1;
> + break;
> + }
> +
> case VCPUOP_get_physid:
> {
> struct vcpu_get_physid cpu_id;
> diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
> index ef2411c..a922711 100644
> --- a/xen/arch/x86/hvm/hvm.c
> +++ b/xen/arch/x86/hvm/hvm.c
> @@ -4629,6 +4629,7 @@ static long hvm_vcpu_op(
> case VCPUOP_stop_singleshot_timer:
> case VCPUOP_register_vcpu_info:
> case VCPUOP_register_vcpu_time_memory_area:
> + case VCPUOP_enable_smap_check_vcpu_time_memory_area:
> rc = do_vcpu_op(cmd, vcpuid, arg);
> break;
> default:
> @@ -4688,6 +4689,7 @@ static long hvm_vcpu_op_compat32(
> case VCPUOP_stop_singleshot_timer:
> case VCPUOP_register_vcpu_info:
> case VCPUOP_register_vcpu_time_memory_area:
> + case VCPUOP_enable_smap_check_vcpu_time_memory_area:
> rc = compat_vcpu_op(cmd, vcpuid, arg);
> break;
> default:
> diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c
> index a4e1656..338381e 100644
> --- a/xen/arch/x86/time.c
> +++ b/xen/arch/x86/time.c
> @@ -821,7 +821,7 @@ static void __update_vcpu_system_time(struct vcpu *v, int force)
> v->arch.pv_vcpu.pending_system_time = _u;
> }
>
> -bool_t update_secondary_system_time(const struct vcpu *v,
> +bool_t update_secondary_system_time(struct vcpu *v,
> struct vcpu_time_info *u)
> {
> XEN_GUEST_HANDLE(vcpu_time_info_t) user_u = v->arch.time_info_guest;
> @@ -829,9 +829,16 @@ bool_t update_secondary_system_time(const struct vcpu *v,
> if ( guest_handle_is_null(user_u) )
> return 1;
>
> + if ( v->arch.enable_smap_check )
> + v->arch.smap_check_policy = SMAP_CHECK_ENABLED;
> +
¼> /* 1. Update userspace version. */
> if ( __copy_field_to_guest(user_u, u, version) == sizeof(u->version) )
> + {
> + if ( v->arch.enable_smap_check )
> + v->arch.smap_check_policy = SMAP_CHECK_HONOR_CPL_AC;
> return 0;
> + }
> wmb();
> /* 2. Update all other userspace fields. */
> __copy_to_guest(user_u, u, 1);
> @@ -840,6 +847,9 @@ bool_t update_secondary_system_time(const struct vcpu *v,
> u->version = version_update_end(u->version);
> __copy_field_to_guest(user_u, u, version);
>
> + if ( v->arch.enable_smap_check )
> + v->arch.smap_check_policy = SMAP_CHECK_HONOR_CPL_AC;
> +
> return 1;
> }
>
> diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h
> index d7cac4f..051fed0 100644
> --- a/xen/include/asm-x86/domain.h
> +++ b/xen/include/asm-x86/domain.h
> @@ -455,6 +455,13 @@ struct arch_vcpu
> * SMAP_CHECK_DISABLED - disable the check
> */
> uint8_t smap_check_policy;
> +
> + /*
> + * This is a flag to indicate that whether the guest wants to enable
> + * SMAP check when Xen is updating the secondary system time from it.
> + */
> + bool_t enable_smap_check;
> + uint16_t pad;
> } __cacheline_aligned;
>
> #define SMAP_CHECK_HONOR_CPL_AC 0
> @@ -466,7 +473,7 @@ struct arch_vcpu
> #define hvm_svm hvm_vcpu.u.svm
>
> bool_t update_runstate_area(struct vcpu *);
> -bool_t update_secondary_system_time(const struct vcpu *,
> +bool_t update_secondary_system_time(struct vcpu *,
> struct vcpu_time_info *);
>
> void vcpu_show_execution_state(struct vcpu *);
> diff --git a/xen/include/public/vcpu.h b/xen/include/public/vcpu.h
> index e888daf..d348395 100644
> --- a/xen/include/public/vcpu.h
> +++ b/xen/include/public/vcpu.h
> @@ -227,6 +227,16 @@ struct vcpu_register_time_memory_area {
> typedef struct vcpu_register_time_memory_area vcpu_register_time_memory_area_t;
> DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t);
>
> +/*
> + * Flags to tell Xen whether we need to do the SMAP check when updating
> + * the secondary copy of the vcpu time when SMAP is enabled. Since the
> + * memory location for the secondary copy of the vcpu time may be mapped
> + * into userspace by guests intendedly, we let the guest to determine
> + * whether the check is needed. The default behavior of hypevisor is
> + * not doing the check.
> + */
> +#define VCPUOP_enable_smap_check_vcpu_time_memory_area 14
> +
> #endif /* __XEN_PUBLIC_VCPU_H__ */
>
> /*
> --
> 1.8.3.1
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 26+ messages in thread* Re: [PATCH 2/2] x86/hvm: honor guest's option when updating secondary system time for guest
2014-07-10 11:00 ` Tim Deegan
@ 2014-07-23 12:16 ` Jan Beulich
0 siblings, 0 replies; 26+ messages in thread
From: Jan Beulich @ 2014-07-23 12:16 UTC (permalink / raw)
To: Tim Deegan; +Cc: linux, keir, Feng Wu, xen-devel
>>> On 10.07.14 at 13:00, <tim@xen.org> wrote:
> At 07:18 +0800 on 08 Jul (1404800298), Feng Wu wrote:
>> In this patch, we add a new hypervisor which allows guests to enable
>> SMAP check when Xen is updating the secondary system time for guest.
>> The SMAP check for this update is disabled by default.
>
> Again, it seems like we should never do SMAP checks here, since (a)
> this is a hypervisor operation, totally independent of whether the
> vcpu is in user mode or not, (b) this happens asynchronously to the
> guest so we can't raise a fault, an (c) this is explicitly _supposed_
> to access a user-space mapping.
Not exactly: It is supposed to access a page that has a user space
mapping, but there's no implication that the update has to happen
through this user space mapping. In fact it is more likely for this not
to be the case, as I'd expect the user mode mapping to be r/o
while the mapping via which the update is to happen obviously has
to be r/w).
Jan
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH 2/2] x86/hvm: honor guest's option when updating secondary system time for guest
2014-07-07 23:18 ` [PATCH 2/2] x86/hvm: honor guest's option when updating secondary system time for guest Feng Wu
` (2 preceding siblings ...)
2014-07-10 11:00 ` Tim Deegan
@ 2014-07-23 12:19 ` Jan Beulich
2014-07-25 4:30 ` Wu, Feng
3 siblings, 1 reply; 26+ messages in thread
From: Jan Beulich @ 2014-07-23 12:19 UTC (permalink / raw)
To: Feng Wu; +Cc: linux, tim, keir, xen-devel
>>> On 08.07.14 at 01:18, <feng.wu@intel.com> wrote:
> --- a/xen/include/public/vcpu.h
> +++ b/xen/include/public/vcpu.h
> @@ -227,6 +227,16 @@ struct vcpu_register_time_memory_area {
> typedef struct vcpu_register_time_memory_area
> vcpu_register_time_memory_area_t;
> DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t);
>
> +/*
> + * Flags to tell Xen whether we need to do the SMAP check when updating
> + * the secondary copy of the vcpu time when SMAP is enabled. Since the
> + * memory location for the secondary copy of the vcpu time may be mapped
> + * into userspace by guests intendedly, we let the guest to determine
> + * whether the check is needed. The default behavior of hypevisor is
> + * not doing the check.
> + */
> +#define VCPUOP_enable_smap_check_vcpu_time_memory_area 14
I think the new op to be VCPUOP_register_vcpu_time_memory_area_smap,
identical to VCPUOP_register_vcpu_time_memory_area apart from also
setting the flag, would be more natural. But considering what I just wrote
in the reply to Tim I guess we can expect a nun-user mapping to be
presented here anyway, i.e. we wouldn't need to new operation at all.
Jan
^ permalink raw reply [flat|nested] 26+ messages in thread* Re: [PATCH 2/2] x86/hvm: honor guest's option when updating secondary system time for guest
2014-07-23 12:19 ` Jan Beulich
@ 2014-07-25 4:30 ` Wu, Feng
2014-07-25 7:25 ` Jan Beulich
0 siblings, 1 reply; 26+ messages in thread
From: Wu, Feng @ 2014-07-25 4:30 UTC (permalink / raw)
To: Jan Beulich
Cc: linux@eikelenboom.it, tim@xen.org, keir@xen.org,
xen-devel@lists.xen.org
> -----Original Message-----
> From: Jan Beulich [mailto:JBeulich@suse.com]
> Sent: Wednesday, July 23, 2014 8:19 PM
> To: Wu, Feng
> Cc: linux@eikelenboom.it; xen-devel@lists.xen.org; konrad.wilk@oracle.com;
> keir@xen.org; tim@xen.org
> Subject: Re: [PATCH 2/2] x86/hvm: honor guest's option when updating
> secondary system time for guest
>
> >>> On 08.07.14 at 01:18, <feng.wu@intel.com> wrote:
> > --- a/xen/include/public/vcpu.h
> > +++ b/xen/include/public/vcpu.h
> > @@ -227,6 +227,16 @@ struct vcpu_register_time_memory_area {
> > typedef struct vcpu_register_time_memory_area
> > vcpu_register_time_memory_area_t;
> > DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t);
> >
> > +/*
> > + * Flags to tell Xen whether we need to do the SMAP check when updating
> > + * the secondary copy of the vcpu time when SMAP is enabled. Since the
> > + * memory location for the secondary copy of the vcpu time may be mapped
> > + * into userspace by guests intendedly, we let the guest to determine
> > + * whether the check is needed. The default behavior of hypevisor is
> > + * not doing the check.
> > + */
> > +#define VCPUOP_enable_smap_check_vcpu_time_memory_area 14
>
> I think the new op to be VCPUOP_register_vcpu_time_memory_area_smap,
> identical to VCPUOP_register_vcpu_time_memory_area apart from also
> setting the flag, would be more natural. But considering what I just wrote
> in the reply to Tim I guess we can expect a nun-user mapping to be
> presented here anyway, i.e. we wouldn't need to new operation at all.
Do you mean since the user-paging is r/o, guest will pass a r/w kernel page to
Xen for updating the system time. So we don't need to do the SMAP check
in this case?
Thanks,
Feng
>
> Jan
^ permalink raw reply [flat|nested] 26+ messages in thread* Re: [PATCH 2/2] x86/hvm: honor guest's option when updating secondary system time for guest
2014-07-25 4:30 ` Wu, Feng
@ 2014-07-25 7:25 ` Jan Beulich
2014-07-25 7:33 ` Wu, Feng
0 siblings, 1 reply; 26+ messages in thread
From: Jan Beulich @ 2014-07-25 7:25 UTC (permalink / raw)
To: Feng Wu
Cc: linux@eikelenboom.it, tim@xen.org, keir@xen.org,
xen-devel@lists.xen.org
>>> On 25.07.14 at 06:30, <feng.wu@intel.com> wrote:
>
>> -----Original Message-----
>> From: Jan Beulich [mailto:JBeulich@suse.com]
>> Sent: Wednesday, July 23, 2014 8:19 PM
>> To: Wu, Feng
>> Cc: linux@eikelenboom.it; xen-devel@lists.xen.org; konrad.wilk@oracle.com;
>> keir@xen.org; tim@xen.org
>> Subject: Re: [PATCH 2/2] x86/hvm: honor guest's option when updating
>> secondary system time for guest
>>
>> >>> On 08.07.14 at 01:18, <feng.wu@intel.com> wrote:
>> > --- a/xen/include/public/vcpu.h
>> > +++ b/xen/include/public/vcpu.h
>> > @@ -227,6 +227,16 @@ struct vcpu_register_time_memory_area {
>> > typedef struct vcpu_register_time_memory_area
>> > vcpu_register_time_memory_area_t;
>> > DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t);
>> >
>> > +/*
>> > + * Flags to tell Xen whether we need to do the SMAP check when updating
>> > + * the secondary copy of the vcpu time when SMAP is enabled. Since the
>> > + * memory location for the secondary copy of the vcpu time may be mapped
>> > + * into userspace by guests intendedly, we let the guest to determine
>> > + * whether the check is needed. The default behavior of hypevisor is
>> > + * not doing the check.
>> > + */
>> > +#define VCPUOP_enable_smap_check_vcpu_time_memory_area 14
>>
>> I think the new op to be VCPUOP_register_vcpu_time_memory_area_smap,
>> identical to VCPUOP_register_vcpu_time_memory_area apart from also
>> setting the flag, would be more natural. But considering what I just wrote
>> in the reply to Tim I guess we can expect a nun-user mapping to be
>> presented here anyway, i.e. we wouldn't need to new operation at all.
>
> Do you mean since the user-paging is r/o, guest will pass a r/w kernel page
> to
> Xen for updating the system time. So we don't need to do the SMAP check
> in this case?
If the user page is r/o, it's VA obviously can't be used for updating by
Xen. Hence the kernel has to provide a r/w mapped VA. That should be
subject to SMAP checking (consistent with the runstate area handling),
to make sure it's not a user accessible mapping.
Jan
^ permalink raw reply [flat|nested] 26+ messages in thread* Re: [PATCH 2/2] x86/hvm: honor guest's option when updating secondary system time for guest
2014-07-25 7:25 ` Jan Beulich
@ 2014-07-25 7:33 ` Wu, Feng
2014-07-25 7:39 ` Jan Beulich
0 siblings, 1 reply; 26+ messages in thread
From: Wu, Feng @ 2014-07-25 7:33 UTC (permalink / raw)
To: Jan Beulich
Cc: linux@eikelenboom.it, tim@xen.org, keir@xen.org,
xen-devel@lists.xen.org
> -----Original Message-----
> From: Jan Beulich [mailto:JBeulich@suse.com]
> Sent: Friday, July 25, 2014 3:26 PM
> To: Wu, Feng
> Cc: linux@eikelenboom.it; xen-devel@lists.xen.org; konrad.wilk@oracle.com;
> keir@xen.org; tim@xen.org
> Subject: RE: [PATCH 2/2] x86/hvm: honor guest's option when updating
> secondary system time for guest
>
> >>> On 25.07.14 at 06:30, <feng.wu@intel.com> wrote:
>
> >
> >> -----Original Message-----
> >> From: Jan Beulich [mailto:JBeulich@suse.com]
> >> Sent: Wednesday, July 23, 2014 8:19 PM
> >> To: Wu, Feng
> >> Cc: linux@eikelenboom.it; xen-devel@lists.xen.org;
> konrad.wilk@oracle.com;
> >> keir@xen.org; tim@xen.org
> >> Subject: Re: [PATCH 2/2] x86/hvm: honor guest's option when updating
> >> secondary system time for guest
> >>
> >> >>> On 08.07.14 at 01:18, <feng.wu@intel.com> wrote:
> >> > --- a/xen/include/public/vcpu.h
> >> > +++ b/xen/include/public/vcpu.h
> >> > @@ -227,6 +227,16 @@ struct vcpu_register_time_memory_area {
> >> > typedef struct vcpu_register_time_memory_area
> >> > vcpu_register_time_memory_area_t;
> >> > DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t);
> >> >
> >> > +/*
> >> > + * Flags to tell Xen whether we need to do the SMAP check when
> updating
> >> > + * the secondary copy of the vcpu time when SMAP is enabled. Since the
> >> > + * memory location for the secondary copy of the vcpu time may be
> mapped
> >> > + * into userspace by guests intendedly, we let the guest to determine
> >> > + * whether the check is needed. The default behavior of hypevisor is
> >> > + * not doing the check.
> >> > + */
> >> > +#define VCPUOP_enable_smap_check_vcpu_time_memory_area 14
> >>
> >> I think the new op to be VCPUOP_register_vcpu_time_memory_area_smap,
> >> identical to VCPUOP_register_vcpu_time_memory_area apart from also
> >> setting the flag, would be more natural. But considering what I just wrote
> >> in the reply to Tim I guess we can expect a nun-user mapping to be
> >> presented here anyway, i.e. we wouldn't need to new operation at all.
> >
> > Do you mean since the user-paging is r/o, guest will pass a r/w kernel page
> > to
> > Xen for updating the system time. So we don't need to do the SMAP check
> > in this case?
>
> If the user page is r/o, it's VA obviously can't be used for updating by
> Xen. Hence the kernel has to provide a r/w mapped VA. That should be
> subject to SMAP checking (consistent with the runstate area handling),
> to make sure it's not a user accessible mapping.
But there are two possible problems here:
1. Is it possible that guest passes a user r/w page to update the system time information?
2. Even the user page is r/o, the kernel can still use it to update the system time info when WP is disabled.
Thanks,
Feng
>
> Jan
^ permalink raw reply [flat|nested] 26+ messages in thread* Re: [PATCH 2/2] x86/hvm: honor guest's option when updating secondary system time for guest
2014-07-25 7:33 ` Wu, Feng
@ 2014-07-25 7:39 ` Jan Beulich
2014-07-25 8:03 ` Wu, Feng
0 siblings, 1 reply; 26+ messages in thread
From: Jan Beulich @ 2014-07-25 7:39 UTC (permalink / raw)
To: Feng Wu
Cc: linux@eikelenboom.it, tim@xen.org, keir@xen.org,
xen-devel@lists.xen.org
>>> On 25.07.14 at 09:33, <feng.wu@intel.com> wrote:
>
>> -----Original Message-----
>> From: Jan Beulich [mailto:JBeulich@suse.com]
>> Sent: Friday, July 25, 2014 3:26 PM
>> To: Wu, Feng
>> Cc: linux@eikelenboom.it; xen-devel@lists.xen.org; konrad.wilk@oracle.com;
>> keir@xen.org; tim@xen.org
>> Subject: RE: [PATCH 2/2] x86/hvm: honor guest's option when updating
>> secondary system time for guest
>>
>> >>> On 25.07.14 at 06:30, <feng.wu@intel.com> wrote:
>>
>> >
>> >> -----Original Message-----
>> >> From: Jan Beulich [mailto:JBeulich@suse.com]
>> >> Sent: Wednesday, July 23, 2014 8:19 PM
>> >> To: Wu, Feng
>> >> Cc: linux@eikelenboom.it; xen-devel@lists.xen.org;
>> konrad.wilk@oracle.com;
>> >> keir@xen.org; tim@xen.org
>> >> Subject: Re: [PATCH 2/2] x86/hvm: honor guest's option when updating
>> >> secondary system time for guest
>> >>
>> >> >>> On 08.07.14 at 01:18, <feng.wu@intel.com> wrote:
>> >> > --- a/xen/include/public/vcpu.h
>> >> > +++ b/xen/include/public/vcpu.h
>> >> > @@ -227,6 +227,16 @@ struct vcpu_register_time_memory_area {
>> >> > typedef struct vcpu_register_time_memory_area
>> >> > vcpu_register_time_memory_area_t;
>> >> > DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t);
>> >> >
>> >> > +/*
>> >> > + * Flags to tell Xen whether we need to do the SMAP check when
>> updating
>> >> > + * the secondary copy of the vcpu time when SMAP is enabled. Since the
>> >> > + * memory location for the secondary copy of the vcpu time may be
>> mapped
>> >> > + * into userspace by guests intendedly, we let the guest to determine
>> >> > + * whether the check is needed. The default behavior of hypevisor is
>> >> > + * not doing the check.
>> >> > + */
>> >> > +#define VCPUOP_enable_smap_check_vcpu_time_memory_area 14
>> >>
>> >> I think the new op to be VCPUOP_register_vcpu_time_memory_area_smap,
>> >> identical to VCPUOP_register_vcpu_time_memory_area apart from also
>> >> setting the flag, would be more natural. But considering what I just wrote
>> >> in the reply to Tim I guess we can expect a nun-user mapping to be
>> >> presented here anyway, i.e. we wouldn't need to new operation at all.
>> >
>> > Do you mean since the user-paging is r/o, guest will pass a r/w kernel page
>> > to
>> > Xen for updating the system time. So we don't need to do the SMAP check
>> > in this case?
>>
>> If the user page is r/o, it's VA obviously can't be used for updating by
>> Xen. Hence the kernel has to provide a r/w mapped VA. That should be
>> subject to SMAP checking (consistent with the runstate area handling),
>> to make sure it's not a user accessible mapping.
>
> But there are two possible problems here:
> 1. Is it possible that guest passes a user r/w page to update the system
> time information?
The guest kernel may pass a page that was originally mapped r/w-
kernel, but the mapping later gets (say inadvertently) changed to
r/w-user. That's why I think the SMAP checking ought to be done
here.
> 2. Even the user page is r/o, the kernel can still use it to update the
> system time info when WP is disabled.
The kernel can - for its own accesses to the page - do whatever
it wants. It can't, however, control Xen's updating of it, and Xen
won't do that with CR0.WP clear (leaving aside Aravindh's PV
mem-access work, where this option is currently being discussed).
Jan
^ permalink raw reply [flat|nested] 26+ messages in thread* Re: [PATCH 2/2] x86/hvm: honor guest's option when updating secondary system time for guest
2014-07-25 7:39 ` Jan Beulich
@ 2014-07-25 8:03 ` Wu, Feng
2014-07-25 8:31 ` Jan Beulich
0 siblings, 1 reply; 26+ messages in thread
From: Wu, Feng @ 2014-07-25 8:03 UTC (permalink / raw)
To: Jan Beulich
Cc: linux@eikelenboom.it, tim@xen.org, keir@xen.org,
xen-devel@lists.xen.org
> -----Original Message-----
> From: Jan Beulich [mailto:JBeulich@suse.com]
> Sent: Friday, July 25, 2014 3:40 PM
> To: Wu, Feng
> Cc: linux@eikelenboom.it; xen-devel@lists.xen.org; konrad.wilk@oracle.com;
> keir@xen.org; tim@xen.org
> Subject: RE: [PATCH 2/2] x86/hvm: honor guest's option when updating
> secondary system time for guest
>
> >>> On 25.07.14 at 09:33, <feng.wu@intel.com> wrote:
>
> >
> >> -----Original Message-----
> >> From: Jan Beulich [mailto:JBeulich@suse.com]
> >> Sent: Friday, July 25, 2014 3:26 PM
> >> To: Wu, Feng
> >> Cc: linux@eikelenboom.it; xen-devel@lists.xen.org;
> konrad.wilk@oracle.com;
> >> keir@xen.org; tim@xen.org
> >> Subject: RE: [PATCH 2/2] x86/hvm: honor guest's option when updating
> >> secondary system time for guest
> >>
> >> >>> On 25.07.14 at 06:30, <feng.wu@intel.com> wrote:
> >>
> >> >
> >> >> -----Original Message-----
> >> >> From: Jan Beulich [mailto:JBeulich@suse.com]
> >> >> Sent: Wednesday, July 23, 2014 8:19 PM
> >> >> To: Wu, Feng
> >> >> Cc: linux@eikelenboom.it; xen-devel@lists.xen.org;
> >> konrad.wilk@oracle.com;
> >> >> keir@xen.org; tim@xen.org
> >> >> Subject: Re: [PATCH 2/2] x86/hvm: honor guest's option when updating
> >> >> secondary system time for guest
> >> >>
> >> >> >>> On 08.07.14 at 01:18, <feng.wu@intel.com> wrote:
> >> >> > --- a/xen/include/public/vcpu.h
> >> >> > +++ b/xen/include/public/vcpu.h
> >> >> > @@ -227,6 +227,16 @@ struct vcpu_register_time_memory_area {
> >> >> > typedef struct vcpu_register_time_memory_area
> >> >> > vcpu_register_time_memory_area_t;
> >> >> > DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t);
> >> >> >
> >> >> > +/*
> >> >> > + * Flags to tell Xen whether we need to do the SMAP check when
> >> updating
> >> >> > + * the secondary copy of the vcpu time when SMAP is enabled. Since
> the
> >> >> > + * memory location for the secondary copy of the vcpu time may be
> >> mapped
> >> >> > + * into userspace by guests intendedly, we let the guest to determine
> >> >> > + * whether the check is needed. The default behavior of hypevisor is
> >> >> > + * not doing the check.
> >> >> > + */
> >> >> > +#define VCPUOP_enable_smap_check_vcpu_time_memory_area
> 14
> >> >>
> >> >> I think the new op to be
> VCPUOP_register_vcpu_time_memory_area_smap,
> >> >> identical to VCPUOP_register_vcpu_time_memory_area apart from also
> >> >> setting the flag, would be more natural. But considering what I just
> wrote
> >> >> in the reply to Tim I guess we can expect a nun-user mapping to be
> >> >> presented here anyway, i.e. we wouldn't need to new operation at all.
> >> >
> >> > Do you mean since the user-paging is r/o, guest will pass a r/w kernel page
> >> > to
> >> > Xen for updating the system time. So we don't need to do the SMAP check
> >> > in this case?
> >>
> >> If the user page is r/o, it's VA obviously can't be used for updating by
> >> Xen. Hence the kernel has to provide a r/w mapped VA. That should be
> >> subject to SMAP checking (consistent with the runstate area handling),
> >> to make sure it's not a user accessible mapping.
> >
> > But there are two possible problems here:
> > 1. Is it possible that guest passes a user r/w page to update the system
> > time information?
>
> The guest kernel may pass a page that was originally mapped r/w-
> kernel, but the mapping later gets (say inadvertently) changed to
> r/w-user. That's why I think the SMAP checking ought to be done
> here.
But in another case, as what we discussed before, if the guest intended to
pass a user r/w page to get the time information. Do we need to do the
SMAP checking for this?
>
> > 2. Even the user page is r/o, the kernel can still use it to update the
> > system time info when WP is disabled.
>
> The kernel can - for its own accesses to the page - do whatever
> it wants. It can't, however, control Xen's updating of it, and Xen
> won't do that with CR0.WP clear (leaving aside Aravindh's PV
> mem-access work, where this option is currently being discussed).
Just like my comments above, my point is in some case, guest may pass a
user page (r/o or r/w) to get the time information, I doubt whether the SMAP
checking should be done for this?
Thanks,
Feng
>
> Jan
^ permalink raw reply [flat|nested] 26+ messages in thread* Re: [PATCH 2/2] x86/hvm: honor guest's option when updating secondary system time for guest
2014-07-25 8:03 ` Wu, Feng
@ 2014-07-25 8:31 ` Jan Beulich
2014-07-25 8:35 ` Wu, Feng
2014-07-25 8:52 ` Andrew Cooper
0 siblings, 2 replies; 26+ messages in thread
From: Jan Beulich @ 2014-07-25 8:31 UTC (permalink / raw)
To: Feng Wu
Cc: linux@eikelenboom.it, tim@xen.org, keir@xen.org,
xen-devel@lists.xen.org
>>> On 25.07.14 at 10:03, <feng.wu@intel.com> wrote:
>
>> -----Original Message-----
>> From: Jan Beulich [mailto:JBeulich@suse.com]
>> Sent: Friday, July 25, 2014 3:40 PM
>> To: Wu, Feng
>> Cc: linux@eikelenboom.it; xen-devel@lists.xen.org; konrad.wilk@oracle.com;
>> keir@xen.org; tim@xen.org
>> Subject: RE: [PATCH 2/2] x86/hvm: honor guest's option when updating
>> secondary system time for guest
>>
>> >>> On 25.07.14 at 09:33, <feng.wu@intel.com> wrote:
>>
>> >
>> >> -----Original Message-----
>> >> From: Jan Beulich [mailto:JBeulich@suse.com]
>> >> Sent: Friday, July 25, 2014 3:26 PM
>> >> To: Wu, Feng
>> >> Cc: linux@eikelenboom.it; xen-devel@lists.xen.org;
>> konrad.wilk@oracle.com;
>> >> keir@xen.org; tim@xen.org
>> >> Subject: RE: [PATCH 2/2] x86/hvm: honor guest's option when updating
>> >> secondary system time for guest
>> >>
>> >> >>> On 25.07.14 at 06:30, <feng.wu@intel.com> wrote:
>> >>
>> >> >
>> >> >> -----Original Message-----
>> >> >> From: Jan Beulich [mailto:JBeulich@suse.com]
>> >> >> Sent: Wednesday, July 23, 2014 8:19 PM
>> >> >> To: Wu, Feng
>> >> >> Cc: linux@eikelenboom.it; xen-devel@lists.xen.org;
>> >> konrad.wilk@oracle.com;
>> >> >> keir@xen.org; tim@xen.org
>> >> >> Subject: Re: [PATCH 2/2] x86/hvm: honor guest's option when updating
>> >> >> secondary system time for guest
>> >> >>
>> >> >> >>> On 08.07.14 at 01:18, <feng.wu@intel.com> wrote:
>> >> >> > --- a/xen/include/public/vcpu.h
>> >> >> > +++ b/xen/include/public/vcpu.h
>> >> >> > @@ -227,6 +227,16 @@ struct vcpu_register_time_memory_area {
>> >> >> > typedef struct vcpu_register_time_memory_area
>> >> >> > vcpu_register_time_memory_area_t;
>> >> >> > DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t);
>> >> >> >
>> >> >> > +/*
>> >> >> > + * Flags to tell Xen whether we need to do the SMAP check when
>> >> updating
>> >> >> > + * the secondary copy of the vcpu time when SMAP is enabled. Since
>> the
>> >> >> > + * memory location for the secondary copy of the vcpu time may be
>> >> mapped
>> >> >> > + * into userspace by guests intendedly, we let the guest to determine
>> >> >> > + * whether the check is needed. The default behavior of hypevisor is
>> >> >> > + * not doing the check.
>> >> >> > + */
>> >> >> > +#define VCPUOP_enable_smap_check_vcpu_time_memory_area
>> 14
>> >> >>
>> >> >> I think the new op to be
>> VCPUOP_register_vcpu_time_memory_area_smap,
>> >> >> identical to VCPUOP_register_vcpu_time_memory_area apart from also
>> >> >> setting the flag, would be more natural. But considering what I just
>> wrote
>> >> >> in the reply to Tim I guess we can expect a nun-user mapping to be
>> >> >> presented here anyway, i.e. we wouldn't need to new operation at all.
>> >> >
>> >> > Do you mean since the user-paging is r/o, guest will pass a r/w kernel page
>> >> > to
>> >> > Xen for updating the system time. So we don't need to do the SMAP check
>> >> > in this case?
>> >>
>> >> If the user page is r/o, it's VA obviously can't be used for updating by
>> >> Xen. Hence the kernel has to provide a r/w mapped VA. That should be
>> >> subject to SMAP checking (consistent with the runstate area handling),
>> >> to make sure it's not a user accessible mapping.
>> >
>> > But there are two possible problems here:
>> > 1. Is it possible that guest passes a user r/w page to update the system
>> > time information?
>>
>> The guest kernel may pass a page that was originally mapped r/w-
>> kernel, but the mapping later gets (say inadvertently) changed to
>> r/w-user. That's why I think the SMAP checking ought to be done
>> here.
>
> But in another case, as what we discussed before, if the guest intended to
> pass a user r/w page to get the time information. Do we need to do the
> SMAP checking for this?
The question is whether we should bother supporting such insecure
kernels.
>> > 2. Even the user page is r/o, the kernel can still use it to update the
>> > system time info when WP is disabled.
>>
>> The kernel can - for its own accesses to the page - do whatever
>> it wants. It can't, however, control Xen's updating of it, and Xen
>> won't do that with CR0.WP clear (leaving aside Aravindh's PV
>> mem-access work, where this option is currently being discussed).
>
> Just like my comments above, my point is in some case, guest may pass a
> user page (r/o or r/w) to get the time information, I doubt whether the SMAP
> checking should be done for this?
If we want to allow kernels to expose the time data r/w to user mode,
then yes, we would need to avoid the SMAP check. But as said above,
I don't think helping kernels to be insecure is of any particular value.
Jan
^ permalink raw reply [flat|nested] 26+ messages in thread* Re: [PATCH 2/2] x86/hvm: honor guest's option when updating secondary system time for guest
2014-07-25 8:31 ` Jan Beulich
@ 2014-07-25 8:35 ` Wu, Feng
2014-07-25 8:52 ` Andrew Cooper
1 sibling, 0 replies; 26+ messages in thread
From: Wu, Feng @ 2014-07-25 8:35 UTC (permalink / raw)
To: Jan Beulich
Cc: linux@eikelenboom.it, tim@xen.org, keir@xen.org,
xen-devel@lists.xen.org
> -----Original Message-----
> From: Jan Beulich [mailto:JBeulich@suse.com]
> Sent: Friday, July 25, 2014 4:32 PM
> To: Wu, Feng
> Cc: linux@eikelenboom.it; xen-devel@lists.xen.org; konrad.wilk@oracle.com;
> keir@xen.org; tim@xen.org
> Subject: RE: [PATCH 2/2] x86/hvm: honor guest's option when updating
> secondary system time for guest
>
> >>> On 25.07.14 at 10:03, <feng.wu@intel.com> wrote:
>
> >
> >> -----Original Message-----
> >> From: Jan Beulich [mailto:JBeulich@suse.com]
> >> Sent: Friday, July 25, 2014 3:40 PM
> >> To: Wu, Feng
> >> Cc: linux@eikelenboom.it; xen-devel@lists.xen.org;
> konrad.wilk@oracle.com;
> >> keir@xen.org; tim@xen.org
> >> Subject: RE: [PATCH 2/2] x86/hvm: honor guest's option when updating
> >> secondary system time for guest
> >>
> >> >>> On 25.07.14 at 09:33, <feng.wu@intel.com> wrote:
> >>
> >> >
> >> >> -----Original Message-----
> >> >> From: Jan Beulich [mailto:JBeulich@suse.com]
> >> >> Sent: Friday, July 25, 2014 3:26 PM
> >> >> To: Wu, Feng
> >> >> Cc: linux@eikelenboom.it; xen-devel@lists.xen.org;
> >> konrad.wilk@oracle.com;
> >> >> keir@xen.org; tim@xen.org
> >> >> Subject: RE: [PATCH 2/2] x86/hvm: honor guest's option when updating
> >> >> secondary system time for guest
> >> >>
> >> >> >>> On 25.07.14 at 06:30, <feng.wu@intel.com> wrote:
> >> >>
> >> >> >
> >> >> >> -----Original Message-----
> >> >> >> From: Jan Beulich [mailto:JBeulich@suse.com]
> >> >> >> Sent: Wednesday, July 23, 2014 8:19 PM
> >> >> >> To: Wu, Feng
> >> >> >> Cc: linux@eikelenboom.it; xen-devel@lists.xen.org;
> >> >> konrad.wilk@oracle.com;
> >> >> >> keir@xen.org; tim@xen.org
> >> >> >> Subject: Re: [PATCH 2/2] x86/hvm: honor guest's option when
> updating
> >> >> >> secondary system time for guest
> >> >> >>
> >> >> >> >>> On 08.07.14 at 01:18, <feng.wu@intel.com> wrote:
> >> >> >> > --- a/xen/include/public/vcpu.h
> >> >> >> > +++ b/xen/include/public/vcpu.h
> >> >> >> > @@ -227,6 +227,16 @@ struct vcpu_register_time_memory_area {
> >> >> >> > typedef struct vcpu_register_time_memory_area
> >> >> >> > vcpu_register_time_memory_area_t;
> >> >> >> >
> DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t);
> >> >> >> >
> >> >> >> > +/*
> >> >> >> > + * Flags to tell Xen whether we need to do the SMAP check when
> >> >> updating
> >> >> >> > + * the secondary copy of the vcpu time when SMAP is enabled.
> Since
> >> the
> >> >> >> > + * memory location for the secondary copy of the vcpu time may be
> >> >> mapped
> >> >> >> > + * into userspace by guests intendedly, we let the guest to
> determine
> >> >> >> > + * whether the check is needed. The default behavior of hypevisor is
> >> >> >> > + * not doing the check.
> >> >> >> > + */
> >> >> >> > +#define VCPUOP_enable_smap_check_vcpu_time_memory_area
> >> 14
> >> >> >>
> >> >> >> I think the new op to be
> >> VCPUOP_register_vcpu_time_memory_area_smap,
> >> >> >> identical to VCPUOP_register_vcpu_time_memory_area apart from
> also
> >> >> >> setting the flag, would be more natural. But considering what I just
> >> wrote
> >> >> >> in the reply to Tim I guess we can expect a nun-user mapping to be
> >> >> >> presented here anyway, i.e. we wouldn't need to new operation at all.
> >> >> >
> >> >> > Do you mean since the user-paging is r/o, guest will pass a r/w kernel
> page
> >> >> > to
> >> >> > Xen for updating the system time. So we don't need to do the SMAP
> check
> >> >> > in this case?
> >> >>
> >> >> If the user page is r/o, it's VA obviously can't be used for updating by
> >> >> Xen. Hence the kernel has to provide a r/w mapped VA. That should be
> >> >> subject to SMAP checking (consistent with the runstate area handling),
> >> >> to make sure it's not a user accessible mapping.
> >> >
> >> > But there are two possible problems here:
> >> > 1. Is it possible that guest passes a user r/w page to update the system
> >> > time information?
> >>
> >> The guest kernel may pass a page that was originally mapped r/w-
> >> kernel, but the mapping later gets (say inadvertently) changed to
> >> r/w-user. That's why I think the SMAP checking ought to be done
> >> here.
> >
> > But in another case, as what we discussed before, if the guest intended to
> > pass a user r/w page to get the time information. Do we need to do the
> > SMAP checking for this?
>
> The question is whether we should bother supporting such insecure
> kernels.
>
> >> > 2. Even the user page is r/o, the kernel can still use it to update the
> >> > system time info when WP is disabled.
> >>
> >> The kernel can - for its own accesses to the page - do whatever
> >> it wants. It can't, however, control Xen's updating of it, and Xen
> >> won't do that with CR0.WP clear (leaving aside Aravindh's PV
> >> mem-access work, where this option is currently being discussed).
> >
> > Just like my comments above, my point is in some case, guest may pass a
> > user page (r/o or r/w) to get the time information, I doubt whether the SMAP
> > checking should be done for this?
>
> If we want to allow kernels to expose the time data r/w to user mode,
> then yes, we would need to avoid the SMAP check. But as said above,
> I don't think helping kernels to be insecure is of any particular value.
Okay, thanks a lot for your comments! It makes sense. I got your point. I will do the
SMAP checking for both of the two cases (runstate area and system time information).
Thanks,
Feng
>
> Jan
^ permalink raw reply [flat|nested] 26+ messages in thread* Re: [PATCH 2/2] x86/hvm: honor guest's option when updating secondary system time for guest
2014-07-25 8:31 ` Jan Beulich
2014-07-25 8:35 ` Wu, Feng
@ 2014-07-25 8:52 ` Andrew Cooper
2014-07-25 9:17 ` Jan Beulich
1 sibling, 1 reply; 26+ messages in thread
From: Andrew Cooper @ 2014-07-25 8:52 UTC (permalink / raw)
To: Jan Beulich, Feng Wu
Cc: linux@eikelenboom.it, keir@xen.org, tim@xen.org,
xen-devel@lists.xen.org
On 25/07/14 09:31, Jan Beulich wrote:
>>>> On 25.07.14 at 10:03, <feng.wu@intel.com> wrote:
>>> -----Original Message-----
>>> From: Jan Beulich [mailto:JBeulich@suse.com]
>>> Sent: Friday, July 25, 2014 3:40 PM
>>> To: Wu, Feng
>>> Cc: linux@eikelenboom.it; xen-devel@lists.xen.org; konrad.wilk@oracle.com;
>>> keir@xen.org; tim@xen.org
>>> Subject: RE: [PATCH 2/2] x86/hvm: honor guest's option when updating
>>> secondary system time for guest
>>>
>>>>>> On 25.07.14 at 09:33, <feng.wu@intel.com> wrote:
>>>>> -----Original Message-----
>>>>> From: Jan Beulich [mailto:JBeulich@suse.com]
>>>>> Sent: Friday, July 25, 2014 3:26 PM
>>>>> To: Wu, Feng
>>>>> Cc: linux@eikelenboom.it; xen-devel@lists.xen.org;
>>> konrad.wilk@oracle.com;
>>>>> keir@xen.org; tim@xen.org
>>>>> Subject: RE: [PATCH 2/2] x86/hvm: honor guest's option when updating
>>>>> secondary system time for guest
>>>>>
>>>>>>>> On 25.07.14 at 06:30, <feng.wu@intel.com> wrote:
>>>>>>> -----Original Message-----
>>>>>>> From: Jan Beulich [mailto:JBeulich@suse.com]
>>>>>>> Sent: Wednesday, July 23, 2014 8:19 PM
>>>>>>> To: Wu, Feng
>>>>>>> Cc: linux@eikelenboom.it; xen-devel@lists.xen.org;
>>>>> konrad.wilk@oracle.com;
>>>>>>> keir@xen.org; tim@xen.org
>>>>>>> Subject: Re: [PATCH 2/2] x86/hvm: honor guest's option when updating
>>>>>>> secondary system time for guest
>>>>>>>
>>>>>>>>>> On 08.07.14 at 01:18, <feng.wu@intel.com> wrote:
>>>>>>>> --- a/xen/include/public/vcpu.h
>>>>>>>> +++ b/xen/include/public/vcpu.h
>>>>>>>> @@ -227,6 +227,16 @@ struct vcpu_register_time_memory_area {
>>>>>>>> typedef struct vcpu_register_time_memory_area
>>>>>>>> vcpu_register_time_memory_area_t;
>>>>>>>> DEFINE_XEN_GUEST_HANDLE(vcpu_register_time_memory_area_t);
>>>>>>>>
>>>>>>>> +/*
>>>>>>>> + * Flags to tell Xen whether we need to do the SMAP check when
>>>>> updating
>>>>>>>> + * the secondary copy of the vcpu time when SMAP is enabled. Since
>>> the
>>>>>>>> + * memory location for the secondary copy of the vcpu time may be
>>>>> mapped
>>>>>>>> + * into userspace by guests intendedly, we let the guest to determine
>>>>>>>> + * whether the check is needed. The default behavior of hypevisor is
>>>>>>>> + * not doing the check.
>>>>>>>> + */
>>>>>>>> +#define VCPUOP_enable_smap_check_vcpu_time_memory_area
>>> 14
>>>>>>> I think the new op to be
>>> VCPUOP_register_vcpu_time_memory_area_smap,
>>>>>>> identical to VCPUOP_register_vcpu_time_memory_area apart from also
>>>>>>> setting the flag, would be more natural. But considering what I just
>>> wrote
>>>>>>> in the reply to Tim I guess we can expect a nun-user mapping to be
>>>>>>> presented here anyway, i.e. we wouldn't need to new operation at all.
>>>>>> Do you mean since the user-paging is r/o, guest will pass a r/w kernel page
>>>>>> to
>>>>>> Xen for updating the system time. So we don't need to do the SMAP check
>>>>>> in this case?
>>>>> If the user page is r/o, it's VA obviously can't be used for updating by
>>>>> Xen. Hence the kernel has to provide a r/w mapped VA. That should be
>>>>> subject to SMAP checking (consistent with the runstate area handling),
>>>>> to make sure it's not a user accessible mapping.
>>>> But there are two possible problems here:
>>>> 1. Is it possible that guest passes a user r/w page to update the system
>>>> time information?
>>> The guest kernel may pass a page that was originally mapped r/w-
>>> kernel, but the mapping later gets (say inadvertently) changed to
>>> r/w-user. That's why I think the SMAP checking ought to be done
>>> here.
>> But in another case, as what we discussed before, if the guest intended to
>> pass a user r/w page to get the time information. Do we need to do the
>> SMAP checking for this?
> The question is whether we should bother supporting such insecure
> kernels.
Thinking about this some more, how can we possibly know whether writing
to the nominated page is even safe? At the point of update, there is no
knowledge about the current cr3 in use.
As far as I can see, the only safe actions Xen can take is refuse to
ever write to user mappings, and insist that any OS using this feature
provide a supervisor mapping to Xen (and guarantee it will never swap
the target of that mapping) and give user mappings of the same gpa to
any of its own userspace which wants access. This then avoids any
concerns wrt SMAP.
~Andrew
^ permalink raw reply [flat|nested] 26+ messages in thread* Re: [PATCH 2/2] x86/hvm: honor guest's option when updating secondary system time for guest
2014-07-25 8:52 ` Andrew Cooper
@ 2014-07-25 9:17 ` Jan Beulich
0 siblings, 0 replies; 26+ messages in thread
From: Jan Beulich @ 2014-07-25 9:17 UTC (permalink / raw)
To: Andrew Cooper
Cc: linux@eikelenboom.it, tim@xen.org, keir@xen.org, Feng Wu,
xen-devel@lists.xen.org
>>> On 25.07.14 at 10:52, <andrew.cooper3@citrix.com> wrote:
> Thinking about this some more, how can we possibly know whether writing
> to the nominated page is even safe? At the point of update, there is no
> knowledge about the current cr3 in use.
That's a problem the kernel has to be bothered by, but not the
hypervisor.
> As far as I can see, the only safe actions Xen can take is refuse to
> ever write to user mappings, and insist that any OS using this feature
> provide a supervisor mapping to Xen (and guarantee it will never swap
> the target of that mapping) and give user mappings of the same gpa to
> any of its own userspace which wants access. This then avoids any
> concerns wrt SMAP.
No, user mappings can validly (and do) appear in the non-user
mode parts of the page tables.
Jan
^ permalink raw reply [flat|nested] 26+ messages in thread