From patchwork Wed May 9 17:54:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 135324 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp47506lji; Wed, 9 May 2018 10:56:04 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoN6ni59odepY+nesLXZ4ajv6c5BvFmG9nyFmhQUME4oN/KsH4dlH/sQ46namSspms6ljy7 X-Received: by 2002:ac8:37e9:: with SMTP id e38-v6mr28467504qtc.408.1525888564590; Wed, 09 May 2018 10:56:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525888564; cv=none; d=google.com; s=arc-20160816; b=wcr7BDtCSqSBgpJXHN3m336ZRexE1W50kbvvBwNu88qvEwNU0rGYV714tt5UgTItsm rm3DR75pmqWWyPZjpMmK6Z7fD+PWNliQzdrQ0i8yPh75qByIw0Hexjf8SKXzrwVwNoP1 o+xpfu6m+lwmaxZgRTsSIhwlXl4fqDRcRNyGK9275Bquz9zC9qb/teIlSmLoohOmUwRS c9gm2r+/QkLTXGJ9OzoKSYu9i+qa5Bz9J9IJVlJhYXo1WCt+D+YU9lQRiol0hEtWebA9 XW/Y5rK5Oqe8f/ps4z8Zvnye/0eqoGSyl3WsgPpQoDoBc2+311jYo/Nl8WX2hf8P3rOe B+KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=rPj9lU0iZ9WGDR12RZsiZ4M3s0sB5FZV3Ne4MSulYgQ=; b=hPshqqVVXBJBCWrMbmnmLBiEoSzrT3OVwysbrNUKgEppm+4hFmLQwTKq7nNG39feRE TGPqZzfWMgbRjJrbqc/k3+1FGrrgnMTmdQ+x6qnZ/hO2cOJNq27FEkje+oMNmh6e1I7b 074ZgGTNSFwauKeFe5z7fGhOuSAfFhWJEvpLBcgpWMsfsg8XRmdk+kDtjjMt0xBlkfIY Pzch2AxbybOAcTj00ITwS5UFZgpUWLhyHw7V3DXaZlRUWSjKGhGLtJlRcafvcxkF5w+J TvzuAd8FOD2RgBdah99bp6G44qAKUM29BXu8Z7oCH8kCti7B3UEaI+yTTKURDr+Hsaji wo0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ZWDVafZk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id j60-v6si9567932qtb.402.2018.05.09.10.56.04 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 09 May 2018 10:56:04 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ZWDVafZk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:58080 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGTJs-0005DT-1l for patch@linaro.org; Wed, 09 May 2018 13:56:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47576) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGTIx-0004M7-9t for qemu-devel@nongnu.org; Wed, 09 May 2018 13:55:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGTIt-00052p-KX for qemu-devel@nongnu.org; Wed, 09 May 2018 13:55:07 -0400 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]:40591) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGTIt-00051k-Fo for qemu-devel@nongnu.org; Wed, 09 May 2018 13:55:03 -0400 Received: by mail-pf0-x241.google.com with SMTP id f189so25991559pfa.7 for ; Wed, 09 May 2018 10:55:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rPj9lU0iZ9WGDR12RZsiZ4M3s0sB5FZV3Ne4MSulYgQ=; b=ZWDVafZk4j6QUJsTzG3pFTkQOxrdgbTiugj8Adb3n0Mhy1qsP6E5s0bLT9GuRB/N0q h+aTNHtPQ8ttTpitlokdmrdbNej/gR6gaOazefD/rxi5mveQ0X/s27DfVRYJx6ABsGL1 81U+43dKtnCQd1ykPh+VJj1QsGaNj1gmraEYk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rPj9lU0iZ9WGDR12RZsiZ4M3s0sB5FZV3Ne4MSulYgQ=; b=H6Noc7or7ZSMA1iUDo3Gpfr/h3M4o6gguzx5aAuCSfRBeJcZlsrT6ilOjb7VIs46Oi GMsYhdzqEBWAXGjGqcwSi/BuIHrFe9/6r6fnLQ2TxG7Y4IXB0DluNDrH++3ELkFoBG9G zfnrsKcaz7XV2Rnq8rxaeLvMD5ysLEP9FavjOU+GJ7pmMdaEOGfP7EtL4OwPF6eIYvQ1 5cU4Re3vDGgL0EiTyzjYKe/MRwE4JJXsTuvpks4Vy/XGoomZuzBV+sToM0Oj8bAE6Irc 9ogwqEJN3eHGeIYhwRimFbONR4S74oxFJwlBUME7s2BRHanBHgltFfAfrZrd3sku8MRb Gtcw== X-Gm-Message-State: ALKqPwchjZxPteQ1mGovXP2KAKa3bKVGzoHT54T7cxkLKz94w4hyT0Bg oxJgQ2lb+cEnLDO7bloFfJb47VeUoHo= X-Received: by 2002:a65:550d:: with SMTP id f13-v6mr6000914pgr.324.1525888502044; Wed, 09 May 2018 10:55:02 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-2-170.tukw.qwest.net. [97.113.2.170]) by smtp.gmail.com with ESMTPSA id l90sm60332813pfb.149.2018.05.09.10.55.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 09 May 2018 10:55:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 9 May 2018 10:54:31 -0700 Message-Id: <20180509175458.15642-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180509175458.15642-1-richard.henderson@linaro.org> References: <20180509175458.15642-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::241 Subject: [Qemu-devel] [PULL 01/28] target/riscv: avoid integer overflow in next_page PC check X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Sagar Karandikar , David Hildenbrand , Palmer Dabbelt , Mark Cave-Ayland , Max Filippov , Michael Clark , "Edgar E. Iglesias" , Guan Xuetao , Yongbok Kim , Alexander Graf , "Emilio G. Cota" , Richard Henderson , Artyom Tarasenko , Eduardo Habkost , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, Stafford Horne , David Gibson , Peter Crosthwaite , Bastian Koppelmann , Cornelia Huck , Michael Walle , qemu-ppc@nongnu.org, Paolo Bonzini , Aurelien Jarno Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" If the PC is in the last page of the address space, next_page_start overflows to 0. Fix it. Reported-by: Richard Henderson Suggested-by: Richard Henderson Reviewed-by: Richard Henderson Reviewed-by: Michael Clark Acked-by: Bastian Koppelmann Cc: Michael Clark Cc: Palmer Dabbelt Cc: Sagar Karandikar Cc: Bastian Koppelmann Signed-off-by: Emilio G. Cota Signed-off-by: Richard Henderson --- target/riscv/translate.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) -- 2.17.0 diff --git a/target/riscv/translate.c b/target/riscv/translate.c index c0e6a044d3..a98033ca77 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -1850,11 +1850,11 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb) CPURISCVState *env = cs->env_ptr; DisasContext ctx; target_ulong pc_start; - target_ulong next_page_start; + target_ulong page_start; int num_insns; int max_insns; pc_start = tb->pc; - next_page_start = (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; + page_start = pc_start & TARGET_PAGE_MASK; ctx.pc = pc_start; /* once we have GDB, the rest of the translate.c implementation should be @@ -1904,7 +1904,7 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb) if (cs->singlestep_enabled) { break; } - if (ctx.pc >= next_page_start) { + if (ctx.pc - page_start >= TARGET_PAGE_SIZE) { break; } if (tcg_op_buf_full()) {