xen: Fixes and improvements to HVM_PARAM handling
cover xen: Fixes and improvements to HVM_PARAM handling
This started with the observation in patch 5, and expanded from there. The end result should be rather more predictable and easy to deprecate parameters from.
An observation which I haven't addressed (and don't have time in the near future) is that the hvm params array is moderately wasteful on x86 and very wasteful on ARM. An option would be to switch to using a named structure, which would also fix the problem that both arch's hypercall handers are BCBS gadgets.
Andrew Cooper (5):
x86/hvm: Switch hvm_allow_get_param() to use a whitelist x86/hvm: Switch hvm_allow_set_param() to use a whitelist x86/hvm: Make HVM_PARAM_{STORE,CONSOLE}_EVTCHN read-only to the guest x86/hvm: Misc non-functional cleanup to the HVM_PARAM infrastructure xen/ARM: Restrict access to most HVM_PARAM's
xen/arch/arm/hvm.c | 62 +++++++++- xen/arch/x86/hvm/hvm.c | 312 +++++++++++++++++++++++++------------------------ 2 files changed, 221 insertions(+), 153 deletions(-)
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 1/5 x86/hvm: Switch hvm_allow_get_param() to use a whitelist
There are holes in the HVM_PARAM space, some of which are from deprecated parameters, but toolstack and device models currently have blanket read access.
Rearrange hvm_allow_get_param() to have a whitelist of toolstack-readable parameters, with the default case failing with -EINVAL (which subsumes the HVM_NR_PARAMS check).
No expected change for the defined, in-use params.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
--- xen/arch/x86/hvm/hvm.c | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-)
xen/arch/x86/hvm/hvm.c +28 -10
@@ -4350,7 +4350,7 @@ static int hvm_allow_get_param(struct domain *d,switch ( a->index ) { -/* The following parameters can be read by the guest. */ +/* The following parameters can be read by the guest and toolstack. */ case HVM_PARAM_CALLBACK_IRQ :case HVM_PARAM_VM86_TSS :case HVM_PARAM_VM86_TSS_SIZED :
@@ -4363,18 +4363,39 @@ static int hvm_allow_get_param(struct domain *d,case HVM_PARAM_ALTP2M :case HVM_PARAM_X87_FIP_WIDTH :break ; -/* -* The following parameters must not be read by the guest -* since the domain may need to be paused. -*/ + +/* +* The following parameters are intended for toolstack usage only. +* Some require the domain to be paused, and therefore may not read by +* the domain. +*/ +case HVM_PARAM_PAE_ENABLED :case HVM_PARAM_IOREQ_PFN :case HVM_PARAM_BUFIOREQ_PFN :case HVM_PARAM_BUFIOREQ_EVTCHN : -/* The remaining parameters should not be read by the guest. */ -default : +case HVM_PARAM_VIRIDIAN : +case HVM_PARAM_TIMER_MODE : +case HVM_PARAM_HPET_ENABLED : +case HVM_PARAM_IDENT_PT : +case HVM_PARAM_DM_DOMAIN : +case HVM_PARAM_ACPI_S_STATE : +case HVM_PARAM_VPT_ALIGN : +case HVM_PARAM_NESTEDHVM : +case HVM_PARAM_PAGING_RING_PFN : +case HVM_PARAM_MONITOR_RING_PFN : +case HVM_PARAM_SHARING_RING_PFN : +case HVM_PARAM_TRIPLE_FAULT_REASON : +case HVM_PARAM_IOREQ_SERVER_PFN : +case HVM_PARAM_NR_IOREQ_SERVER_PAGES : +case HVM_PARAM_MCA_CAP :if ( d == current->domain ) rc = -EPERM ;break ; + +/* Hole, deprecated, or out-of-range. */ +default : + rc = -EINVAL ; +break ; }return rc;
@@ -4390,9 +4411,6 @@ static int hvmop_get_param(if (copy_from_guest (&a, arg,1 ) )return -EFAULT ; -if ( a.index >=HVM_NR_PARAMS ) -return -EINVAL ; - d =rcu_lock_domain_by_any_id (a.domid);if ( d ==NULL )return -ESRCH ;
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 1/5] x86/hvm: Switch hvm_allow_get_param() to use a whitelist
Quoted 41 lines
-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 05 September 2018 19:12
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>
Subject: [PATCH 1/5] x86/hvm: Switchhvm_allow_get_param()to use a whitelistThere are holes in the
HVM_PARAMspace, some of which are from deprecated
parameters, but toolstack and device models currently have blanket read access.Rearrange
hvm_allow_get_param()to have a whitelist of toolstack-readable parameters, with the default case failing with-EINVAL(which subsumes theHVM_NR_PARAMScheck).No expected change for the defined, in-use params.
Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>--- xen/arch/x86/hvm/hvm.c | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-)xen/arch/x86/hvm/hvm.c +0
-0
xen/arch/x86/hvm/hvm.c static int hvm_allow_get_param(struct domain *d, · line 4353
Quoted 5 lines
xen/arch/x86/hvm/hvm.c +1
-1@@ -4350,7 +4350,7 @@ static int hvm_allow_get_param(struct domain *d,switch ( a->index ) { -/* The following parameters can be read by the guest. */ +/* The following parameters can be read by the guest and toolstack. */
Intentional indentation change? I guess so since you do it again below, but just checking.
Quoted 52 lines
xen/arch/x86/hvm/hvm.c +4
-4case HVM_PARAM_CALLBACK_IRQ :case HVM_PARAM_VM86_TSS :case HVM_PARAM_VM86_TSS_SIZED :@@ -4363,18 +4363,39 @@ static int hvm_allow_get_param(struct domain *d, case HVM_PARAM_ALTP2M:case HVM_PARAM_X87_FIP_WIDTH :break ; -/* -* The following parameters must not be read by the guest -* since the domain may need to be paused. -*/ + +/* +* The following parameters are intended for toolstack usage only. +* Some require the domain to be paused, and therefore may not read by
xen/arch/x86/hvm/hvm.c +23
-2+* the domain. +*/ +case HVM_PARAM_PAE_ENABLED :case HVM_PARAM_IOREQ_PFN :case HVM_PARAM_BUFIOREQ_PFN :case HVM_PARAM_BUFIOREQ_EVTCHN : -/* The remaining parameters should not be read by the guest. */ -default : +case HVM_PARAM_VIRIDIAN : +case HVM_PARAM_TIMER_MODE : +case HVM_PARAM_HPET_ENABLED : +case HVM_PARAM_IDENT_PT : +case HVM_PARAM_DM_DOMAIN : +case HVM_PARAM_ACPI_S_STATE : +case HVM_PARAM_VPT_ALIGN : +case HVM_PARAM_NESTEDHVM : +case HVM_PARAM_PAGING_RING_PFN : +case HVM_PARAM_MONITOR_RING_PFN : +case HVM_PARAM_SHARING_RING_PFN : +case HVM_PARAM_TRIPLE_FAULT_REASON : +case HVM_PARAM_IOREQ_SERVER_PFN : +case HVM_PARAM_NR_IOREQ_SERVER_PAGES : +case HVM_PARAM_MCA_CAP :if ( d == current->domain ) rc = -EPERM ;break ; + +/* Hole, deprecated, or out-of-range. */ +default : + rc = -EINVAL ; +break ; }return rc;
xen/arch/x86/hvm/hvm.c static int hvmop_get_param( · line 4395
Quoted 6 lines
xen/arch/x86/hvm/hvm.c +0
-3@@ -4390,9 +4411,6 @@ static int hvmop_get_param(if (copy_from_guest (&a, arg,1 ) )return -EFAULT ; -if ( a.index >=HVM_NR_PARAMS ) -return -EINVAL ; -
ASSERT, just in case someone screws up the allow function in future?
Quoted 5 lines
xen/arch/x86/hvm/hvm.c +0
-1d =rcu_lock_domain_by_any_id (a.domid);if ( d ==NULL )return -ESRCH ; --2.1.4
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 1/5] x86/hvm: Switch hvm_allow_get_param() to use a whitelist
Quoted 11 lines · Paul Durrant
xen/arch/x86/hvm/hvm.c static int hvm_allow_get_param(struct domain *d, · line 4353
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +1
-1@@ -4350,7 +4350,7 @@ static int hvm_allow_get_param(struct domain *d,switch ( a->index ) { -/* The following parameters can be read by the guest. */ +/* The following parameters can be read by the guest and toolstack. */ Intentional indentation change? I guess so since you do it again below, but just checking.
Yes - this is where BSD style puts comments, as you are inside the braced scope of the switch statement.
Notice furthermore that there is a correction to the end of the comment.
Quoted 56 lines
Quoted 56 lines
xen/arch/x86/hvm/hvm.c +4
-4case HVM_PARAM_CALLBACK_IRQ :case HVM_PARAM_VM86_TSS :case HVM_PARAM_VM86_TSS_SIZED :@@ -4363,18 +4363,39 @@ static int hvm_allow_get_param(struct domain *d, case HVM_PARAM_ALTP2M:case HVM_PARAM_X87_FIP_WIDTH :break ; -/* -* The following parameters must not be read by the guest -* since the domain may need to be paused. -*/ + +/* +* The following parameters are intended for toolstack usage only. +* Some require the domain to be paused, and therefore may not read by
xen/arch/x86/hvm/hvm.c +23
-2+* the domain. +*/ +case HVM_PARAM_PAE_ENABLED :case HVM_PARAM_IOREQ_PFN :case HVM_PARAM_BUFIOREQ_PFN :case HVM_PARAM_BUFIOREQ_EVTCHN : -/* The remaining parameters should not be read by the guest. */ -default : +case HVM_PARAM_VIRIDIAN : +case HVM_PARAM_TIMER_MODE : +case HVM_PARAM_HPET_ENABLED : +case HVM_PARAM_IDENT_PT : +case HVM_PARAM_DM_DOMAIN : +case HVM_PARAM_ACPI_S_STATE : +case HVM_PARAM_VPT_ALIGN : +case HVM_PARAM_NESTEDHVM : +case HVM_PARAM_PAGING_RING_PFN : +case HVM_PARAM_MONITOR_RING_PFN : +case HVM_PARAM_SHARING_RING_PFN : +case HVM_PARAM_TRIPLE_FAULT_REASON : +case HVM_PARAM_IOREQ_SERVER_PFN : +case HVM_PARAM_NR_IOREQ_SERVER_PAGES : +case HVM_PARAM_MCA_CAP :if ( d == current->domain ) rc = -EPERM ;break ; + +/* Hole, deprecated, or out-of-range. */ +default : + rc = -EINVAL ; +break ; }return rc;@@ -4390,9 +4411,6 @@ static int hvmop_get_param(if (copy_from_guest (&a, arg,1 ) )return -EFAULT ;
Quoted 4 lines
xen/arch/x86/hvm/hvm.c static int hvmop_get_param( · line 4395
Quoted 3 lines
xen/arch/x86/hvm/hvm.c +0
-3-if ( a.index >=HVM_NR_PARAMS ) -return -EINVAL ; -ASSERT, just in case someone screws up the allow function in future?
That's not going to help in any practical way. This check does really exist, and is part of the switch statement.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 1/5] x86/hvm: Switch hvm_allow_get_param() to use a whitelist
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 06.09.18 at 17:21, <[email protected]> wrote:
Quoted 6 lines · Paul Durrant
Quoted 6 lines
xen/arch/x86/hvm/hvm.c +0
-0@@ -4350,7 +4350,7 @@ static int hvm_allow_get_param(struct domain *d,
Quoted 8 lines
Quoted 5 lines
xen/arch/x86/hvm/hvm.c static int hvm_allow_get_param(struct domain *d, · line 4353
Quoted 4 lines
xen/arch/x86/hvm/hvm.c +1
-1switch ( a->index ) { -/* The following parameters can be read by the guest. */ +/* The following parameters can be read by the guest and toolstack. */ Intentional indentation change? I guess so since you do it again below, but just checking.
Yes - this is where BSD style puts comments, as you are inside the braced scope of the switch statement.
Well, I'm inclined to support Paul here, no matter what BSD style may have to say. Our own style description doesn't spell out anything either way...
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 1/5] x86/hvm: Switch hvm_allow_get_param() to use a whitelist
In reply to Andrew CooperQuoted 6 lines
Quoted 1 line
Quoted 1 line · On 06.09.18 at 17:21, <[email protected]> wrote:
Quoted 4 lines · Paul Durrant
Quoted 4 lines
xen/arch/x86/hvm/hvm.c +0
-0@@ -4390,9 +4411,6 @@ static int hvmop_get_param(if (copy_from_guest (&a, arg,1 ) )return -EFAULT ;
Quoted 7 lines
Quoted 4 lines
xen/arch/x86/hvm/hvm.c static int hvmop_get_param( · line 4395
Quoted 3 lines
xen/arch/x86/hvm/hvm.c +0
-3-if ( a.index >=HVM_NR_PARAMS ) -return -EINVAL ; -ASSERT, just in case someone screws up the allow function in future?
That's not going to help in any practical way. This check does really exist, and is part of the switch statement.
Which switch() statement? The one in the allow function includes this, but the one here simply has
default:
a.value = d->arch.hvm.params[a.index];
break;Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 1/5] x86/hvm: Switch hvm_allow_get_param() to use a whitelist
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 06.09.18 at 17:21, <[email protected]> wrote:
Quoted 8 lines · Paul Durrant
xen/arch/x86/hvm/hvm.c static int hvmop_get_param( · line 4395
Quoted 7 lines
xen/arch/x86/hvm/hvm.c +0
-3@@ -4390,9 +4411,6 @@ static int hvmop_get_param(if (copy_from_guest (&a, arg,1 ) )return -EFAULT ; -if ( a.index >=HVM_NR_PARAMS ) -return -EINVAL ; -ASSERT, just in case someone screws up the allow function in future?
Quoted 8 lines
Quoted 2 lines
That's not going to help in any practical way. This check does really exist, and is part of the switch statement.
Which
switch()statement? The one in the allow function includes this, but the one here simply hasdefault: a.value = d->arch.hvm.params[a.index]; break;
A boundary check on a.index logically falls within the remit of hvm_allow_get_param()
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 1/5] x86/hvm: Switch hvm_allow_get_param() to use a whitelist
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 07.09.18 at 20:18, <[email protected]> wrote:
Quoted 15 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 06.09.18 at 17:21, <[email protected]> wrote:
Quoted 4 lines · Paul Durrant
Quoted 4 lines
xen/arch/x86/hvm/hvm.c +0
-0@@ -4390,9 +4411,6 @@ static int hvmop_get_param(if (copy_from_guest (&a, arg,1 ) )return -EFAULT ;Quoted 6 lines
Quoted 4 lines
xen/arch/x86/hvm/hvm.c static int hvmop_get_param( · line 4395
Quoted 3 lines
xen/arch/x86/hvm/hvm.c +0
-3-if ( a.index >=HVM_NR_PARAMS ) -return -EINVAL ; -ASSERT, just in case someone screws up the allow function in future?
That's not going to help in any practical way. This check does really exist, and is part of the switch statement.
Which
switch()statement? The one in the allow function includes this, but the one here simply has
Quoted 6 lines
Quoted 3 lines
default: a.value = d->arch.hvm.params[a.index]; break;A boundary check on a.index logically falls within the remit of
hvm_allow_get_param()
Correct. Hence - due to the split between the two functions - the desire to have a validating ASSERT() in the other function.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 1/5] x86/hvm: Switch hvm_allow_get_param() to use a whitelist
In reply to Andrew CooperQuoted 11 lines · Andrew Cooper
There are holes in the
HVM_PARAMspace, some of which are from deprecated parameters, but toolstack and device models currently have blanket read access.Rearrange
hvm_allow_get_param()to have a whitelist of toolstack-readable parameters, with the default case failing with-EINVAL(which subsumes theHVM_NR_PARAMScheck).No expected change for the defined, in-use params.
Signed-off-by Andrew Cooper <[email protected]>
Just one nit.
Quoted 26 lines
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>--- xen/arch/x86/hvm/hvm.c | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-)xen/arch/x86/hvm/hvm.c +1
-1@@ -4350,7 +4350,7 @@ static int hvm_allow_get_param(struct domain *d,switch ( a->index ) { -/* The following parameters can be read by the guest. */ +/* The following parameters can be read by the guest and toolstack. */ case HVM_PARAM_CALLBACK_IRQ :case HVM_PARAM_VM86_TSS :case HVM_PARAM_VM86_TSS_SIZED :@@ -4363,18 +4363,39 @@ static int hvm_allow_get_param(struct domain *d,case HVM_PARAM_ALTP2M :
xen/arch/x86/hvm/hvm.c static int hvm_allow_get_param(struct domain *d, · line 4369
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +4
-4case HVM_PARAM_X87_FIP_WIDTH :break ; -/* -* The following parameters must not be read by the guest -* since the domain may need to be paused. -*/ + +/* +* The following parameters are intended for toolstack usage only. +* Some require the domain to be paused, and therefore may not read by
^ be
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 2/5 x86/hvm: Switch hvm_allow_set_param() to use a whitelist
In reply to Andrew CooperThere are holes in the HVM_PARAM space, some of which are from deprecated parameters, but toolstack and device models currently has (almost) blanket write access.
Rearrange hvm_allow_get_param() to have a whitelist of toolstack-writeable parameters, with the default case failing with -EINVAL. This subsumes the HVM_NR_PARAMS check, as well as the MEMORY_EVENT_* deprecated block, and the BUFIOREQ_EVTCHN Xen-write-only value.
No expected change for the defined, in-use params.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
--- xen/arch/x86/hvm/hvm.c | 53 +++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 22 deletions(-)
xen/arch/x86/hvm/hvm.c +31 -22
@@ -4073,7 +4073,7 @@ static int hvm_allow_set_param(struct domain *d,switch ( a->index ) { -/* The following parameters can be set by the guest. */ +/* The following parameters can be set by the guest and toolstack. */ case HVM_PARAM_CALLBACK_IRQ :case HVM_PARAM_VM86_TSS :case HVM_PARAM_VM86_TSS_SIZED :
@@ -4083,18 +4083,40 @@ static int hvm_allow_set_param(struct domain *d,case HVM_PARAM_CONSOLE_EVTCHN :case HVM_PARAM_X87_FIP_WIDTH :break ; -/* -* The following parameters must not be set by the guest -* since the domain may need to be paused. -*/ + +/* +* The following parameters are intended for toolstack usage only. +* Some require the domain to be paused while others control +* permissions in Xen, and therefore may not set by the domain. +*/ +case HVM_PARAM_STORE_PFN : +case HVM_PARAM_PAE_ENABLED : +case HVM_PARAM_IOREQ_PFN : +case HVM_PARAM_BUFIOREQ_PFN : +case HVM_PARAM_VIRIDIAN : +case HVM_PARAM_TIMER_MODE : +case HVM_PARAM_HPET_ENABLED :case HVM_PARAM_IDENT_PT :case HVM_PARAM_DM_DOMAIN :case HVM_PARAM_ACPI_S_STATE : -/* The remaining parameters should not be set by the guest. */ -default : +case HVM_PARAM_VPT_ALIGN : +case HVM_PARAM_CONSOLE_PFN : +case HVM_PARAM_NESTEDHVM : +case HVM_PARAM_PAGING_RING_PFN : +case HVM_PARAM_MONITOR_RING_PFN : +case HVM_PARAM_SHARING_RING_PFN : +case HVM_PARAM_TRIPLE_FAULT_REASON : +case HVM_PARAM_IOREQ_SERVER_PFN : +case HVM_PARAM_NR_IOREQ_SERVER_PAGES : +case HVM_PARAM_MCA_CAP :if ( d == current->domain ) rc = -EPERM ;break ; + +/* Writeable only by Xen, hole, deprecated, or out-of-range. */ +default : + rc = -EINVAL ; +break ; }if ( rc )
@@ -4130,9 +4152,6 @@ static int hvmop_set_param(if (copy_from_guest (&a, arg,1 ) )return -EFAULT ; -if ( a.index >=HVM_NR_PARAMS ) -return -EINVAL ; - d =rcu_lock_domain_by_any_id (a.domid);if ( d ==NULL )return -ESRCH ;
@@ -4209,15 +4228,7 @@ static int hvmop_set_param(case HVM_PARAM_ACPI_IOPORTS_LOCATION : rc =pmtimer_change_ioport (d, a.value);break ; -case HVM_PARAM_MEMORY_EVENT_CR0 : -case HVM_PARAM_MEMORY_EVENT_CR3 : -case HVM_PARAM_MEMORY_EVENT_CR4 : -case HVM_PARAM_MEMORY_EVENT_INT3 : -case HVM_PARAM_MEMORY_EVENT_SINGLE_STEP : -case HVM_PARAM_MEMORY_EVENT_MSR : -/* Deprecated */ - rc = -EOPNOTSUPP ; -break ; +case HVM_PARAM_NESTEDHVM : rc =xsm_hvm_param_nested (XSM_PRIV , d);if ( rc )
@@ -4253,9 +4264,7 @@ static int hvmop_set_param( d->arch.hvm.params[HVM_PARAM_NESTEDHVM] ) rc = -EINVAL ;break ; -case HVM_PARAM_BUFIOREQ_EVTCHN : - rc = -EINVAL ; -break ; +case HVM_PARAM_TRIPLE_FAULT_REASON :if ( a.value >SHUTDOWN_MAX ) rc = -EINVAL ;
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 2/5] x86/hvm: Switch hvm_allow_set_param() to use a whitelist
Quoted 11 lines
-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 05 September 2018 19:12
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>
Subject: [PATCH 2/5] x86/hvm: Switchhvm_allow_set_param()to use a whitelist
Quoted 3 lines
There are holes in the
HVM_PARAMspace, some of which are from deprecated
parameters, but toolstack and device models currently has (almost) blanket
s/has/have
Quoted 3 lines
write access.
Rearrange
hvm_allow_get_param()to have a whitelist of toolstack-writeable
s/get/set
Quoted 25 lines
parameters, with the default case failing with
-EINVAL. This subsumes theHVM_NR_PARAMScheck, as well as the MEMORY_EVENT_* deprecated block, and theBUFIOREQ_EVTCHNXen-write-only value.No expected change for the defined, in-use params.
Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>--- xen/arch/x86/hvm/hvm.c | 53 +++++++++++++++++++++++++++++--------- ------------ 1 file changed, 31 insertions(+), 22 deletions(-)xen/arch/x86/hvm/hvm.c +0
-0
xen/arch/x86/hvm/hvm.c static int hvm_allow_set_param(struct domain *d, · line 4076
Quoted 5 lines
xen/arch/x86/hvm/hvm.c +1
-1@@ -4073,7 +4073,7 @@ static int hvm_allow_set_param(struct domain *d,switch ( a->index ) { -/* The following parameters can be set by the guest. */ +/* The following parameters can be set by the guest and toolstack. */
Personally I'm finding this indentation of comment incongruous. Such comments are logically outside of any particular case statement so I think they should have the same level of indentation as the case statements themselves.
Quoted 52 lines
xen/arch/x86/hvm/hvm.c +28
-6case HVM_PARAM_CALLBACK_IRQ :case HVM_PARAM_VM86_TSS :case HVM_PARAM_VM86_TSS_SIZED :@@ -4083,18 +4083,40 @@ static int hvm_allow_set_param(struct domain *d, case HVM_PARAM_CONSOLE_EVTCHN:case HVM_PARAM_X87_FIP_WIDTH :break ; -/* -* The following parameters must not be set by the guest -* since the domain may need to be paused. -*/ + +/* +* The following parameters are intended for toolstack usage only. +* Some require the domain to be paused while others control +* permissions in Xen, and therefore may not set by the domain. +*/ +case HVM_PARAM_STORE_PFN : +case HVM_PARAM_PAE_ENABLED : +case HVM_PARAM_IOREQ_PFN : +case HVM_PARAM_BUFIOREQ_PFN : +case HVM_PARAM_VIRIDIAN : +case HVM_PARAM_TIMER_MODE : +case HVM_PARAM_HPET_ENABLED :case HVM_PARAM_IDENT_PT :case HVM_PARAM_DM_DOMAIN :case HVM_PARAM_ACPI_S_STATE : -/* The remaining parameters should not be set by the guest. */ -default : +case HVM_PARAM_VPT_ALIGN : +case HVM_PARAM_CONSOLE_PFN : +case HVM_PARAM_NESTEDHVM : +case HVM_PARAM_PAGING_RING_PFN : +case HVM_PARAM_MONITOR_RING_PFN : +case HVM_PARAM_SHARING_RING_PFN : +case HVM_PARAM_TRIPLE_FAULT_REASON : +case HVM_PARAM_IOREQ_SERVER_PFN : +case HVM_PARAM_NR_IOREQ_SERVER_PAGES : +case HVM_PARAM_MCA_CAP :if ( d == current->domain ) rc = -EPERM ;break ; + +/* Writeable only by Xen, hole, deprecated, or out-of-range. */ +default : + rc = -EINVAL ; +break ; }if ( rc )
xen/arch/x86/hvm/hvm.c static int hvmop_set_param( · line 4135
Quoted 6 lines
xen/arch/x86/hvm/hvm.c +0
-3@@ -4130,9 +4152,6 @@ static int hvmop_set_param(if (copy_from_guest (&a, arg,1 ) )return -EFAULT ; -if ( a.index >=HVM_NR_PARAMS ) -return -EINVAL ; -
Again, I think an ASSERT here would be good.
Quoted 6 lines
xen/arch/x86/hvm/hvm.c +0
-0d =rcu_lock_domain_by_any_id (a.domid);if ( d ==NULL )return -ESRCH ;@@ -4209,15 +4228,7 @@ static int hvmop_set_param(case HVM_PARAM_ACPI_IOPORTS_LOCATION : rc =pmtimer_change_ioport (d, a.value);
xen/arch/x86/hvm/hvm.c static int hvmop_set_param( · line 4220
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +0
-9break ; -case HVM_PARAM_MEMORY_EVENT_CR0 : -case HVM_PARAM_MEMORY_EVENT_CR3 : -case HVM_PARAM_MEMORY_EVENT_CR4 : -case HVM_PARAM_MEMORY_EVENT_INT3 : -case HVM_PARAM_MEMORY_EVENT_SINGLE_STEP : -case HVM_PARAM_MEMORY_EVENT_MSR : -/* Deprecated */ - rc = -EOPNOTSUPP ; -break ;
Does anything rely on this EOPNOTSUPP vs the EINVAL that would be returned after this patch is applied?
Paul
Quoted 16 lines
xen/arch/x86/hvm/hvm.c +2
-4+case HVM_PARAM_NESTEDHVM : rc =xsm_hvm_param_nested (XSM_PRIV , d);if ( rc )@@ -4253,9 +4264,7 @@ static int hvmop_set_param( d->arch.hvm.params[HVM_PARAM_NESTEDHVM] ) rc = -EINVAL ;break ; -case HVM_PARAM_BUFIOREQ_EVTCHN : - rc = -EINVAL ; -break ; +case HVM_PARAM_TRIPLE_FAULT_REASON :if ( a.value >SHUTDOWN_MAX ) rc = -EINVAL ; --
Quoted 1 line
2.1.4
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 2/5] x86/hvm: Switch hvm_allow_set_param() to use a whitelist
Quoted 14 lines · Paul Durrant
Quoted 11 lines
-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 05 September 2018 19:12
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>
Subject: [PATCH 2/5] x86/hvm: Switchhvm_allow_set_param()to use a whitelistQuoted 3 lines
There are holes in the
HVM_PARAMspace, some of which are from deprecated
parameters, but toolstack and device models currently has (almost) blanket
Quoted 6 lines
s/has/have
Quoted 3 lines
write access.
Rearrange
hvm_allow_get_param()to have a whitelist of toolstack-writeables/get/set
Both fixed.
Quoted 9 lines
Quoted 9 lines
d = rcu_lock_domain_by_any_id(a.domid); if ( d == NULL ) return -ESRCH;xen/arch/x86/hvm/hvm.c +0
-2@@ -4209,15 +4228,7 @@ static int hvmop_set_param(case HVM_PARAM_ACPI_IOPORTS_LOCATION : rc =pmtimer_change_ioport (d, a.value);break ; -case HVM_PARAM_MEMORY_EVENT_CR0 : -case HVM_PARAM_MEMORY_EVENT_CR3 :
Quoted 8 lines
xen/arch/x86/hvm/hvm.c static int hvmop_set_param( · line 4220
Quoted 7 lines
xen/arch/x86/hvm/hvm.c +0
-7-case HVM_PARAM_MEMORY_EVENT_CR4 : -case HVM_PARAM_MEMORY_EVENT_INT3 : -case HVM_PARAM_MEMORY_EVENT_SINGLE_STEP : -case HVM_PARAM_MEMORY_EVENT_MSR : -/* Deprecated */ - rc = -EOPNOTSUPP ; -break ;Does anything rely on this EOPNOTSUPP vs the EINVAL that would be returned after this patch is applied?
Nothing I can spot, although in searching, I see that xc_hvm_param_deprecated_check() is a thing.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 2/5] x86/hvm: Switch hvm_allow_set_param() to use a whitelist
In reply to Andrew CooperQuoted 4 lines · Andrew Cooper
There are holes in the
HVM_PARAMspace, some of which are from deprecated parameters, but toolstack and device models currently has (almost) blanket write access.
Quoted 8 lines
Rearrange
hvm_allow_get_param()to have a whitelist of toolstack-writeable parameters, with the default case failing with-EINVAL. This subsumes theHVM_NR_PARAMScheck, as well as the MEMORY_EVENT_* deprecated block, and theBUFIOREQ_EVTCHNXen-write-only value.No expected change for the defined, in-use params.
Signed-off-by Andrew Cooper <[email protected]>
Quoted 16 lines
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>--- xen/arch/x86/hvm/hvm.c | 53 +++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 22 deletions(-)xen/arch/x86/hvm/hvm.c +0
-0
xen/arch/x86/hvm/hvm.c static int hvm_allow_set_param(struct domain *d, · line 4078
Quoted 7 lines
xen/arch/x86/hvm/hvm.c +1
-1@@ -4073,7 +4073,7 @@ static int hvm_allow_set_param(struct domain *d,switch ( a->index ) { -/* The following parameters can be set by the guest. */ +/* The following parameters can be set by the guest and toolstack. */ case HVM_PARAM_CALLBACK_IRQ :case HVM_PARAM_VM86_TSS :
Note sure about the point of letting the guest set the unreal mode TSS, but anyway this is not the scope of the patch.
xen/arch/x86/hvm/hvm.c static int hvm_allow_set_param(struct domain *d, · line 4083
Quoted 3 lines
xen/arch/x86/hvm/hvm.c +0
-0case HVM_PARAM_VM86_TSS_SIZED :@@ -4083,18 +4083,40 @@ static int hvm_allow_set_param(struct domain *d,case HVM_PARAM_CONSOLE_EVTCHN :
Also it's quite weird that we allow the guest to set the console evtchn...
Quoted 16 lines
xen/arch/x86/hvm/hvm.c +10
-4case HVM_PARAM_X87_FIP_WIDTH :break ; -/* -* The following parameters must not be set by the guest -* since the domain may need to be paused. -*/ + +/* +* The following parameters are intended for toolstack usage only. +* Some require the domain to be paused while others control +* permissions in Xen, and therefore may not set by the domain. +*/ +case HVM_PARAM_STORE_PFN : +case HVM_PARAM_PAE_ENABLED : +case HVM_PARAM_IOREQ_PFN : +case HVM_PARAM_BUFIOREQ_PFN :
xen/arch/x86/hvm/hvm.c static int hvm_allow_set_param(struct domain *d, · line 4103
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +5
-2+case HVM_PARAM_VIRIDIAN : +case HVM_PARAM_TIMER_MODE : +case HVM_PARAM_HPET_ENABLED :case HVM_PARAM_IDENT_PT :case HVM_PARAM_DM_DOMAIN :case HVM_PARAM_ACPI_S_STATE : -/* The remaining parameters should not be set by the guest. */ -default : +case HVM_PARAM_VPT_ALIGN : +case HVM_PARAM_CONSOLE_PFN :
... but not the console page. I think the guest shouldn't be allowed to set any of those.
Quoted 32 lines
xen/arch/x86/hvm/hvm.c +13
-3+case HVM_PARAM_NESTEDHVM : +case HVM_PARAM_PAGING_RING_PFN : +case HVM_PARAM_MONITOR_RING_PFN : +case HVM_PARAM_SHARING_RING_PFN : +case HVM_PARAM_TRIPLE_FAULT_REASON : +case HVM_PARAM_IOREQ_SERVER_PFN : +case HVM_PARAM_NR_IOREQ_SERVER_PAGES : +case HVM_PARAM_MCA_CAP :if ( d == current->domain ) rc = -EPERM ;break ; + +/* Writeable only by Xen, hole, deprecated, or out-of-range. */ +default : + rc = -EINVAL ; +break ; }if ( rc )@@ -4130,9 +4152,6 @@ static int hvmop_set_param(if (copy_from_guest (&a, arg,1 ) )return -EFAULT ; -if ( a.index >=HVM_NR_PARAMS ) -return -EINVAL ; - d =rcu_lock_domain_by_any_id (a.domid);if ( d ==NULL )return -ESRCH ;@@ -4209,15 +4228,7 @@ static int hvmop_set_param(case HVM_PARAM_ACPI_IOPORTS_LOCATION : rc =pmtimer_change_ioport (d, a.value);
xen/arch/x86/hvm/hvm.c static int hvmop_set_param( · line 4220
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +0
-9break ; -case HVM_PARAM_MEMORY_EVENT_CR0 : -case HVM_PARAM_MEMORY_EVENT_CR3 : -case HVM_PARAM_MEMORY_EVENT_CR4 : -case HVM_PARAM_MEMORY_EVENT_INT3 : -case HVM_PARAM_MEMORY_EVENT_SINGLE_STEP : -case HVM_PARAM_MEMORY_EVENT_MSR : -/* Deprecated */ - rc = -EOPNOTSUPP ; -break ;
I assume there's no toolstack logic that relies on those parameters returning EOPNOTSUPP?
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 2/5] x86/hvm: Switch hvm_allow_set_param() to use a whitelist
Quoted 32 lines · Roger Pau Monné
Quoted 4 lines · Andrew Cooper
There are holes in the
HVM_PARAMspace, some of which are from deprecated parameters, but toolstack and device models currently has (almost) blanket write access.Quoted 8 lines
Rearrange
hvm_allow_get_param()to have a whitelist of toolstack-writeable parameters, with the default case failing with-EINVAL. This subsumes theHVM_NR_PARAMScheck, as well as the MEMORY_EVENT_* deprecated block, and theBUFIOREQ_EVTCHNXen-write-only value.No expected change for the defined, in-use params.
Signed-off-by Andrew Cooper <[email protected]>Reviewed-by Roger Pau Monné <[email protected]>Quoted 17 lines
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>--- xen/arch/x86/hvm/hvm.c | 53 +++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 22 deletions(-)xen/arch/x86/hvm/hvm.c +0
-0@@ -4073,7 +4073,7 @@ static int hvm_allow_set_param(struct domain *d,
Quoted 8 lines
xen/arch/x86/hvm/hvm.c static int hvm_allow_set_param(struct domain *d, · line 4078
Quoted 6 lines
xen/arch/x86/hvm/hvm.c +1
-1switch ( a->index ) { -/* The following parameters can be set by the guest. */ +/* The following parameters can be set by the guest and toolstack. */ case HVM_PARAM_CALLBACK_IRQ :case HVM_PARAM_VM86_TSS :Note sure about the point of letting the guest set the unreal mode TSS, but anyway this is not the scope of the patch.
Because hvmloader still sets it up for HVM guests.
Neither you nor Jan took my hints (when doing various related work) that unifying the PVH and HVM paths in the domain builder (alongside IDENT_PT) would be a GoodThing(tm).
OTOH, we do now actually have a fairly simple cleanup task which a student could be guided through doing, which would allow us to remove guest access to these two params.
Quoted 33 lines
xen/arch/x86/hvm/hvm.c static int hvm_allow_set_param(struct domain *d, · line 4083
Quoted 4 lines
xen/arch/x86/hvm/hvm.c +0
-0case HVM_PARAM_VM86_TSS_SIZED :@@ -4083,18 +4083,40 @@ static int hvm_allow_set_param(struct domain *d,case HVM_PARAM_CONSOLE_EVTCHN :Also it's quite weird that we allow the guest to set the console evtchn...
Quoted 16 lines
xen/arch/x86/hvm/hvm.c +10
-4case HVM_PARAM_X87_FIP_WIDTH :break ; -/* -* The following parameters must not be set by the guest -* since the domain may need to be paused. -*/ + +/* +* The following parameters are intended for toolstack usage only. +* Some require the domain to be paused while others control +* permissions in Xen, and therefore may not set by the domain. +*/ +case HVM_PARAM_STORE_PFN : +case HVM_PARAM_PAE_ENABLED : +case HVM_PARAM_IOREQ_PFN : +case HVM_PARAM_BUFIOREQ_PFN :xen/arch/x86/hvm/hvm.c static int hvm_allow_set_param(struct domain *d, · line 4103
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +5
-2+case HVM_PARAM_VIRIDIAN : +case HVM_PARAM_TIMER_MODE : +case HVM_PARAM_HPET_ENABLED :case HVM_PARAM_IDENT_PT :case HVM_PARAM_DM_DOMAIN :case HVM_PARAM_ACPI_S_STATE : -/* The remaining parameters should not be set by the guest. */ -default : +case HVM_PARAM_VPT_ALIGN : +case HVM_PARAM_CONSOLE_PFN :
Quoted 2 lines
... but not the console page. I think the guest shouldn't be allowed to set any of those.
I see you saw why, but you need to read Paul's reply.
Any user of EVTCHNOP_reset needs to recreate the toolstack event channels and rewrite *_EVTCHN to allow the next entity (in Paul's example, the windows crash driver) to start back up correctly.
Of course, the same cant be said for a theoretical GNTTABOP_reset. (If it seems like this is a sprawling mess of swamps, that's because its all terrible.)
Quoted 37 lines
Quoted 37 lines
xen/arch/x86/hvm/hvm.c +13
-6+case HVM_PARAM_NESTEDHVM : +case HVM_PARAM_PAGING_RING_PFN : +case HVM_PARAM_MONITOR_RING_PFN : +case HVM_PARAM_SHARING_RING_PFN : +case HVM_PARAM_TRIPLE_FAULT_REASON : +case HVM_PARAM_IOREQ_SERVER_PFN : +case HVM_PARAM_NR_IOREQ_SERVER_PAGES : +case HVM_PARAM_MCA_CAP :if ( d == current->domain ) rc = -EPERM ;break ; + +/* Writeable only by Xen, hole, deprecated, or out-of-range. */ +default : + rc = -EINVAL ; +break ; }if ( rc )@@ -4130,9 +4152,6 @@ static int hvmop_set_param(if (copy_from_guest (&a, arg,1 ) )return -EFAULT ; -if ( a.index >=HVM_NR_PARAMS ) -return -EINVAL ; - d =rcu_lock_domain_by_any_id (a.domid);if ( d ==NULL )return -ESRCH ;@@ -4209,15 +4228,7 @@ static int hvmop_set_param(case HVM_PARAM_ACPI_IOPORTS_LOCATION : rc =pmtimer_change_ioport (d, a.value);break ; -case HVM_PARAM_MEMORY_EVENT_CR0 : -case HVM_PARAM_MEMORY_EVENT_CR3 : -case HVM_PARAM_MEMORY_EVENT_CR4 :
Quoted 8 lines
xen/arch/x86/hvm/hvm.c static int hvmop_set_param( · line 4220
Quoted 6 lines
xen/arch/x86/hvm/hvm.c +0
-6-case HVM_PARAM_MEMORY_EVENT_INT3 : -case HVM_PARAM_MEMORY_EVENT_SINGLE_STEP : -case HVM_PARAM_MEMORY_EVENT_MSR : -/* Deprecated */ - rc = -EOPNOTSUPP ; -break ;I assume there's no toolstack logic that relies on those parameters returning EOPNOTSUPP?
No. There is a libxc function which intercepts these params and fails early with -EOPNOTSUPP, so hypercalls never hit Xen, but I can't find any code which requests these PARAMs now.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 2/5] x86/hvm: Switch hvm_allow_set_param() to use a whitelist
Quoted 44 lines · Andrew Cooper
Quoted 32 lines · Roger Pau Monné
Quoted 4 lines · Andrew Cooper
There are holes in the
HVM_PARAMspace, some of which are from deprecated parameters, but toolstack and device models currently has (almost) blanket write access.Quoted 8 lines
Rearrange
hvm_allow_get_param()to have a whitelist of toolstack-writeable parameters, with the default case failing with-EINVAL. This subsumes theHVM_NR_PARAMScheck, as well as the MEMORY_EVENT_* deprecated block, and theBUFIOREQ_EVTCHNXen-write-only value.No expected change for the defined, in-use params.
Signed-off-by Andrew Cooper <[email protected]>Reviewed-by Roger Pau Monné <[email protected]>Quoted 17 lines
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>--- xen/arch/x86/hvm/hvm.c | 53 +++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 22 deletions(-)xen/arch/x86/hvm/hvm.c +0
-0@@ -4073,7 +4073,7 @@ static int hvm_allow_set_param(struct domain *d,Quoted 8 lines
xen/arch/x86/hvm/hvm.c static int hvm_allow_set_param(struct domain *d, · line 4078
Quoted 6 lines
xen/arch/x86/hvm/hvm.c +1
-1switch ( a->index ) { -/* The following parameters can be set by the guest. */ +/* The following parameters can be set by the guest and toolstack. */ case HVM_PARAM_CALLBACK_IRQ :case HVM_PARAM_VM86_TSS :Note sure about the point of letting the guest set the unreal mode TSS, but anyway this is not the scope of the patch.
Because hvmloader still sets it up for HVM guests.
Quoted 7 lines
Neither you nor Jan took my hints (when doing various related work) that unifying the PVH and HVM paths in the domain builder (alongside
IDENT_PT) would be a GoodThing(tm).OTOH, we do now actually have a fairly simple cleanup task which a student could be guided through doing, which would allow us to remove guest access to these two params.
Hm, right. The main problem I see with this is that the hypervisor has no knowledge of the memory map when building a DomU (all this is in the toolstack), so it's quite hard to figure out where to place the TSS or the identity page tables.
We could make the special pages addresses somehow part of the public headers, so that there's a fixed address known by both the toolstack and the hypervisor about the location of those magic pages.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 3/5 x86/hvm: Make HVM_PARAM_{STORE, CONSOLE}_EVTCHN read-only to the guest
In reply to Andrew CooperThese values are set by the toolstack for each create/restore operation, and bound by xen{store,console}d before the the guest starts running.
A guest has no reason to modify them at all, and the matching *_PFN parameters are already read-only. Adjust the *_EVTCHN permissions to be consistent.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
--- xen/arch/x86/hvm/hvm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/hvm.c +2 -2
@@ -4079,8 +4079,6 @@ static int hvm_allow_set_param(struct domain *d,case HVM_PARAM_VM86_TSS_SIZED :case HVM_PARAM_ACPI_IOPORTS_LOCATION :case HVM_PARAM_VM_GENERATION_ID_ADDR : -case HVM_PARAM_STORE_EVTCHN : -case HVM_PARAM_CONSOLE_EVTCHN :case HVM_PARAM_X87_FIP_WIDTH :break ;
@@ -4090,6 +4088,7 @@ static int hvm_allow_set_param(struct domain *d,* permissions in Xen, and therefore may not set by the domain. */ case HVM_PARAM_STORE_PFN : +case HVM_PARAM_STORE_EVTCHN :case HVM_PARAM_PAE_ENABLED :case HVM_PARAM_IOREQ_PFN :case HVM_PARAM_BUFIOREQ_PFN :
@@ -4101,6 +4100,7 @@ static int hvm_allow_set_param(struct domain *d,case HVM_PARAM_ACPI_S_STATE :case HVM_PARAM_VPT_ALIGN :case HVM_PARAM_CONSOLE_PFN : +case HVM_PARAM_CONSOLE_EVTCHN :case HVM_PARAM_NESTEDHVM :case HVM_PARAM_PAGING_RING_PFN :case HVM_PARAM_MONITOR_RING_PFN :
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 3/5] x86/hvm: Make HVM_PARAM_{STORE, CONSOLE}_EVTCHN read-only to the guest
Quoted 11 lines
-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 05 September 2018 19:12
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>
Subject: [PATCH 3/5] x86/hvm: Make HVM_PARAM_{STORE,CONSOLE}_EVTCHN read-only to the guest
Quoted 6 lines
These values are set by the toolstack for each create/restore operation, and bound by xen{store,console}d before the the guest starts running.
A guest has no reason to modify them at all, and the matching
*_PFNparameters
are already read-only. Adjust the*_EVTCHNpermissions to be consistent.
Unfortunately this patch will break the Windows PV driver function here:
http://xenbits.xen.org/gitweb/?p=pvdrivers/win/xenbus.git;a=blob;f=src/xenbus/evtchn.c;hb=HEAD#l1037
Unfortunately the values really do change across a reset. It would be possible to use volatile (disappear on reboot) registry keys to store the updated values instead but I don't really see any harm in allowing the guest to update the values to be correct, unless we want to change Xen to do the job so the guest doesn't have to go through this dance.
Paul
Quoted 43 lines
Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>--- xen/arch/x86/hvm/hvm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)xen/arch/x86/hvm/hvm.c +2
-3@@ -4079,8 +4079,6 @@ static int hvm_allow_set_param(struct domain *d,case HVM_PARAM_VM86_TSS_SIZED :case HVM_PARAM_ACPI_IOPORTS_LOCATION :case HVM_PARAM_VM_GENERATION_ID_ADDR : -case HVM_PARAM_STORE_EVTCHN : -case HVM_PARAM_CONSOLE_EVTCHN :case HVM_PARAM_X87_FIP_WIDTH :break ;@@ -4090,6 +4088,7 @@ static int hvm_allow_set_param(struct domain *d,* permissions in Xen, and therefore may not set by the domain. */ case HVM_PARAM_STORE_PFN : +case HVM_PARAM_STORE_EVTCHN :case HVM_PARAM_PAE_ENABLED :case HVM_PARAM_IOREQ_PFN :case HVM_PARAM_BUFIOREQ_PFN :@@ -4101,6 +4100,7 @@ static int hvm_allow_set_param(struct domain *d,case HVM_PARAM_ACPI_S_STATE :case HVM_PARAM_VPT_ALIGN :case HVM_PARAM_CONSOLE_PFN : +case HVM_PARAM_CONSOLE_EVTCHN :case HVM_PARAM_NESTEDHVM :case HVM_PARAM_PAGING_RING_PFN :case HVM_PARAM_MONITOR_RING_PFN : --
Quoted 1 line
2.1.4
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 3/5] x86/hvm: Make HVM_PARAM_{STORE, CONSOLE}_EVTCHN read-only to the guest
Quoted 14 lines · Paul Durrant
Quoted 14 lines
-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 05 September 2018 19:12
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>
Subject: [PATCH 3/5] x86/hvm: Make HVM_PARAM_{STORE,CONSOLE}_EVTCHN read-only to the guestThese values are set by the toolstack for each create/restore operation, and bound by xen{store,console}d before the the guest starts running.
Quoted 8 lines
Quoted 3 lines
A guest has no reason to modify them at all, and the matching
*_PFNparameters
are already read-only. Adjust the*_EVTCHNpermissions to be consistent.Unfortunately this patch will break the Windows PV driver function here:
http://xenbits.xen.org/gitweb/?p=pvdrivers/win/xenbus.git;a=blob;f=src/xenbus/evtchn.c;hb=HEAD#l1037
Unfortunately the values really do change across a reset. It would be possible to use volatile (disappear on reboot) registry keys to store the updated values instead but I don't really see any harm in allowing the guest to update the values to be correct, unless we want to change Xen to do the job so the guest doesn't have to go through this dance.
:( Everything is terrible.
This is a general problem, not x86 specific, so I'll drop this patch and make a similar adjustment to the ARM one.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 3/5] x86/hvm: Make HVM_PARAM_{STORE, CONSOLE}_EVTCHN read-only to the guest
Quoted 20 lines · Andrew Cooper
Quoted 19 lines · Paul Durrant
Quoted 11 lines
-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 05 September 2018 19:12
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>
Subject: [PATCH 3/5] x86/hvm: Make HVM_PARAM_{STORE,CONSOLE}_EVTCHN read-only to the guestQuoted 6 lines
These values are set by the toolstack for each create/restore operation, and bound by xen{store,console}d before the the guest starts running.
A guest has no reason to modify them at all, and the matching
*_PFNparameters
are already read-only. Adjust the*_EVTCHNpermissions to be consistent.Unfortunately this patch will break the Windows PV driver function here:
Quoted 8 lines
Quoted 3 lines
http://xenbits.xen.org/gitweb/?p=pvdrivers/win/xenbus.git;a=blob;f=src/xenbus/evtchn.c;hb=HEAD#l1037
Unfortunately the values really do change across a reset. It would be possible to use volatile (disappear on reboot) registry keys to store the updated values instead but I don't really see any harm in allowing the guest to update the values to be correct, unless we want to change Xen to do the job so the guest doesn't have to go through this dance.
:( Everything is terrible.
This is a general problem, not x86 specific, so I'll drop this patch and make a similar adjustment to the ARM one.
I am a bit confused. I would have thought this was updated by the toolstack at reset. So why would the guest update them?
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 3/5] x86/hvm: Make HVM_PARAM_{STORE, CONSOLE}_EVTCHN read-only to the guest
Quoted 47 lines
-----Original Message-----
From: Julien Grall [mailto:[email protected]]
Sent: 06 September 2018 18:28
To: Andrew Cooper <[email protected]>; Paul Durrant <[email protected]>; Xen-devel <[email protected]>
Cc: Jan Beulich <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; Stefano Stabellini <[email protected]>
Subject: Re: [PATCH 3/5] x86/hvm: Make HVM_PARAM_{STORE,CONSOLE}_EVTCHN read-only to the guestQuoted 8 lines · Andrew Cooper
Quoted 7 lines · Paul Durrant
Quoted 7 lines
-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 05 September 2018 19:12
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>;Stefano
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Stabellini <[email protected]>; Julien Grall <[email protected]>
Subject: [PATCH 3/5] x86/hvm: Make HVM_PARAM_{STORE,CONSOLE}_EVTCHN read-only to the guestThese values are set by the toolstack for each create/restore operation,
and
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
bound by xen{store,console}d before the the guest starts running.
A guest has no reason to modify them at all, and the matching
*_PFNparameters
are already read-only. Adjust the*_EVTCHNpermissions to beconsistent.
Quoted 3 lines
Quoted 3 lines
Unfortunately this patch will break the Windows PV driver function here:
http://xenbits.xen.org/gitweb/?p=pvdrivers/win/xenbus.git;a=blob;f=src/x
enbus/evtchn.c;hb=HEAD#l1037Quoted 2 lines
Quoted 2 lines
Unfortunately the values really do change across a reset. It would be
possible to use volatile (disappear on reboot) registry keys to store the updated values instead but I don't really see any harm in allowing the guest to update the values to be correct, unless we want to change Xen to do the job so the guest doesn't have to go through this dance.
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
:( Everything is terrible.
This is a general problem, not x86 specific, so I'll drop this patch and make a similar adjustment to the ARM one.
I am a bit confused. I would have thought this was updated by the toolstack at reset. So why would the guest update them?
The problem comes when establishing the evtchn ABI. In the Windows case, when the XENBUS driver loads, it will establish the ABI )which is FIFO by default but can be overridden to 2-level). The XENBUS driver can be manually unloaded and re-loaded (e.g. for upgrade purposes) so it is also necessary to tear down the ABI during unload. This means it is necessary to go through an event channel reset operation, and this has the side-effect of tearing down the store and console event channels which were established by the toolstack before the guest started to boot. It is therefore necessary for the guest, prior to requesting the reset, to query the store and console event channels to get information about the remote domain and port and then, after reset, perform an interdomain bind operation to re-establish the channels. When the guest goes through this dance there is no guarantee that it will get the same local port number for each of the channels is it had previously. Thus, either the information has to be stored somewhere locally such that a new instantiation of the XENBUS driver can find it (e.g. a volatile registry key) or the HVM param needs to be updated to match reality.
HTH,
Paul
Quoted 4 lines
Cheers,
--
Julien Grall
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 3/5] x86/hvm: Make HVM_PARAM_{STORE, CONSOLE}_EVTCHN read-only to the guest
In reply to Andrew CooperQuoted 7 lines · Andrew Cooper
These values are set by the toolstack for each create/restore operation, and bound by xen{store,console}d before the the guest starts running.
A guest has no reason to modify them at all, and the matching
*_PFNparameters are already read-only. Adjust the*_EVTCHNpermissions to be consistent.Signed-off-by Andrew Cooper <[email protected]>
Oh, that answers one of my questions in the previous patch :)
I wonder however if such parameters being writable was part of the public ABI, since it's exposed to guests and now we are changing the behavior.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 4/5 x86/hvm: Misc non-functional cleanup to the HVM_PARAM infrastructure
In reply to Andrew CooperThe parameter marshalling and xsm checks are common to both the set and get paths. Lift all of the common code out into do_hvm_op() and let hvmop_{get,set}_param() operate on struct xen_hvm_param directly.
This is somewhat noisy in the functions as each a. reference has to change to a-> instead.
In addition, drop an empty default statement, insert newlines as appropriate between cases, and there is no need to update the IDENT_PT on the fastpath, because the common path after the switch will make the update.
No functional change, but a net shrink of -328 to do_hvm_op().
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
--- xen/arch/x86/hvm/hvm.c | 223 +++++++++++++++++++++++-------------------------- 1 file changed, 104 insertions(+), 119 deletions(-)
xen/arch/x86/hvm/hvm.c +104 -119
@@ -4065,11 +4065,7 @@ static int hvm_allow_set_param(struct domain *d, const struct xen_hvm_param *a) {uint64_t value = d->arch.hvm.params[a->index]; -int rc; - - rc =xsm_hvm_param (XSM_TARGET , d, HVMOP_set_param); -if ( rc ) -return rc; +int rc =0 ;switch ( a->index ) {
@@ -4133,62 +4129,46 @@ static int hvm_allow_set_param(struct domain *d,if ( value !=0 && a->value != value ) rc = -EEXIST ;break ; -default : -break ; }return rc; } -static int hvmop_set_param ( -XEN_GUEST_HANDLE_PARAM (xen_hvm_param_t) arg) +static int hvmop_set_param (struct domain *d,struct xen_hvm_param *a) {struct domain *curr_d = current->domain; -struct xen_hvm_param a; -struct domain *d;struct vcpu *v;int rc; -if (copy_from_guest (&a, arg,1 ) ) -return -EFAULT ; - - d =rcu_lock_domain_by_any_id (a.domid); -if ( d ==NULL ) -return -ESRCH ; - - rc = -EINVAL ; -if ( !is_hvm_domain (d) ) - goto out; - - rc =hvm_allow_set_param (d, &a); + rc =hvm_allow_set_param (d, a);if ( rc ) goto out; -switch ( a.index ) +switch ( a->index ) {case HVM_PARAM_CALLBACK_IRQ : -hvm_set_callback_via (d, a.value); +hvm_set_callback_via (d, a->value);hvm_latch_shinfo_size (d);break ; +case HVM_PARAM_TIMER_MODE : -if ( a.value > HVMPTM_one_missed_tick_pending ) +if ( a->value > HVMPTM_one_missed_tick_pending ) rc = -EINVAL ;break ; +case HVM_PARAM_VIRIDIAN : -if ( (a.value & ~HVMPV_feature_mask) || - !(a.value & HVMPV_base_freq) ) +if ( (a->value & ~HVMPV_feature_mask) || + !(a->value & HVMPV_base_freq) ) rc = -EINVAL ;break ; +case HVM_PARAM_IDENT_PT :/* * Only actually required for VT-x lacking unrestricted_guest * capabilities. Short circuit the pause if possible. */ if ( !paging_mode_hap (d) || !cpu_has_vmx ) - { - d->arch.hvm.params[a.index] = a.value;break ; - }/* * Update GUEST_CR3 in each VMCS to point at identity map.
@@ -4201,117 +4181,123 @@ static int hvmop_set_param( rc =0 ;domain_pause (d); - d->arch.hvm.params[a.index] = a.value; + d->arch.hvm.params[a->index] = a->value; for_each_vcpu ( d, v )paging_update_cr3 (v, false);domain_unpause (d);domctl_lock_release ();break ; +case HVM_PARAM_DM_DOMAIN :/* The only value this should ever be set to is DOMID_SELF */ -if ( a.value !=DOMID_SELF ) +if ( a->value !=DOMID_SELF ) rc = -EINVAL ; - a.value = curr_d->domain_id; + a->value = curr_d->domain_id;break ; +case HVM_PARAM_ACPI_S_STATE : rc =0 ; -if ( a.value ==3 ) +if ( a->value ==3 )hvm_s3_suspend (d); -else if ( a.value ==0 ) +else if ( a->value ==0 )hvm_s3_resume (d);else rc = -EINVAL ; -break ; +case HVM_PARAM_ACPI_IOPORTS_LOCATION : - rc =pmtimer_change_ioport (d, a.value); + rc =pmtimer_change_ioport (d, a->value);break ;case HVM_PARAM_NESTEDHVM : rc =xsm_hvm_param_nested (XSM_PRIV , d);if ( rc )break ; -if ( a.value >1 ) +if ( a->value >1 ) rc = -EINVAL ;/* * Remove the check below once we have * shadow-on-shadow. */ -if ( !paging_mode_hap (d) && a.value ) +if ( !paging_mode_hap (d) && a->value ) rc = -EINVAL ; -if ( a.value && +if ( a->value && d->arch.hvm.params[HVM_PARAM_ALTP2M ] ) rc = -EINVAL ;/* Set up NHVM state for any vcpus that are already up. */ -if ( a.value && +if ( a->value && !d->arch.hvm.params[HVM_PARAM_NESTEDHVM ] )for_each_vcpu (d, v)if ( rc ==0 ) rc =nestedhvm_vcpu_initialise (v); -if ( !a.value || rc ) +if ( !a->value || rc )for_each_vcpu (d, v)nestedhvm_vcpu_destroy (v);break ; +case HVM_PARAM_ALTP2M : rc =xsm_hvm_param_altp2mhvm (XSM_PRIV , d);if ( rc )break ; -if ( a.value > XEN_ALTP2M_limited ) +if ( a->value > XEN_ALTP2M_limited ) rc = -EINVAL ; -if ( a.value && +if ( a->value && d->arch.hvm.params[HVM_PARAM_NESTEDHVM ] ) rc = -EINVAL ;break ;case HVM_PARAM_TRIPLE_FAULT_REASON : -if ( a.value >SHUTDOWN_MAX ) +if ( a->value >SHUTDOWN_MAX ) rc = -EINVAL ;break ; +case HVM_PARAM_IOREQ_SERVER_PFN : - d->arch.hvm.ioreq_gfn.base = a.value; + d->arch.hvm.ioreq_gfn.base = a->value;break ; +case HVM_PARAM_NR_IOREQ_SERVER_PAGES : {unsigned int i; -if ( a.value ==0 || - a.value >sizeof (d->arch.hvm.ioreq_gfn.mask) *8 ) +if ( a->value ==0 || + a->value >sizeof (d->arch.hvm.ioreq_gfn.mask) *8 ) { rc = -EINVAL ;break ; } -for ( i =0 ; i < a.value; i++ ) +for ( i =0 ; i < a->value; i++ )set_bit (i, &d->arch.hvm.ioreq_gfn.mask);break ; } +case HVM_PARAM_X87_FIP_WIDTH : -if ( a.value !=0 && a.value !=4 && a.value !=8 ) +if ( a->value !=0 && a->value !=4 && a->value !=8 ) { rc = -EINVAL ;break ; } - d->arch.x87_fip_width = a.value; + d->arch.x87_fip_width = a->value;break ;case HVM_PARAM_VM86_TSS :/* Hardware would silently truncate high bits. */ -if ( a.value != (uint32_t )a.value ) +if ( a->value != (uint32_t )a->value ) {if ( d == curr_d )domain_crash (d); rc = -EINVAL ; }/* Old hvmloader binaries hardcode the size to 128 bytes. */ -if ( a.value ) - a.value |= (128ULL <<32 ) |VM86_TSS_UPDATED ; - a.index =HVM_PARAM_VM86_TSS_SIZED ; +if ( a->value ) + a->value |= (128ULL <<32 ) |VM86_TSS_UPDATED ; + a->index =HVM_PARAM_VM86_TSS_SIZED ;break ;case HVM_PARAM_VM86_TSS_SIZED : -if ( (a.value >>32 ) <sizeof (struct tss32 ) ) +if ( (a->value >>32 ) <sizeof (struct tss32 ) ) {if ( d == curr_d )domain_crash (d);
@@ -4322,41 +4308,34 @@ static int hvmop_set_param(* 256 bits interrupt redirection bitmap + 64k bits I/O bitmap * plus one padding byte). */ -if ( (a.value >>32 ) >sizeof (struct tss32 ) + - (0x100 /8 ) + (0x10000 /8 ) +1 ) - a.value = (uint32_t )a.value | - ((sizeof (struct tss32 ) + (0x100 /8 ) + - (0x10000 /8 ) +1 ) <<32 ); - a.value |=VM86_TSS_UPDATED ; +if ( (a->value >>32 ) >sizeof (struct tss32 ) + + (0x100 /8 ) + (0x10000 /8 ) +1 ) + a->value = (uint32_t )a->value | + ((sizeof (struct tss32 ) + (0x100 /8 ) + + (0x10000 /8 ) +1 ) <<32 ); + a->value |=VM86_TSS_UPDATED ;break ;case HVM_PARAM_MCA_CAP : - rc =vmce_enable_mca_cap (d, a.value); + rc =vmce_enable_mca_cap (d, a->value);break ; }if ( rc !=0 ) goto out; - d->arch.hvm.params[a.index] = a.value; + d->arch.hvm.params[a->index] = a->value;HVM_DBG_LOG (DBG_LEVEL_HCALL ,"set param %u = %" PRIx64, - a.index, a.value); + a->index, a->value); out: -rcu_unlock_domain (d);return rc; }static int hvm_allow_get_param (struct domain *d,const struct xen_hvm_param *a) { -int rc; - - rc =xsm_hvm_param (XSM_TARGET , d, HVMOP_get_param); -if ( rc ) -return rc; -switch ( a->index ) {/* The following parameters can be read by the guest and toolstack. */
@@ -4371,7 +4350,7 @@ static int hvm_allow_get_param(struct domain *d,case HVM_PARAM_CONSOLE_EVTCHN :case HVM_PARAM_ALTP2M :case HVM_PARAM_X87_FIP_WIDTH : -break ; +return 0 ;/* * The following parameters are intended for toolstack usage only.
@@ -4397,59 +4376,41 @@ static int hvm_allow_get_param(struct domain *d,case HVM_PARAM_IOREQ_SERVER_PFN :case HVM_PARAM_NR_IOREQ_SERVER_PAGES :case HVM_PARAM_MCA_CAP : -if ( d == current->domain ) - rc = -EPERM ; -break ; +return d == current->domain ? -EPERM :0 ;/* Hole, deprecated, or out-of-range. */ default : - rc = -EINVAL ; -break ; +return -EINVAL ; } - -return rc; } -static int hvmop_get_param ( -XEN_GUEST_HANDLE_PARAM (xen_hvm_param_t) arg) +static int hvmop_get_param (struct domain *d,struct xen_hvm_param *a) { -struct xen_hvm_param a; -struct domain *d;int rc; -if (copy_from_guest (&a, arg,1 ) ) -return -EFAULT ; - - d =rcu_lock_domain_by_any_id (a.domid); -if ( d ==NULL ) -return -ESRCH ; - - rc = -EINVAL ; -if ( !is_hvm_domain (d) ) - goto out; - - rc =hvm_allow_get_param (d, &a); + rc =hvm_allow_get_param (d, a);if ( rc ) - goto out; +return rc; -switch ( a.index ) +switch ( a->index ) {case HVM_PARAM_ACPI_S_STATE : - a.value = d->arch.hvm.is_s3_suspended ?3 :0 ; + a->value = d->arch.hvm.is_s3_suspended ?3 :0 ;break ;case HVM_PARAM_VM86_TSS : - a.value = (uint32_t )d->arch.hvm.params[HVM_PARAM_VM86_TSS_SIZED ]; + a->value = (uint32_t )d->arch.hvm.params[HVM_PARAM_VM86_TSS_SIZED ];break ;case HVM_PARAM_VM86_TSS_SIZED : - a.value = d->arch.hvm.params[HVM_PARAM_VM86_TSS_SIZED ] & - ~VM86_TSS_UPDATED ; + a->value = d->arch.hvm.params[HVM_PARAM_VM86_TSS_SIZED ] & + ~VM86_TSS_UPDATED ;break ;case HVM_PARAM_X87_FIP_WIDTH : - a.value = d->arch.x87_fip_width; + a->value = d->arch.x87_fip_width;break ; +case HVM_PARAM_IOREQ_PFN :case HVM_PARAM_BUFIOREQ_PFN :case HVM_PARAM_BUFIOREQ_EVTCHN :
@@ -4465,23 +4426,19 @@ static int hvmop_get_param( rc =hvm_create_ioreq_server (d, true,HVM_IOREQSRV_BUFIOREQ_LEGACY ,NULL );if ( rc !=0 && rc != -EEXIST ) - goto out; +return rc; } -/*FALLTHRU*/ +/* Fallthrough */ default : - a.value = d->arch.hvm.params[a.index]; + a->value = d->arch.hvm.params[a->index];break ; } - rc =__copy_to_guest (arg, &a,1 ) ? -EFAULT :0 ; -HVM_DBG_LOG (DBG_LEVEL_HCALL ,"get param %u = %" PRIx64, - a.index, a.value); + a->index, a->value); - out: -rcu_unlock_domain (d); -return rc; +return 0 ; }/*
@@ -4896,14 +4853,42 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)break ;case HVMOP_set_param: - rc =hvmop_set_param ( -guest_handle_cast (arg, xen_hvm_param_t)); -break ; -case HVMOP_get_param: - rc =hvmop_get_param ( -guest_handle_cast (arg, xen_hvm_param_t)); + { +struct xen_hvm_param a; +struct domain *d; + + rc = -EFAULT ; +if (copy_from_guest (&a, arg,1 ) ) +break ; + + rc = -ESRCH ; + d =rcu_lock_domain_by_any_id (a.domid); +if ( d ==NULL ) +break ; + + rc = -EINVAL ; +if ( !is_hvm_domain (d) ) + goto param_out; + + rc =xsm_hvm_param (XSM_TARGET , d, op); +if ( rc ) + goto param_out; + +if ( op == HVMOP_set_param ) + rc =hvmop_set_param (d, &a); +else + { + rc =hvmop_get_param (d, &a); + +if ( !rc &&__copy_to_guest (arg, &a,1 ) ) + rc = -EFAULT ; + } + + param_out: +rcu_unlock_domain (d);break ; + }case HVMOP_flush_tlbs: rc =guest_handle_is_null (arg) ?hvmop_flush_tlb_all () : -EINVAL ;
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 4/5] x86/hvm: Misc non-functional cleanup to the HVM_PARAM infrastructure
Quoted 19 lines
-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 05 September 2018 19:12
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>
Subject: [PATCH 4/5] x86/hvm: Misc non-functional cleanup to theHVM_PARAMinfrastructureThe parameter marshalling and xsm checks are common to both the set and get
paths. Lift all of the common code out intodo_hvm_op()and let hvmop_{get,set}_param() operate on structxen_hvm_paramdirectly.This is somewhat noisy in the functions as each a. reference has to change to a-> instead.
Quoted 8 lines
In addition, drop an empty default statement, insert newlines as appropriate between cases, and there is no need to update the
IDENT_PTon the fastpath,
because the common path after the switch will make the update.No functional change, but a net shrink of -328 to
do_hvm_op().Signed-off-by Andrew Cooper <[email protected]>
Quoted 467 lines
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>--- xen/arch/x86/hvm/hvm.c | 223 +++++++++++++++++++++++----------------- --------- 1 file changed, 104 insertions(+), 119 deletions(-)xen/arch/x86/hvm/hvm.c +11
-31@@ -4065,11 +4065,7 @@ static int hvm_allow_set_param(struct domain *d, const struct xen_hvm_param *a) {uint64_t value = d->arch.hvm.params[a->index]; -int rc; - - rc =xsm_hvm_param (XSM_TARGET , d, HVMOP_set_param); -if ( rc ) -return rc; +int rc =0 ;switch ( a->index ) {@@ -4133,62 +4129,46 @@ static int hvm_allow_set_param(struct domain *d, if ( value != 0 && a->value != value ) rc = -EEXIST;break ; -default : -break ; }return rc; } -static int hvmop_set_param ( -XEN_GUEST_HANDLE_PARAM (xen_hvm_param_t) arg) +static int hvmop_set_param (struct domain *d,struct xen_hvm_param *a) {struct domain *curr_d = current->domain; -struct xen_hvm_param a; -struct domain *d;struct vcpu *v;int rc; -if (copy_from_guest (&a, arg,1 ) ) -return -EFAULT ; - - d =rcu_lock_domain_by_any_id (a.domid); -if ( d ==NULL ) -return -ESRCH ; - - rc = -EINVAL ; -if ( !is_hvm_domain (d) ) - goto out; - - rc =hvm_allow_set_param (d, &a); + rc =hvm_allow_set_param (d, a);if ( rc ) goto out; -switch ( a.index ) +switch ( a->index ) {case HVM_PARAM_CALLBACK_IRQ : -hvm_set_callback_via (d, a.value); +hvm_set_callback_via (d, a->value);hvm_latch_shinfo_size (d);break ; +case HVM_PARAM_TIMER_MODE : -if ( a.value > HVMPTM_one_missed_tick_pending ) +if ( a->value > HVMPTM_one_missed_tick_pending ) rc = -EINVAL ;break ; +case HVM_PARAM_VIRIDIAN : -if ( (a.value & ~HVMPV_feature_mask) || - !(a.value & HVMPV_base_freq) ) +if ( (a->value & ~HVMPV_feature_mask) || + !(a->value & HVMPV_base_freq) ) rc = -EINVAL ;break ; +case HVM_PARAM_IDENT_PT :/* * Only actually required for VT-x lacking unrestricted_guest * capabilities. Short circuit the pause if possible. */ if ( !paging_mode_hap (d) || !cpu_has_vmx ) - { - d->arch.hvm.params[a.index] = a.value;break ; - }/* * Update
GUEST_CR3in each VMCS to point at identity map.xen/arch/x86/hvm/hvm.c +54
-73@@ -4201,117 +4181,123 @@ static int hvmop_set_param( rc =0 ;domain_pause (d); - d->arch.hvm.params[a.index] = a.value; + d->arch.hvm.params[a->index] = a->value; for_each_vcpu ( d, v )paging_update_cr3 (v, false);domain_unpause (d);domctl_lock_release ();break ; +case HVM_PARAM_DM_DOMAIN :/* The only value this should ever be set to is DOMID_SELF */ -if ( a.value !=DOMID_SELF ) +if ( a->value !=DOMID_SELF ) rc = -EINVAL ; - a.value = curr_d->domain_id; + a->value = curr_d->domain_id;break ; +case HVM_PARAM_ACPI_S_STATE : rc =0 ; -if ( a.value ==3 ) +if ( a->value ==3 )hvm_s3_suspend (d); -else if ( a.value ==0 ) +else if ( a->value ==0 )hvm_s3_resume (d);else rc = -EINVAL ; -break ; +case HVM_PARAM_ACPI_IOPORTS_LOCATION : - rc =pmtimer_change_ioport (d, a.value); + rc =pmtimer_change_ioport (d, a->value);break ;case HVM_PARAM_NESTEDHVM : rc =xsm_hvm_param_nested (XSM_PRIV , d);if ( rc )break ; -if ( a.value >1 ) +if ( a->value >1 ) rc = -EINVAL ;/* * Remove the check below once we have * shadow-on-shadow. */ -if ( !paging_mode_hap (d) && a.value ) +if ( !paging_mode_hap (d) && a->value ) rc = -EINVAL ; -if ( a.value && +if ( a->value && d->arch.hvm.params[HVM_PARAM_ALTP2M ] ) rc = -EINVAL ;/* Set up NHVM state for any vcpus that are already up. */ -if ( a.value && +if ( a->value && !d->arch.hvm.params[HVM_PARAM_NESTEDHVM ] )for_each_vcpu (d, v)if ( rc ==0 ) rc =nestedhvm_vcpu_initialise (v); -if ( !a.value || rc ) +if ( !a->value || rc )for_each_vcpu (d, v)nestedhvm_vcpu_destroy (v);break ; +case HVM_PARAM_ALTP2M : rc =xsm_hvm_param_altp2mhvm (XSM_PRIV , d);if ( rc )break ; -if ( a.value > XEN_ALTP2M_limited ) +if ( a->value > XEN_ALTP2M_limited ) rc = -EINVAL ; -if ( a.value && +if ( a->value && d->arch.hvm.params[HVM_PARAM_NESTEDHVM ] ) rc = -EINVAL ;break ;case HVM_PARAM_TRIPLE_FAULT_REASON : -if ( a.value >SHUTDOWN_MAX ) +if ( a->value >SHUTDOWN_MAX ) rc = -EINVAL ;break ; +case HVM_PARAM_IOREQ_SERVER_PFN : - d->arch.hvm.ioreq_gfn.base = a.value; + d->arch.hvm.ioreq_gfn.base = a->value;break ; +case HVM_PARAM_NR_IOREQ_SERVER_PAGES : {unsigned int i; -if ( a.value ==0 || - a.value >sizeof (d->arch.hvm.ioreq_gfn.mask) *8 ) +if ( a->value ==0 || + a->value >sizeof (d->arch.hvm.ioreq_gfn.mask) *8 ) { rc = -EINVAL ;break ; } -for ( i =0 ; i < a.value; i++ ) +for ( i =0 ; i < a->value; i++ )set_bit (i, &d->arch.hvm.ioreq_gfn.mask);break ; } +case HVM_PARAM_X87_FIP_WIDTH : -if ( a.value !=0 && a.value !=4 && a.value !=8 ) +if ( a->value !=0 && a->value !=4 && a->value !=8 ) { rc = -EINVAL ;break ; } - d->arch.x87_fip_width = a.value; + d->arch.x87_fip_width = a->value;break ;case HVM_PARAM_VM86_TSS :/* Hardware would silently truncate high bits. */ -if ( a.value != (uint32_t )a.value ) +if ( a->value != (uint32_t )a->value ) {if ( d == curr_d )domain_crash (d); rc = -EINVAL ; }/* Old hvmloader binaries hardcode the size to 128 bytes. */ -if ( a.value ) - a.value |= (128ULL <<32 ) |VM86_TSS_UPDATED ; - a.index =HVM_PARAM_VM86_TSS_SIZED ; +if ( a->value ) + a->value |= (128ULL <<32 ) |VM86_TSS_UPDATED ; + a->index =HVM_PARAM_VM86_TSS_SIZED ;break ;case HVM_PARAM_VM86_TSS_SIZED : -if ( (a.value >>32 ) <sizeof (struct tss32 ) ) +if ( (a->value >>32 ) <sizeof (struct tss32 ) ) {if ( d == curr_d )domain_crash (d);@@ -4322,41 +4308,34 @@ static int hvmop_set_param(* 256 bits interrupt redirection bitmap + 64k bits I/O bitmap * plus one padding byte). */ -if ( (a.value >>32 ) >sizeof (struct tss32 ) + - (0x100 /8 ) + (0x10000 /8 ) +1 ) - a.value = (uint32_t )a.value | - ((sizeof (struct tss32 ) + (0x100 /8 ) + - (0x10000 /8 ) +1 ) <<32 ); - a.value |=VM86_TSS_UPDATED ; +if ( (a->value >>32 ) >sizeof (struct tss32 ) + + (0x100 /8 ) + (0x10000 /8 ) +1 ) + a->value = (uint32_t )a->value | + ((sizeof (struct tss32 ) + (0x100 /8 ) + + (0x10000 /8 ) +1 ) <<32 ); + a->value |=VM86_TSS_UPDATED ;break ;case HVM_PARAM_MCA_CAP : - rc =vmce_enable_mca_cap (d, a.value); + rc =vmce_enable_mca_cap (d, a->value);break ; }if ( rc !=0 ) goto out; - d->arch.hvm.params[a.index] = a.value; + d->arch.hvm.params[a->index] = a->value;HVM_DBG_LOG (DBG_LEVEL_HCALL ,"set param %u = %" PRIx64, - a.index, a.value); + a->index, a->value); out: -rcu_unlock_domain (d);return rc; }static int hvm_allow_get_param (struct domain *d,const struct xen_hvm_param *a) { -int rc; - - rc =xsm_hvm_param (XSM_TARGET , d, HVMOP_get_param); -if ( rc ) -return rc; -switch ( a->index ) {/* The following parameters can be read by the guest and toolstack. */ @@ -4371,7 +4350,7 @@ static int hvm_allow_get_param(struct domain *d,case HVM_PARAM_CONSOLE_EVTCHN :case HVM_PARAM_ALTP2M :case HVM_PARAM_X87_FIP_WIDTH : -break ; +return 0 ;/* * The following parameters are intended for toolstack usage only. @@ -4397,59 +4376,41 @@ static int hvm_allow_get_param(struct domain *d, case HVM_PARAM_IOREQ_SERVER_PFN:case HVM_PARAM_NR_IOREQ_SERVER_PAGES :case HVM_PARAM_MCA_CAP : -if ( d == current->domain ) - rc = -EPERM ; -break ; +return d == current->domain ? -EPERM :0 ;/* Hole, deprecated, or out-of-range. */ default : - rc = -EINVAL ; -break ; +return -EINVAL ; } - -return rc; } -static int hvmop_get_param ( -XEN_GUEST_HANDLE_PARAM (xen_hvm_param_t) arg) +static int hvmop_get_param (struct domain *d,struct xen_hvm_param *a) { -struct xen_hvm_param a; -struct domain *d;int rc; -if (copy_from_guest (&a, arg,1 ) ) -return -EFAULT ; - - d =rcu_lock_domain_by_any_id (a.domid); -if ( d ==NULL ) -return -ESRCH ; - - rc = -EINVAL ; -if ( !is_hvm_domain (d) ) - goto out; - - rc =hvm_allow_get_param (d, &a); + rc =hvm_allow_get_param (d, a);if ( rc ) - goto out; +return rc; -switch ( a.index ) +switch ( a->index ) {case HVM_PARAM_ACPI_S_STATE : - a.value = d->arch.hvm.is_s3_suspended ?3 :0 ; + a->value = d->arch.hvm.is_s3_suspended ?3 :0 ;break ;case HVM_PARAM_VM86_TSS : - a.value = (uint32_t )d- >arch.hvm.params[HVM_PARAM_VM86_TSS_SIZED]; + a->value = (uint32_t )d- >arch.hvm.params[HVM_PARAM_VM86_TSS_SIZED];break ;case HVM_PARAM_VM86_TSS_SIZED : - a.value = d->arch.hvm.params[HVM_PARAM_VM86_TSS_SIZED ] & - ~VM86_TSS_UPDATED ; + a->value = d->arch.hvm.params[HVM_PARAM_VM86_TSS_SIZED ] & + ~VM86_TSS_UPDATED ;break ;case HVM_PARAM_X87_FIP_WIDTH : - a.value = d->arch.x87_fip_width; + a->value = d->arch.x87_fip_width;break ; +case
HVM_PARAM_IOREQ_PFN:
caseHVM_PARAM_BUFIOREQ_PFN:
caseHVM_PARAM_BUFIOREQ_EVTCHN:xen/arch/x86/hvm/hvm.c +39
-15@@ -4465,23 +4426,19 @@ static int hvmop_get_param( rc =hvm_create_ioreq_server (d, true,HVM_IOREQSRV_BUFIOREQ_LEGACY ,NULL );if ( rc !=0 && rc != -EEXIST ) - goto out; +return rc; } -/*FALLTHRU*/ +/* Fallthrough */ default : - a.value = d->arch.hvm.params[a.index]; + a->value = d->arch.hvm.params[a->index];break ; } - rc =__copy_to_guest (arg, &a,1 ) ? -EFAULT :0 ; -HVM_DBG_LOG (DBG_LEVEL_HCALL ,"get param %u = %" PRIx64, - a.index, a.value); + a->index, a->value); - out: -rcu_unlock_domain (d); -return rc; +return 0 ; }/* @@ -4896,14 +4853,42 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) break;case HVMOP_set_param: - rc =hvmop_set_param ( -guest_handle_cast (arg, xen_hvm_param_t)); -break ; -case HVMOP_get_param: - rc =hvmop_get_param ( -guest_handle_cast (arg, xen_hvm_param_t)); + { +struct xen_hvm_param a; +struct domain *d; + + rc = -EFAULT ; +if (copy_from_guest (&a, arg,1 ) ) +break ; + + rc = -ESRCH ; + d =rcu_lock_domain_by_any_id (a.domid); +if ( d ==NULL ) +break ; + + rc = -EINVAL ; +if ( !is_hvm_domain (d) ) + goto param_out; + + rc =xsm_hvm_param (XSM_TARGET , d, op); +if ( rc ) + goto param_out; + +if ( op == HVMOP_set_param ) + rc =hvmop_set_param (d, &a); +else + { + rc =hvmop_get_param (d, &a); + +if ( !rc &&__copy_to_guest (arg, &a,1 ) ) + rc = -EFAULT ; + } + + param_out: +rcu_unlock_domain (d);break ; + }case HVMOP_flush_tlbs:rc = guest_handle_is_null(arg) ? hvmop_flush_tlb_all() : -EINVAL;
Quoted 2 lines
--
2.1.4
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Jan Beulich
Acked-byRe: [PATCH 4/5] x86/hvm: Misc non-functional cleanup to the HVM_PARAM infrastructure
Quoted 17 lines
Quoted 17 lines
Quoted 1 line · On 06.09.18 at 11:26, <[email protected]> wrote:
From: Andrew Cooper [mailto:[email protected]]
Sent: 05 September 2018 19:12The parameter marshalling and xsm checks are common to both the set and get
paths. Lift all of the common code out intodo_hvm_op()and let hvmop_{get,set}_param() operate on structxen_hvm_paramdirectly.This is somewhat noisy in the functions as each a. reference has to change to a-> instead.
In addition, drop an empty default statement, insert newlines as appropriate between cases, and there is no need to update the
IDENT_PTon the fastpath,
because the common path after the switch will make the update.
Quoted 5 lines
Quoted 3 lines
No functional change, but a net shrink of -328 to
do_hvm_op().Signed-off-by Andrew Cooper <[email protected]>Reviewed-by Paul Durrant <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 4/5] x86/hvm: Misc non-functional cleanup to the HVM_PARAM infrastructure
In reply to Andrew CooperQuoted 7 lines · Andrew Cooper
The parameter marshalling and xsm checks are common to both the set and get paths. Lift all of the common code out into
do_hvm_op()and let hvmop_{get,set}_param() operate on structxen_hvm_paramdirectly.This is somewhat noisy in the functions as each a. reference has to change to a-> instead.
Quoted 7 lines
In addition, drop an empty default statement, insert newlines as appropriate between cases, and there is no need to update the
IDENT_PTon the fastpath, because the common path after the switch will make the update.No functional change, but a net shrink of -328 to
do_hvm_op().Signed-off-by Andrew Cooper <[email protected]>
Just two suggestions below.
Quoted 27 lines
xen/arch/x86/hvm/hvm.c +7
-7@@ -4322,41 +4308,34 @@ static int hvmop_set_param(* 256 bits interrupt redirection bitmap + 64k bits I/O bitmap * plus one padding byte). */ -if ( (a.value >>32 ) >sizeof (struct tss32 ) + - (0x100 /8 ) + (0x10000 /8 ) +1 ) - a.value = (uint32_t )a.value | - ((sizeof (struct tss32 ) + (0x100 /8 ) + - (0x10000 /8 ) +1 ) <<32 ); - a.value |=VM86_TSS_UPDATED ; +if ( (a->value >>32 ) >sizeof (struct tss32 ) + + (0x100 /8 ) + (0x10000 /8 ) +1 ) + a->value = (uint32_t )a->value | + ((sizeof (struct tss32 ) + (0x100 /8 ) + + (0x10000 /8 ) +1 ) <<32 ); + a->value |=VM86_TSS_UPDATED ;break ;case HVM_PARAM_MCA_CAP : - rc =vmce_enable_mca_cap (d, a.value); + rc =vmce_enable_mca_cap (d, a->value);break ; }if ( rc !=0 ) goto out;
xen/arch/x86/hvm/hvm.c static int hvmop_set_param( · line 4333
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +2
-3- d->arch.hvm.params[a.index] = a.value; + d->arch.hvm.params[a->index] = a->value;HVM_DBG_LOG (DBG_LEVEL_HCALL ,"set param %u = %" PRIx64, - a.index, a.value); + a->index, a->value); out: -rcu_unlock_domain (d);return rc;
If the out label is just return rc, and unless there's no further patches adding code here I would consider removing it.
Quoted 11 lines
xen/arch/x86/hvm/hvm.c +1
-7-static int hvmop_get_param ( -XEN_GUEST_HANDLE_PARAM (xen_hvm_param_t) arg) +static int hvmop_get_param (struct domain *d,struct xen_hvm_param *a) { -struct xen_hvm_param a; -struct domain *d;int rc; -if (copy_from_guest (&a, arg,1 ) ) -return -EFAULT ; -
xen/arch/x86/hvm/hvm.c static int hvm_allow_get_param(struct domain *d, · line 4391
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +1
-9- d =rcu_lock_domain_by_any_id (a.domid); -if ( d ==NULL ) -return -ESRCH ; - - rc = -EINVAL ; -if ( !is_hvm_domain (d) ) - goto out; - - rc =hvm_allow_get_param (d, &a); + rc =hvm_allow_get_param (d, a);
You could move this initialization at declaration time.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 5/5 xen/ARM: Restrict access to most HVM_PARAM's
In reply to Andrew CooperARM currently has no restrictions on toolstack and guest access to the entire HVM_PARAM block. As the paging/monitor/sharing features aren't under security support, this doesn't need an XSA.
The CALLBACK_IRQ and {STORE,CONSOLE}_{PFN,EVTCHN} details exposed read-only to the guest, while the *_RING_PFN details are restricted to only toolstack access. No other parameters are used.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
This is only compile tested, and based on my reading of the source. There might be other PARAMS needing including.
--- xen/arch/arm/hvm.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 3 deletions(-)
xen/arch/arm/hvm.c +59 -3
@@ -31,6 +31,57 @@#include <asm/hypercall.h> +static int hvm_allow_set_param (const struct domain *d,unsigned int param) +{ +switch ( param ) + { +/* +* The following parameters are intended for toolstack usage only. +* They may not be set by the domain. +*/ +case HVM_PARAM_CALLBACK_IRQ : +case HVM_PARAM_STORE_PFN : +case HVM_PARAM_STORE_EVTCHN : +case HVM_PARAM_CONSOLE_PFN : +case HVM_PARAM_CONSOLE_EVTCHN : +case HVM_PARAM_PAGING_RING_PFN : +case HVM_PARAM_MONITOR_RING_PFN : +case HVM_PARAM_SHARING_RING_PFN : +return d == current->domain ? -EPERM :0 ; + +/* Writeable only by Xen, hole, deprecated, or out-of-range. */ +default : +return -EINVAL ; + } +} + +static int hvm_allow_get_param (const struct domain *d,unsigned int param) +{ +switch ( param ) + { +/* The following parameters can be read by the guest and toolstack. */ +case HVM_PARAM_CALLBACK_IRQ : +case HVM_PARAM_STORE_PFN : +case HVM_PARAM_STORE_EVTCHN : +case HVM_PARAM_CONSOLE_PFN : +case HVM_PARAM_CONSOLE_EVTCHN : +return 0 ; + +/* +* The following parameters are intended for toolstack usage only. +* They may not be read by the domain. +*/ +case HVM_PARAM_PAGING_RING_PFN : +case HVM_PARAM_MONITOR_RING_PFN : +case HVM_PARAM_SHARING_RING_PFN : +return d == current->domain ? -EPERM :0 ; + +/* Hole, deprecated, or out-of-range. */ +default : +return -EINVAL ; + } +} +long do_hvm_op (unsigned long op,XEN_GUEST_HANDLE_PARAM (void ) arg) {long rc =0 ;
@@ -46,9 +97,6 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)if (copy_from_guest (&a, arg,1 ) )return -EFAULT ; -if ( a.index >=HVM_NR_PARAMS ) -return -EINVAL ; - d =rcu_lock_domain_by_any_id (a.domid);if ( d ==NULL )return -ESRCH ;
@@ -59,10 +107,18 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)if ( op == HVMOP_set_param ) { + rc =hvm_allow_set_param (d, a.index); +if ( rc ) + goto param_fail; + d->arch.hvm.params[a.index] = a.value; }else { + rc =hvm_allow_get_param (d, a.index); +if ( rc ) + goto param_fail; + a.value = d->arch.hvm.params[a.index]; rc =copy_to_guest (arg, &a,1 ) ? -EFAULT :0 ; }
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 5/5] xen/ARM: Restrict access to most HVM_PARAM's
Quoted 48 lines
-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 05 September 2018 19:12
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>
Subject: [PATCH 5/5] xen/ARM: Restrict access to most HVM_PARAM'sARM currently has no restrictions on toolstack and guest access to the entire
HVM_PARAMblock. As the paging/monitor/sharing features aren't under security
support, this doesn't need an XSA.The
CALLBACK_IRQand {STORE,CONSOLE}_{PFN,EVTCHN} details exposed read-only to
the guest, while the*_RING_PFNdetails are restricted to only toolstack access. No other parameters are used.Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>This is only compile tested, and based on my reading of the source. There might be other PARAMS needing including.
--- xen/arch/arm/hvm.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 3 deletions(-)xen/arch/arm/hvm.c +3
-0@@ -31,6 +31,57 @@#include <asm/hypercall.h> +static int hvm_allow_set_param (const struct domain *d,unsigned int param) +{ + switch ( param )
xen/arch/arm/hvm.c line 47
Quoted 10 lines
xen/arch/arm/hvm.c +10
-0+ { +/* +* The following parameters are intended for toolstack usage only. +* They may not be set by the domain. +*/ +case HVM_PARAM_CALLBACK_IRQ : +case HVM_PARAM_STORE_PFN : +case HVM_PARAM_STORE_EVTCHN : +case HVM_PARAM_CONSOLE_PFN : +case HVM_PARAM_CONSOLE_EVTCHN :
Probably should remove the EVTCHN params from this list after fixing patch #3.
Quoted 44 lines
xen/arch/arm/hvm.c +38
-0+case HVM_PARAM_PAGING_RING_PFN : +case HVM_PARAM_MONITOR_RING_PFN : +case HVM_PARAM_SHARING_RING_PFN : +return d == current->domain ? -EPERM :0 ; + +/* Writeable only by Xen, hole, deprecated, or out-of-range. */ +default : +return -EINVAL ; + } +} + +static int hvm_allow_get_param (const struct domain *d,unsigned int param) +{ +switch ( param ) + { +/* The following parameters can be read by the guest and toolstack. */ +case HVM_PARAM_CALLBACK_IRQ : +case HVM_PARAM_STORE_PFN : +case HVM_PARAM_STORE_EVTCHN : +case HVM_PARAM_CONSOLE_PFN : +case HVM_PARAM_CONSOLE_EVTCHN : +return 0 ; + +/* +* The following parameters are intended for toolstack usage only. +* They may not be read by the domain. +*/ +case HVM_PARAM_PAGING_RING_PFN : +case HVM_PARAM_MONITOR_RING_PFN : +case HVM_PARAM_SHARING_RING_PFN : +return d == current->domain ? -EPERM :0 ; + +/* Hole, deprecated, or out-of-range. */ +default : +return -EINVAL ; + } +} + long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void)arg)
{ long rc = 0;
xen/arch/arm/hvm.c long do_hvm_op(unsigned long op, · line 52
Quoted 7 lines
xen/arch/arm/hvm.c +0
-3@@ -46,9 +97,6 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)if (copy_from_guest (&a, arg,1 ) )return -EFAULT ; -if ( a.index >=HVM_NR_PARAMS ) -return -EINVAL ; -
ASSERT here.
Paul
Quoted 23 lines
xen/arch/arm/hvm.c +0
-0d =rcu_lock_domain_by_any_id (a.domid);if ( d ==NULL )return -ESRCH;xen/arch/arm/hvm.c +8
-0@@ -59,10 +107,18 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)if ( op == HVMOP_set_param ) { + rc =hvm_allow_set_param (d, a.index); +if ( rc ) + goto param_fail; + d->arch.hvm.params[a.index] = a.value; }else { + rc =hvm_allow_get_param (d, a.index); +if ( rc ) + goto param_fail; + a.value = d->arch.hvm.params[a.index]; rc =copy_to_guest (arg, &a,1 ) ? -EFAULT :0 ;}
Quoted 2 lines
--
2.1.4
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 5/5] xen/ARM: Restrict access to most HVM_PARAM's
Hi Paul,
Quoted 109 lines · Paul Durrant
Quoted 48 lines
-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 05 September 2018 19:12
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>
Subject: [PATCH 5/5] xen/ARM: Restrict access to most HVM_PARAM'sARM currently has no restrictions on toolstack and guest access to the entire
HVM_PARAMblock. As the paging/monitor/sharing features aren't under security
support, this doesn't need an XSA.The
CALLBACK_IRQand {STORE,CONSOLE}_{PFN,EVTCHN} details exposed read-only to
the guest, while the*_RING_PFNdetails are restricted to only toolstack access. No other parameters are used.Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>This is only compile tested, and based on my reading of the source. There might be other PARAMS needing including.
--- xen/arch/arm/hvm.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 3 deletions(-)xen/arch/arm/hvm.c +3
-0@@ -31,6 +31,57 @@#include <asm/hypercall.h> +static int hvm_allow_set_param (const struct domain *d,unsigned int param) +{ + switch ( param )xen/arch/arm/hvm.c line 47
Quoted 10 lines
xen/arch/arm/hvm.c +10
-0+ { +/* +* The following parameters are intended for toolstack usage only. +* They may not be set by the domain. +*/ +case HVM_PARAM_CALLBACK_IRQ : +case HVM_PARAM_STORE_PFN : +case HVM_PARAM_STORE_EVTCHN : +case HVM_PARAM_CONSOLE_PFN : +case HVM_PARAM_CONSOLE_EVTCHN :Probably should remove the EVTCHN params from this list after fixing patch #3.
Quoted 48 lines
xen/arch/arm/hvm.c +38
-0+case HVM_PARAM_PAGING_RING_PFN : +case HVM_PARAM_MONITOR_RING_PFN : +case HVM_PARAM_SHARING_RING_PFN : +return d == current->domain ? -EPERM :0 ; + +/* Writeable only by Xen, hole, deprecated, or out-of-range. */ +default : +return -EINVAL ; + } +} + +static int hvm_allow_get_param (const struct domain *d,unsigned int param) +{ +switch ( param ) + { +/* The following parameters can be read by the guest and toolstack. */ +case HVM_PARAM_CALLBACK_IRQ : +case HVM_PARAM_STORE_PFN : +case HVM_PARAM_STORE_EVTCHN : +case HVM_PARAM_CONSOLE_PFN : +case HVM_PARAM_CONSOLE_EVTCHN : +return 0 ; + +/* +* The following parameters are intended for toolstack usage only. +* They may not be read by the domain. +*/ +case HVM_PARAM_PAGING_RING_PFN : +case HVM_PARAM_MONITOR_RING_PFN : +case HVM_PARAM_SHARING_RING_PFN : +return d == current->domain ? -EPERM :0 ; + +/* Hole, deprecated, or out-of-range. */ +default : +return -EINVAL ; + } +} + long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void)arg)
{ long rc = 0;xen/arch/arm/hvm.c +0
-0@@ -46,9 +97,6 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)if (copy_from_guest (&a, arg,1 ) )return -EFAULT ;
Quoted 5 lines
xen/arch/arm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 51
Quoted 3 lines
xen/arch/arm/hvm.c +0
-3-if ( a.index >=HVM_NR_PARAMS ) -return -EINVAL ; -ASSERT here.
I don't think this would be correct. This is an input from the guest, so if you do fuzzing you will end up to get an hypervisor crash rather than returning an error.
A potential place for an ASSERT would be just before accessing hvm.params. But then, technically the index should have been sanitized by hvm_allow_{get,set}_param.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 5/5] xen/ARM: Restrict access to most HVM_PARAM's
Quoted 127 lines · Julien Grall
Hi Paul,
Quoted 118 lines · Paul Durrant
Quoted 55 lines
-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 05 September 2018 19:12
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>
Subject: [PATCH 5/5] xen/ARM: Restrict access to most HVM_PARAM'sARM currently has no restrictions on toolstack and guest access to the entire
HVM_PARAMblock. As the paging/monitor/sharing features aren't under security
support, this doesn't need an XSA.The
CALLBACK_IRQand {STORE,CONSOLE}_{PFN,EVTCHN} details exposed read-only to
the guest, while the*_RING_PFNdetails are restricted to only toolstack
access. No other parameters are used.Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>This is only compile tested, and based on my reading of the source. There
might be other PARAMS needing including.
---
xen/arch/arm/hvm.c| 62
+++++++++++++++++++++++++++++++++++++++++++++++++++---1 file changed, 59 insertions(+), 3 deletions(-)xen/arch/arm/hvm.c +6
-0@@ -31,6 +31,57 @@ #include <asm/hypercall.h> +static int hvm_allow_set_param (const struct domain *d,unsigned int param) +{ + switch ( param ) + { + /* +* The following parameters are intended for toolstack Quoted 8 lines
usage only.
+ * They may not be set by the domain. + */
+ caseHVM_PARAM_CALLBACK_IRQ:
+ caseHVM_PARAM_STORE_PFN:
+ caseHVM_PARAM_STORE_EVTCHN:
+ caseHVM_PARAM_CONSOLE_PFN:
+ caseHVM_PARAM_CONSOLE_EVTCHN:Probably should remove the EVTCHN params from this list after fixing patch #3.
Quoted 51 lines
+ case
HVM_PARAM_PAGING_RING_PFN:
+ caseHVM_PARAM_MONITOR_RING_PFN:
+ caseHVM_PARAM_SHARING_RING_PFN:
+ return d ==current->domain?-EPERM: 0; +
+ /* Writeable only by Xen, hole, deprecated, or out-of-range. */
+ default:
+ return-EINVAL;
+ }xen/arch/arm/hvm.c +3
-0+} + +static int hvm_allow_get_param(const struct domain *d, unsigned intparam)
+{
+ switch ( param )
+ {
+ /* The following parameters can be read by the guest and toolstack. */
+ caseHVM_PARAM_CALLBACK_IRQ:
+ caseHVM_PARAM_STORE_PFN:
+ caseHVM_PARAM_STORE_EVTCHN:
+ caseHVM_PARAM_CONSOLE_PFN:
+ caseHVM_PARAM_CONSOLE_EVTCHN:
+ return 0;
+
+ /*
+ * The following parameters are intended for toolstack usage only.
+ * They may not be read by the domain.
+ */
+ caseHVM_PARAM_PAGING_RING_PFN:
+ caseHVM_PARAM_MONITOR_RING_PFN:
+ caseHVM_PARAM_SHARING_RING_PFN:
+ return d ==current->domain?-EPERM: 0;xen/arch/arm/hvm.c +7
-0+ + /* Hole, deprecated, or out-of-range. */ + default: + return -EINVAL; + } +} +long
do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)
{
long rc = 0;xen/arch/arm/hvm.c +0
-0@@ -46,9 +97,6 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) if ( copy_from_guest(&a, arg, 1) ) return -EFAULT;Quoted 5 lines
xen/arch/arm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 51
Quoted 3 lines
xen/arch/arm/hvm.c +0
-3- if ( a.index >= HVM_NR_PARAMS ) - return -EINVAL; -ASSERT here.
Quoted 7 lines
I don't think this would be correct. This is an input from the guest, so if you do fuzzing you will end up to get an hypervisor crash rather than returning an error.
A potential place for an ASSERT would be just before accessing hvm.params. But then, technically the index should have been sanitized by hvm_allow_{get,set}_param.
Yeah - across all of these ASSERT() requests - using an assert for a boundary check doesn't do anything in the case where it matters most, and in this case, Julien is correct that it is a fully guest-controlled number at this point.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 5/5] xen/ARM: Restrict access to most HVM_PARAM's
Quoted 146 lines
-----Original Message-----
From: Andrew Cooper
Sent: 06 September 2018 11:40
To: Julien Grall <[email protected]>; Paul Durrant <[email protected]>; Xen-devel <[email protected]>
Cc: Jan Beulich <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; Stefano Stabellini <[email protected]>
Subject: Re: [PATCH 5/5] xen/ARM: Restrict access to most HVM_PARAM'sQuoted 10 lines · Julien Grall
Hi Paul,
Quoted 7 lines · Paul Durrant
Quoted 7 lines
-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 05 September 2018 19:12
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>;Stefano
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Stabellini <[email protected]>; Julien Grall <[email protected]>
Subject: [PATCH 5/5] xen/ARM: Restrict access to most HVM_PARAM'sARM currently has no restrictions on toolstack and guest access to the entire
HVM_PARAMblock. As the paging/monitor/sharing features aren'tunder
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
security
support, this doesn't need an XSA.The
CALLBACK_IRQand {STORE,CONSOLE}_{PFN,EVTCHN} detailsexposed
Quoted 84 lines
Quoted 84 lines
Quoted 37 lines
read-only to
the guest, while the*_RING_PFNdetails are restricted to only toolstack
access. No other parameters are used.Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>This is only compile tested, and based on my reading of the source. There
might be other PARAMS needing including.
---
xen/arch/arm/hvm.c| 62
+++++++++++++++++++++++++++++++++++++++++++++++++++---1 file changed, 59 insertions(+), 3 deletions(-)xen/arch/arm/hvm.c +6
-0@@ -31,6 +31,57 @@ #include <asm/hypercall.h> +static int hvm_allow_set_param (const struct domain *d,unsigned int param) +{ + switch ( param ) + { + /* +* The following parameters are intended for toolstack Quoted 8 lines
usage only.
+ * They may not be set by the domain. + */
+ caseHVM_PARAM_CALLBACK_IRQ:
+ caseHVM_PARAM_STORE_PFN:
+ caseHVM_PARAM_STORE_EVTCHN:
+ caseHVM_PARAM_CONSOLE_PFN:
+ caseHVM_PARAM_CONSOLE_EVTCHN:Probably should remove the EVTCHN params from this list after fixing patch #3.
Quoted 35 lines
+ case
HVM_PARAM_PAGING_RING_PFN:
+ caseHVM_PARAM_MONITOR_RING_PFN:
+ caseHVM_PARAM_SHARING_RING_PFN:
+ return d ==current->domain?-EPERM: 0; +
+ /* Writeable only by Xen, hole, deprecated, or out-of-range. */
+ default:
+ return-EINVAL;
+ }xen/arch/arm/hvm.c +3
-0+} + +static int hvm_allow_get_param(const struct domain *d, unsigned intparam)
+{
+ switch ( param )
+ {
+ /* The following parameters can be read by the guest and toolstack. */
+ caseHVM_PARAM_CALLBACK_IRQ:
+ caseHVM_PARAM_STORE_PFN:
+ caseHVM_PARAM_STORE_EVTCHN:
+ caseHVM_PARAM_CONSOLE_PFN:
+ caseHVM_PARAM_CONSOLE_EVTCHN:
+ return 0;
+
+ /*
+ * The following parameters are intended for toolstack usage only.
+ * They may not be read by the domain.
+ */
+ caseHVM_PARAM_PAGING_RING_PFN:
+ caseHVM_PARAM_MONITOR_RING_PFN:
+ caseHVM_PARAM_SHARING_RING_PFN:
+ return d ==current->domain?-EPERM: 0;Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
xen/arch/arm/hvm.c +7
-0+ + /* Hole, deprecated, or out-of-range. */ + default: + return -EINVAL; + } +} +long do_hvm_op(unsigned long op,
XEN_GUEST_HANDLE_PARAM(void)Quoted 18 lines
Quoted 8 lines
Quoted 8 lines
arg)
{
long rc = 0;xen/arch/arm/hvm.c +0
-0@@ -46,9 +97,6 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) if ( copy_from_guest(&a, arg, 1) ) return -EFAULT;Quoted 5 lines
xen/arch/arm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 51
Quoted 3 lines
xen/arch/arm/hvm.c +0
-3- if ( a.index >= HVM_NR_PARAMS ) - return -EINVAL; -ASSERT here.
I don't think this would be correct. This is an input from the guest, so if you do fuzzing you will end up to get an hypervisor crash rather than returning an error.
Quoted 9 lines
Quoted 3 lines
A potential place for an ASSERT would be just before accessing hvm.params. But then, technically the index should have been sanitized by hvm_allow_{get,set}_param.
Yeah - across all of these
ASSERT()requests - using an assert for a boundary check doesn't do anything in the case where it matters most, and in this case, Julien is correct that it is a fully guest-controlled number at this point.
I'm just uneasy about removing a bounds check. If a logic error creeps into an 'allow' function in future then we'd have no protection. An ASSERT would at least make such a logic error obvious.
Paul
Quoted 1 line
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 5/5] xen/ARM: Restrict access to most HVM_PARAM's
In reply to Julien GrallQuoted 134 lines
-----Original Message-----
From: Julien Grall [mailto:[email protected]]
Sent: 06 September 2018 11:37
To: Paul Durrant <[email protected]>; Andrew Cooper <[email protected]>; Xen-devel <[email protected]>
Cc: Jan Beulich <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; Stefano Stabellini <[email protected]>
Subject: Re: [PATCH 5/5] xen/ARM: Restrict access to most HVM_PARAM'sHi Paul,
Quoted 7 lines · Paul Durrant
Quoted 7 lines
-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 05 September 2018 19:12
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; Paul Durrant <[email protected]>;Stefano
Quoted 4 lines
Quoted 4 lines
Stabellini <[email protected]>; Julien Grall <[email protected]>
Subject: [PATCH 5/5] xen/ARM: Restrict access to most HVM_PARAM'sARM currently has no restrictions on toolstack and guest access to the
entire
Quoted 1 line
Quoted 1 line
HVM_PARAMblock. As the paging/monitor/sharing features aren'tunder
Quoted 4 lines
Quoted 4 lines
security
support, this doesn't need an XSA.The
CALLBACK_IRQand {STORE,CONSOLE}_{PFN,EVTCHN} detailsexposed
Quoted 28 lines
Quoted 28 lines
read-only to
the guest, while the*_RING_PFNdetails are restricted to only toolstack access. No other parameters are used.Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>This is only compile tested, and based on my reading of the source. There might be other PARAMS needing including.
--- xen/arch/arm/hvm.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 3 deletions(-)xen/arch/arm/hvm.c +0
-0@@ -31,6 +31,57 @@#include <asm/hypercall.h> Quoted 16 lines
Quoted 4 lines
xen/arch/arm/hvm.c +3
-0+static int hvm_allow_set_param (const struct domain *d,unsigned int param) +{ + switch ( param )xen/arch/arm/hvm.c line 46
Quoted 10 lines
xen/arch/arm/hvm.c +10
-0+ { +/* +* The following parameters are intended for toolstack usage only. +* They may not be set by the domain. +*/ +case HVM_PARAM_CALLBACK_IRQ : +case HVM_PARAM_STORE_PFN : +case HVM_PARAM_STORE_EVTCHN : +case HVM_PARAM_CONSOLE_PFN : +case HVM_PARAM_CONSOLE_EVTCHN :Probably should remove the EVTCHN params from this list after fixing patch
#3.
Quoted 10 lines
Quoted 10 lines
xen/arch/arm/hvm.c +9
-0+case HVM_PARAM_PAGING_RING_PFN : +case HVM_PARAM_MONITOR_RING_PFN : +case HVM_PARAM_SHARING_RING_PFN : +return d == current->domain ? -EPERM :0 ; + +/* Writeable only by Xen, hole, deprecated, or out-of-range. */ +default : +return -EINVAL ; + }Quoted 8 lines
xen/arch/arm/hvm.c
Quoted 8 lines
xen/arch/arm/hvm.c +7
-0+} + +static int hvm_allow_get_param (const struct domain *d,unsigned int param) +{ +switch ( param ) + { +/* The following parameters can be read by the guest and toolstack. */
Quoted 31 lines
Quoted 31 lines
xen/arch/arm/hvm.c +22
-0+case HVM_PARAM_CALLBACK_IRQ : +case HVM_PARAM_STORE_PFN : +case HVM_PARAM_STORE_EVTCHN : +case HVM_PARAM_CONSOLE_PFN : +case HVM_PARAM_CONSOLE_EVTCHN : +return 0 ; + +/* +* The following parameters are intended for toolstack usage only. +* They may not be read by the domain. +*/ +case HVM_PARAM_PAGING_RING_PFN : +case HVM_PARAM_MONITOR_RING_PFN : +case HVM_PARAM_SHARING_RING_PFN : +return d == current->domain ? -EPERM :0 ; + +/* Hole, deprecated, or out-of-range. */ +default : +return -EINVAL ; + } +} + long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void)arg)
{ long rc = 0;xen/arch/arm/hvm.c +0
-0@@ -46,9 +97,6 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)if (copy_from_guest (&a, arg,1 ) )return -EFAULT ;Quoted 5 lines
xen/arch/arm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 51
Quoted 3 lines
xen/arch/arm/hvm.c +0
-3-if ( a.index >=HVM_NR_PARAMS ) -return -EINVAL ; -ASSERT here.
Quoted 3 lines
I don't think this would be correct. This is an input from the guest, so if you do fuzzing you will end up to get an hypervisor crash rather than returning an error.
Ah, true.
Quoted 5 lines
A potential place for an ASSERT would be just before accessing hvm.params. But then, technically the index should have been sanitized by hvm_allow_{get,set}_param.
Yes, that's where I meant to suggest adding the ASSERT. I wanted it to verify that sanitization.
Paul
Quoted 4 lines
Cheers,
--
Julien Grall
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel