From: "Jan Beulich" Subject: Re: [BUGFIX][PATCH 4/4] hvm_save_one: allow the 2nd instance to be fetched for PIC. Date: Fri, 13 Dec 2013 14:38:12 +0000 Message-ID: <52AB29E4020000780010D0EE@nat28.tlf.novell.com> References: <1386809777-12898-1-git-send-email-dslutz@terremark.com> <1386809777-12898-5-git-send-email-dslutz@terremark.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1VrTsd-0006xb-V6 for xen-devel@lists.xenproject.org; Fri, 13 Dec 2013 14:38:16 +0000 In-Reply-To: <1386809777-12898-5-git-send-email-dslutz@terremark.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Don Slutz Cc: xen-devel , Keir Fraser , Ian Jackson , Ian Campbell , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org >>> On 12.12.13 at 01:56, Don Slutz wrote: > @@ -114,20 +111,20 @@ int hvm_save_one(struct domain *d, uint16_t typecode, uint16_t instance, > } > else > { > - uint32_t off; > + uint32_t off, add; "add" is a pretty odd name for what this is being used for. Why don't you use desc->length directly? > > rv = -EBADSLT; > - for (off = 0; off < ctxt.cur; off += hvm_sr_handlers[typecode].size) { > + for (off = 0; off < ctxt.cur; off += add + sizeof (struct hvm_save_descriptor)) { > struct hvm_save_descriptor *desc > = (struct hvm_save_descriptor *)&ctxt.data[off]; > + add = desc->length; > if (instance == desc->instance) { > rv = 0; > if ( copy_to_guest(handle, > ctxt.data > + off > + sizeof (struct hvm_save_descriptor), > - hvm_sr_handlers[typecode].size > - - sizeof (struct hvm_save_descriptor)) ) > + add) ) Further, the way this was done before means that for multi- instance records all records would get copied out, but the caller would have no way of knowing that (except by implying that behavior, e.g. "known to be the case for PIC"). Which shows another shortcoming of the interface: There's no buffer size being passed in from the caller, yet we have variable size records. Which means latent data corruption in the caller. Hence I think rather than complicating the logic here, we should change the interface to pass a size in and back out, which will not only avoid corrupting memory, but also allow the guest to recognize multi-instance data being returned. Jan