x86/domctl: Reject XEN_DOMCTL_hypercall_init against oneself
PATCH 1/1 x86/domctl: Reject XEN_DOMCTL_hypercall_init against oneself
A toolstack is expected to use XEN_DOMCTL_hypercall_init where applicable to construct a new guest, but is absolutely not expected to use it against itself. Kernels have a stable ABI for accessing the same functionality, via MSR 0x40000000.
Found when auditing hypercalls for Host UEFI-SecureBoot safety.
---
CC: Anthony PERARD <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Julien Grall <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Ross Lagerwall <[email protected]>
CC: Frediano Ziglio <[email protected]>
--- xen/arch/x86/domctl.c | 8 ++++++++ 1 file changed, 8 insertions(+)
xen/arch/x86/domctl.c +8 -0
@@ -372,6 +372,14 @@ long arch_do_domctl(struct page_info *page;void *hypercall_page; +/* +* Kernels should use the MSR method to get a hypercall page. The +* toolstack should not be using the DOMCTL on itself. +*/ + ret = -EINVAL ; +if ( d == currd ) +break ; + page =get_page_from_gfn (d, gmfn,NULL ,P2M_ALLOC );if ( !page || !get_page_type (page, PGT_writable_page) )
base-commit: 68797a710f4e91cc09fe5650ee14478316010f88
Signature · 1 line
2.39.5
Quoted 9 lines · Andrew Cooper
A toolstack is expected to use
XEN_DOMCTL_hypercall_initwhere applicable to construct a new guest, but is absolutely not expected to use it against itself. Kernels have a stable ABI for accessing the same functionality, via MSR0x40000000.Found when auditing hypercalls for Host UEFI-SecureBoot safety.
Reported-by Frediano Ziglio <[email protected]>Signed-off-by Andrew Cooper <[email protected]>
Quoted 9 lines
---
CC: Anthony PERARD <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Julien Grall <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Ross Lagerwall <[email protected]>
CC: Frediano Ziglio <[email protected]>
It's worth nothing that the observations which lead to this mean it's impossible to support multiple TCB domains without Flask.
Imagine that we did have two control domains and they could operate on each other. It's inappropriate for the domain's kernel to be auditing which domid's are which privilege.
Flask can let Xen express that level of control, and in practice the system would need configuring with a privilege hierarchy. Equally-powerful domains which can operate on each other simply doesn't make sense from a system point of view.
But, as Flask is not supported yet in Xen, the Host UEFI-SB security policy is going to have to be limited to a single all-power dom0 in the short term.
~Andrew
xen/arch/x86/domctl.c long arch_do_domctl( · line 381
Quoted 13 lines · Andrew Cooper
xen/arch/x86/domctl.c +7
-0@@ -372,6 +372,14 @@ long arch_do_domctl(struct page_info *page;void *hypercall_page; +/* +* Kernels should use the MSR method to get a hypercall page. The +* toolstack should not be using the DOMCTL on itself. +*/ + ret = -EINVAL ; +if ( d == currd ) +break ;
Isn't what the comment says more generally true? To act on themselves, most domctl-s are inappropriate to use, I think. There are a few exceptions, where alternatives simply don't exist (and where, if a kernel wanted to use a domctl [or sysctl], it would need to go through hoops to deal with the interface versioning). Yet there's still the question of whether we shouldn't apply this restriction in a broader fashion.
Jan
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
xen/arch/x86/domctl.c +0
-0@@ -372,6 +372,14 @@ long arch_do_domctl(struct page_info *page;void *hypercall_page;
Quoted 13 lines
xen/arch/x86/domctl.c long arch_do_domctl( · line 381
Quoted 7 lines
xen/arch/x86/domctl.c +7
-0+/* +* Kernels should use the MSR method to get a hypercall page. The +* toolstack should not be using the DOMCTL on itself. +*/ + ret = -EINVAL ; +if ( d == currd ) +break ;Isn't what the comment says more generally true? To act on themselves, most domctl-s are inappropriate to use, I think. There are a few exceptions, where alternatives simply don't exist (and where, if a kernel wanted to use a domctl [or sysctl], it would need to go through hoops to deal with the interface versioning). Yet there's still the question of whether we shouldn't apply this restriction in a broader fashion.
I'd go so far as to say that domctls ought to be restricted against oneself, but it's not quite that easy. The majority of them already are restricted because of domain/vcpu_pause(), but this is all ad-hoc.
In principle, the control domain ought to be able to issue some of the getter's on itself, but even that's inconsistent. get_dominfo is permitted, but paging ops are not.
This is still a TBD for the stable tools interfaces. One option I am considering was to split the opcode space by whether it was logically a getter or setter, but I expect this does not work nicely if we also want to retain backwards compatibility.
~Andrew
Jan Beulich
Reviewed-byQuoted 22 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
xen/arch/x86/domctl.c +0
-0@@ -372,6 +372,14 @@ long arch_do_domctl(struct page_info *page;void *hypercall_page;Quoted 13 lines
xen/arch/x86/domctl.c long arch_do_domctl( · line 381
Quoted 7 lines
xen/arch/x86/domctl.c +7
-0+/* +* Kernels should use the MSR method to get a hypercall page. The +* toolstack should not be using the DOMCTL on itself. +*/ + ret = -EINVAL ; +if ( d == currd ) +break ;Isn't what the comment says more generally true? To act on themselves, most domctl-s are inappropriate to use, I think. There are a few exceptions, where alternatives simply don't exist (and where, if a kernel wanted to use a domctl [or sysctl], it would need to go through hoops to deal with the interface versioning). Yet there's still the question of whether we shouldn't apply this restriction in a broader fashion.
Quoted 7 lines
I'd go so far as to say that domctls ought to be restricted against oneself, but it's not quite that easy. The majority of them already are restricted because of domain/vcpu_pause(), but this is all ad-hoc.
In principle, the control domain ought to be able to issue some of the getter's on itself, but even that's inconsistent.
get_dominfois permitted, but paging ops are not.
Hmm, right. And as said, there are a few which simply can't be done a non- domctl way. For the patch here:
Quoted 4 lines
This is still a TBD for the stable tools interfaces. One option I am considering was to split the opcode space by whether it was logically a getter or setter, but I expect this does not work nicely if we also want to retain backwards compatibility.
I didn't expect we'd strive for (binary) backwards compatibility there. Source compatibility (i.e. merely requiring a re-compile) may be a goal, yet even there I wouldn't be certain.
Jan