From: "Jan Beulich" Subject: Re: [PATCH] x86/HVM: avoid pointer wraparound in bufioreq handling Date: Tue, 16 Jun 2015 10:29:45 +0100 Message-ID: <558008A902000078000855E7@mail.emea.novell.com> References: <557EFDA10200007800084F23@mail.emea.novell.com> <557FE1DB0200007800085388@mail.emea.novell.com> <1434442808.13744.39.camel@citrix.com> <557FFC6302000078000854F9@mail.emea.novell.com> <1434445183.13744.61.camel@citrix.com> <9AAE0902D5BC7E449B7C8E4E778ABCD02594F62B@AMSPEX01CL01.citrite.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Z4nBn-0000Cg-5z for xen-devel@lists.xenproject.org; Tue, 16 Jun 2015 09:29:51 +0000 In-Reply-To: <9AAE0902D5BC7E449B7C8E4E778ABCD02594F62B@AMSPEX01CL01.citrite.net> 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: Paul Durrant Cc: Wei Liu , Ian Campbell , Andrew Cooper , Stefano Stabellini , Ian Jackson , xen-devel , "Keir (Xen.org)" List-Id: xen-devel@lists.xenproject.org >>> On 16.06.15 at 11:15, wrote: >> -----Original Message----- >> From: Ian Campbell [mailto:ian.campbell@citrix.com] >> Sent: 16 June 2015 10:00 >> To: Jan Beulich >> Cc: Andrew Cooper; Wei Liu; Ian Jackson; Stefano Stabellini; xen-devel; Keir >> (Xen.org); Paul Durrant >> Subject: Re: [Xen-devel] [PATCH] x86/HVM: avoid pointer wraparound in >> bufioreq handling >> >> On Tue, 2015-06-16 at 09:37 +0100, Jan Beulich wrote: >> > >>> On 16.06.15 at 10:20, wrote: >> > > On Tue, 2015-06-16 at 07:44 +0100, Jan Beulich wrote: >> > >> >>> On 15.06.15 at 16:30, wrote: >> > >> > The number of slots per page being 511 (i.e. not a power of two) >> means >> > >> > that the (32-bit) read and write indexes going beyond 2^32 will likely >> > >> > disturb operation. Extend I/O req server creation so the caller can >> > >> > indicate that it is using suitable atomic accesses where needed (not >> > >> > all accesses to the two pointers really need to be atomic), allowing >> > >> > the hypervisor to atomically canonicalize both pointers when both >> have >> > >> > gone through at least one cycle. >> > >> > >> > >> > Signed-off-by: Jan Beulich >> > >> >> > >> No matter that it's just a single line change, I realized that I >> > >> forgot to Cc the tools maintainers. While a v2 will be needed (see >> > >> the reply just sent to Andrew) I'd still appreciate input (if any) to >> > >> limit the number of revisions needed. >> > > >> > > For such a simple toolstack side change which just reflects the >> > > underlying hcall interface I have no real opinion so far as the tools >> > > side goes, but it would be good to update the comments in xenctrl.h too. >> > > With that done for the tools change: >> > > Acked-by: Ian Campbell >> > >> > Thanks. The request for feedback went beyond the request for >> > an ack though, namely >> > >> > TBD: Do we need to be worried about non-libxc users of the changed >> > (tools only) interface? >> >> It's (currently at least) a declared non-stable API, so in principal no. >> It would be polite to give a heads up to the expected potential users >> though, which you've done by CCing the QEMU maintainers I think. Adding >> Paul D for completeness though. > > From my reading, both QEMU upstream and trad are safe. They use a loop of > the form: > > while (read_ptr != write_ptr) > { > do stuff > > read_ptr += (handled a qword) ? 2 : 1; > } > > So, since the only test is for equality I think overflow should be handled > correctly. So, does anything actually need to be fixed? Of course this needs to be fixed: When either pointer crosses the 2^32 boundary, the slot referenced goes from 0x1f to 0 (due to the "modulo 511" operation determining the slot to be used), introducing a discontinuity and potentially corrupting data in slots not consumed yet. Jan