* [Xen-devel] [PATCH] xen/vcpu: Improve sanity checks in vcpu_create()
@ 2020-01-15 18:44 Andrew Cooper
2020-01-16 9:55 ` Jan Beulich
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Cooper @ 2020-01-15 18:44 UTC (permalink / raw)
To: Xen-devel
Cc: Stefano Stabellini, Julien Grall, Wei Liu, Andrew Cooper,
Jan Beulich, Volodymyr Babchuk, Roger Pau Monné
The BUG_ON() is confusing to follow. The (!is_idle_domain(d) || vcpu_id) part
is a vestigial remnant of architectures poisioning idle_vcpu[0] with non-NULL
pointers.
Now that idle_vcpu[0] is NULL on all architectures, and d->max_vcpus specified
before vcpu_create() is called, we can properly range check the requested
vcpu_id.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Wei Liu <wl@xen.org>
CC: Roger Pau Monné <roger.pau@citrix.com>
CC: Stefano Stabellini <sstabellini@kernel.org>
CC: Julien Grall <julien@xen.org>
CC: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
---
xen/common/domain.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/xen/common/domain.c b/xen/common/domain.c
index 0b1103fdb2..ee3f9ffd3e 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -139,7 +139,19 @@ struct vcpu *vcpu_create(struct domain *d, unsigned int vcpu_id)
{
struct vcpu *v;
- BUG_ON((!is_idle_domain(d) || vcpu_id) && d->vcpu[vcpu_id]);
+ /*
+ * Sanity check some input expectations:
+ * - vcpu_id should be bounded by d->max_vcpus, and not previously
+ * allocated.
+ * - VCPUs should be tightly packed and allocated in ascending order,
+ * except for the idle domain which may vary based on PCPU numbering.
+ */
+ if ( vcpu_id >= d->max_vcpus || d->vcpu[vcpu_id] ||
+ (!is_idle_domain(d) && vcpu_id && !d->vcpu[vcpu_id - 1]) )
+ {
+ ASSERT_UNREACHABLE();
+ return NULL;
+ }
if ( (v = alloc_vcpu_struct(d)) == NULL )
return NULL;
--
2.11.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Xen-devel] [PATCH] xen/vcpu: Improve sanity checks in vcpu_create()
2020-01-15 18:44 [Xen-devel] [PATCH] xen/vcpu: Improve sanity checks in vcpu_create() Andrew Cooper
@ 2020-01-16 9:55 ` Jan Beulich
2020-01-16 10:04 ` Julien Grall
0 siblings, 1 reply; 3+ messages in thread
From: Jan Beulich @ 2020-01-16 9:55 UTC (permalink / raw)
To: Andrew Cooper
Cc: Stefano Stabellini, Julien Grall, Wei Liu, Xen-devel,
Volodymyr Babchuk, Roger Pau Monné
On 15.01.2020 19:44, Andrew Cooper wrote:
> The BUG_ON() is confusing to follow. The (!is_idle_domain(d) || vcpu_id) part
> is a vestigial remnant of architectures poisioning idle_vcpu[0] with non-NULL
> pointers.
>
> Now that idle_vcpu[0] is NULL on all architectures, and d->max_vcpus specified
> before vcpu_create() is called, we can properly range check the requested
> vcpu_id.
I guess this is meant to be true on top of your Arm side change
which hasn't been committed yet? And perhaps better "... starts
out as NULL on all ..."?
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Xen-devel] [PATCH] xen/vcpu: Improve sanity checks in vcpu_create()
2020-01-16 9:55 ` Jan Beulich
@ 2020-01-16 10:04 ` Julien Grall
0 siblings, 0 replies; 3+ messages in thread
From: Julien Grall @ 2020-01-16 10:04 UTC (permalink / raw)
To: Jan Beulich, Andrew Cooper
Cc: Xen-devel, Stefano Stabellini, Volodymyr Babchuk, Wei Liu,
Roger Pau Monné
Hi,
On 16/01/2020 09:55, Jan Beulich wrote:
> On 15.01.2020 19:44, Andrew Cooper wrote:
>> The BUG_ON() is confusing to follow. The (!is_idle_domain(d) || vcpu_id) part
>> is a vestigial remnant of architectures poisioning idle_vcpu[0] with non-NULL
>> pointers.
>>
>> Now that idle_vcpu[0] is NULL on all architectures, and d->max_vcpus specified
>> before vcpu_create() is called, we can properly range check the requested
>> vcpu_id.
>
> I guess this is meant to be true on top of your Arm side change
> which hasn't been committed yet? And perhaps better "... starts
> out as NULL on all ..."?
I can commit the two together.
>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
>
> Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <julien@xen.org>
Cheers,
--
Julien Grall
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-01-16 10:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-15 18:44 [Xen-devel] [PATCH] xen/vcpu: Improve sanity checks in vcpu_create() Andrew Cooper
2020-01-16 9:55 ` Jan Beulich
2020-01-16 10:04 ` Julien Grall
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).