All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: Keir Fraser <keir@xen.org>,
	Paul Durrant <Paul.Durrant@citrix.com>, Tim Deegan <tim@xen.org>,
	Xen-devel <xen-devel@lists.xen.org>
Subject: Re: [PATCH] hvm/load: Correct length checks for zeroextended records
Date: Fri, 24 Oct 2014 17:03:04 +0100	[thread overview]
Message-ID: <544A7838.5060603@citrix.com> (raw)
In-Reply-To: <544A8F9A0200007800042083@mail.emea.novell.com>

On 24/10/14 16:42, Jan Beulich wrote:
>>>> On 23.10.14 at 12:50, <andrew.cooper3@citrix.com> wrote:
>> In the case that Xen is attempting to load a zeroextended HVM record where the
>> difference needing extending would overflow the data blob, 
>> _hvm_check_entry()
>> will incorrectly fail before working out that it would have been safe.
>>
>> The "len + sizeof(*d)" check is wrong.  Consider zeroextending a 16 byte
>> record into a 32 byte structure.  "32 + hdr" will fail the overall context
>> length check even though the pre-extended record in the stream is 16 bytes.
>>
>> The first condition is reduced to just a length check for hvm save header,
>> while the second condition is extended to include a check that the record in
>> the stream not exceeding the stream length.
>>
>> The error messages are extended to include further useful information.
>>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
>> Reviewed-by: Paul Durrant <Paul.Durrant@citrix.com>
> Reviewed-by: Jan Beulich <jbeulich@suse.com>
> albeit with a comment:
>
>> --- a/xen/common/hvm/save.c
>> +++ b/xen/common/hvm/save.c
>> @@ -292,19 +292,22 @@ int _hvm_check_entry(struct hvm_domain_context *h,
>>  {
>>      struct hvm_save_descriptor *d 
>>          = (struct hvm_save_descriptor *)&h->data[h->cur];
>> -    if ( len + sizeof (*d) > h->size - h->cur)
>> +    if ( sizeof(*d) > h->size - h->cur)
>>      {
>>          printk(XENLOG_G_WARNING
>> -               "HVM restore: not enough data left to read %u bytes "
>> -               "for type %u\n", len, type);
>> +               "HVM restore: not enough data left to read %zu bytes "
>> +               "for type %u header\n", sizeof(*d), type);
>>          return -1;
>> -    }    
>> +    }
>>      if ( (type != d->typecode) || (len < d->length) ||
>> -         (strict_length && (len != d->length)) )
>> +         (strict_length && (len != d->length)) ||
> If this is already being overhauled, I'd really like to at once switch to
>
>      if ( (type != d->typecode) ||
>          (strict_length ? (len != d->length) : (len < d->length)) ||
>
> to make more obvious what is really being checked here. Definitely
> no reason to re-submit though.

Looks fine, if you are happy to fix this up on commit?

~Andrew

      reply	other threads:[~2014-10-24 16:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-23 10:50 [PATCH] hvm/load: Correct length checks for zeroextended records Andrew Cooper
2014-10-24 15:42 ` Jan Beulich
2014-10-24 16:03   ` Andrew Cooper [this message]

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=544A7838.5060603@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=Paul.Durrant@citrix.com \
    --cc=keir@xen.org \
    --cc=tim@xen.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.