From patchwork Mon Jun 11 17:10:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 138264 Delivered-To: patches@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp4300880lji; Mon, 11 Jun 2018 10:10:14 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI4o1n83c0JI8A3+Cll0J7oxWNbcppBgyEqejAMTsbeAlhHazJqr8H54rD3En7mrIPNk46k X-Received: by 2002:a1c:aac5:: with SMTP id t188-v6mr1276wme.109.1528737014509; Mon, 11 Jun 2018 10:10:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528737014; cv=none; d=google.com; s=arc-20160816; b=AXfYpOS7QTkR82uN3irqmKJ/FCP5Xc11kY8cWj2+sXj7ChYiADBJGNJNO7kmC63woE kGqC3NtnEum6NQbpqYxDcm43iH7QHCXOEgKLBCE1mzLCHr1qEbPJDBxrs6qUwTRNIAiI bRgabK7su7uJ2vO9tpa0HoeYBsXwTziY5vxTG5FtjiQJJwW3E5xl62vADhlO6ZNEueTa 95GNmj9r5b+vZP+JSW/jTCxKNCN+g2vZZcNxSaEToCTDviZPU19rx31wZZ+9tjALVAPG 4a4m7ugToBE6T/WW99G7Yh2/z5u03ry2PjhGbbjed2bl4V+DadkGDnedy/pz0lkLCm/r OMCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=94UzCZPyGfUFEkrLTyMrzM8AOxG1Y35RAkuC5TAQaVY=; b=kKDaEivCby6c7gP2svqSTyHtx4hzU2pwGc4L/z8vmIPEIPb8xDYXZcd/zdfZ7R7OMF 96rdD38bvPaDzpWlBcRlJMtMTGwlIWhmKyUy4X6AyBTnPJLhDU24I39C4jrTUt/VmrEu t6dTChO98Z3tEAzQMLJsTWq5kzG5Ilkxk5PKTSTrUUnqwazI+jpOWH5ulOLMAzLxTJNF WpvNdGHbR2HNpkJRhRpkQz1504LyNT10PVjSzn4g6ebq2HYVUZdlwuwh9hhSMca3FA6J O9W1nK1Nef6QeHfpLEfTKIGi2jxgvHK9Hy6eq266H1uAZ1Y6M/fn5reiDSLx3tNB2SgQ NnpQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by mx.google.com with ESMTPS id 126-v6si6292854wmg.214.2018.06.11.10.10.14 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Jun 2018 10:10:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) client-ip=2001:8b0:1d0::2; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1fSQKc-0007Ep-1Y; Mon, 11 Jun 2018 18:10:14 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Richard Henderson , Paolo Bonzini Subject: [PATCH 2/3] exec.c: Don't accidentally sign-extend 4-byte loads in subpage_read() Date: Mon, 11 Jun 2018 18:10:06 +0100 Message-Id: <20180611171007.4165-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180611171007.4165-1-peter.maydell@linaro.org> References: <20180611171007.4165-1-peter.maydell@linaro.org> In subpage_read() we perform a load of the data into a local buffer which we then access using ldub_p(), lduw_p(), ldl_p() or ldq_p() depending on its size, storing the result into the uint64_t *data. Since ldl_p() returns an 'int', this means that for the 4-byte case we will sign-extend the data, whereas for 1 and 2 byte reads we zero-extend it. This ought not to matter since the caller will likely ignore values in the high bytes of the data, but add a cast so that we're consistent. Signed-off-by: Peter Maydell --- exec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.17.1 Reviewed-by: Richard Henderson diff --git a/exec.c b/exec.c index 9cbba6adcd3..90b47cde7b1 100644 --- a/exec.c +++ b/exec.c @@ -2747,7 +2747,7 @@ static MemTxResult subpage_read(void *opaque, hwaddr addr, uint64_t *data, *data = lduw_p(buf); return MEMTX_OK; case 4: - *data = ldl_p(buf); + *data = (uint32_t)ldl_p(buf); return MEMTX_OK; case 8: *data = ldq_p(buf);