From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Razvan Cojocaru <rcojocaru@bitdefender.com>,
Jan Beulich <JBeulich@suse.com>
Cc: sstabellini@kernel.org, wei.liu2@citrix.com,
George.Dunlap@eu.citrix.com, ian.jackson@eu.citrix.com,
tim@xen.org, xen-devel@lists.xen.org
Subject: Re: [PATCH] xen/hvm: fix hypervisor crash with hvm_save_one()
Date: Tue, 2 May 2017 15:17:31 +0100 [thread overview]
Message-ID: <c49d9fef-fae7-0722-6bc1-41de4ad88936@citrix.com> (raw)
In-Reply-To: <0e615fd3-bea9-99a5-fc11-ee0a887b6e80@bitdefender.com>
On 02/05/17 15:13, Razvan Cojocaru wrote:
> On 05/02/17 17:09, Jan Beulich wrote:
>>>>> On 02.05.17 at 15:54, <rcojocaru@bitdefender.com> wrote:
>>> On 05/02/17 16:48, Jan Beulich wrote:
>>>>>>> On 02.05.17 at 15:25, <rcojocaru@bitdefender.com> wrote:
>>>>> --- a/xen/common/hvm/save.c
>>>>> +++ b/xen/common/hvm/save.c
>>>>> @@ -113,7 +113,7 @@ int hvm_save_one(struct domain *d, uint16_t typecode, uint16_t instance,
>>>>> const struct hvm_save_descriptor *desc;
>>>>>
>>>>> rv = -ENOENT;
>>>>> - for ( off = 0; off < (ctxt.cur - sizeof(*desc)); off += desc->length
>>> )
>>>>> + for ( off = 0; (off + sizeof(*desc)) < ctxt.cur; off += desc->length
>>> )
>>>>> {
>>>>> desc = (void *)(ctxt.data + off);
>>>>> /* Move past header */
>>>> I don't think this is an appropriate fix. Instead I think the function
>>>> should check whether it got back any data at all, prior to entering
>>>> the loop. Furthermore it might be worth considering to (also)
>>>> refuse doing anything here if the domain's is_dying marker has
>>>> already been set.
>>> hvm_save_one() already checks is_dying:
>>>
>>> 77 /* Extract a single instance of a save record, by marshalling all
>>> 78 * records of that type and copying out the one we need. */
>>> 79 int hvm_save_one(struct domain *d, uint16_t typecode, uint16_t
>>> instance,
>>> 80 XEN_GUEST_HANDLE_64(uint8) handle)
>>> 81 {
>>> 82 int rv = 0;
>>> 83 size_t sz = 0;
>>> 84 struct vcpu *v;
>>> 85 hvm_domain_context_t ctxt = { 0, };
>>> 86
>>> 87 if ( d->is_dying
>>> 88 || typecode > HVM_SAVE_CODE_MAX
>>> 89 || hvm_sr_handlers[typecode].size < sizeof(struct
>>> hvm_save_descriptor)
>>> 90 || hvm_sr_handlers[typecode].save == NULL )
>>> 91 return -EINVAL;
>> Hmm, interesting. The timing window to see is_dying clear here,
>> bit no vCPU-s left there should be pretty small, so I wonder how
>> you've managed to hit it. But anyway ...
>>
>>> As for checking whether the handler wrote any data, I believe that
>>> Andrew has checked and none of the handlers report when no data is being
>>> passed on.
>> ... that's not what I've read out of his replies. I don't think the
>> handlers need to report anything special. It is the caller which
>> should check whether, despite having got back "success" there's
>> no data in the buffer.
> So you would prefer something like this?
>
> diff --git a/xen/common/hvm/save.c b/xen/common/hvm/save.c
> index 78706f5..d4c8d84 100644
> --- a/xen/common/hvm/save.c
> +++ b/xen/common/hvm/save.c
> @@ -113,6 +113,10 @@ int hvm_save_one(struct domain *d, uint16_t
> typecode, uint16_t instance,
> const struct hvm_save_descriptor *desc;
>
> rv = -ENOENT;
> +
> + if ( !ctxt.cur )
> + goto out;
> +
> for ( off = 0; off < (ctxt.cur - sizeof(*desc)); off +=
> desc->length )
> {
> desc = (void *)(ctxt.data + off);
> @@ -132,6 +136,7 @@ int hvm_save_one(struct domain *d, uint16_t
> typecode, uint16_t instance,
> }
> }
>
> +out:
> xfree(ctxt.data);
> return rv;
> }
For the record, I am -1 for this, because it does not fix the problem
when ctxt.cur has a value between 1 and sizeof(*desc).
~Andrew
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-05-02 14:17 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-02 13:25 [PATCH] xen/hvm: fix hypervisor crash with hvm_save_one() Razvan Cojocaru
2017-05-02 13:39 ` Andrew Cooper
2017-05-02 13:41 ` Tim Deegan
2017-05-02 13:42 ` Razvan Cojocaru
2017-05-02 13:48 ` Jan Beulich
2017-05-02 13:54 ` Razvan Cojocaru
2017-05-02 14:09 ` Jan Beulich
2017-05-02 14:13 ` Razvan Cojocaru
2017-05-02 14:17 ` Andrew Cooper [this message]
2017-05-02 14:42 ` Jan Beulich
2017-05-02 13:55 ` Andrew Cooper
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c49d9fef-fae7-0722-6bc1-41de4ad88936@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=George.Dunlap@eu.citrix.com \
--cc=JBeulich@suse.com \
--cc=ian.jackson@eu.citrix.com \
--cc=rcojocaru@bitdefender.com \
--cc=sstabellini@kernel.org \
--cc=tim@xen.org \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).