From patchwork Fri Dec 18 15:17:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 558997 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 93F201401AD for ; Sat, 19 Dec 2015 04:06:07 +1100 (AEDT) Received: from localhost ([::1]:33845 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9yTl-0001BR-BJ for incoming@patchwork.ozlabs.org; Fri, 18 Dec 2015 12:06:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33282) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9wno-0002VX-MW for qemu-devel@nongnu.org; Fri, 18 Dec 2015 10:18:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a9wnj-0006ni-Se for qemu-devel@nongnu.org; Fri, 18 Dec 2015 10:18:40 -0500 Received: from smtp.citrix.com ([66.165.176.89]:47816) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9wnj-0006nc-LZ; Fri, 18 Dec 2015 10:18:35 -0500 X-IronPort-AV: E=Sophos;i="5.20,446,1444694400"; d="scan'208";a="320302172" From: Stefano Stabellini To: Date: Fri, 18 Dec 2015 15:17:56 +0000 Message-ID: <1450451877-25157-1-git-send-email-stefano.stabellini@eu.citrix.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 X-DLP: MIA1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.89 Cc: qemu-stable@nongnu.org, xen-devel@lists.xensource.com, qemu-devel@nongnu.org, stefano.stabellini@eu.citrix.com Subject: [Qemu-devel] [PULL 1/2] xen/blkif: Avoid double access to src->nr_segments X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org src is stored in shared memory and src->nr_segments is dereferenced twice at the end of the function. If a compiler decides to compile this into two separate memory accesses then the size limitation could be bypassed. Fix it by removing the double access to src->nr_segments. This is part of XSA-155. Signed-off-by: Stefano Stabellini --- hw/block/xen_blkif.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/hw/block/xen_blkif.h b/hw/block/xen_blkif.h index 711b692..c68487cb 100644 --- a/hw/block/xen_blkif.h +++ b/hw/block/xen_blkif.h @@ -85,8 +85,10 @@ static inline void blkif_get_x86_32_req(blkif_request_t *dst, blkif_x86_32_reque d->nr_sectors = s->nr_sectors; return; } - if (n > src->nr_segments) - n = src->nr_segments; + /* prevent the compiler from optimizing the code and using src->nr_segments instead */ + barrier(); + if (n > dst->nr_segments) + n = dst->nr_segments; for (i = 0; i < n; i++) dst->seg[i] = src->seg[i]; } @@ -106,8 +108,10 @@ static inline void blkif_get_x86_64_req(blkif_request_t *dst, blkif_x86_64_reque d->nr_sectors = s->nr_sectors; return; } - if (n > src->nr_segments) - n = src->nr_segments; + /* prevent the compiler from optimizing the code and using src->nr_segments instead */ + barrier(); + if (n > dst->nr_segments) + n = dst->nr_segments; for (i = 0; i < n; i++) dst->seg[i] = src->seg[i]; }