From patchwork Wed May 9 17:54:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10390575 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0295360353 for ; Wed, 9 May 2018 18:11:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E6BE2286B1 for ; Wed, 9 May 2018 18:11:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D9CFF2811A; Wed, 9 May 2018 18:11:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E9A632868F for ; Wed, 9 May 2018 18:11:05 +0000 (UTC) Received: from localhost ([::1]:58204 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGTYO-0004Xy-If for patchwork-qemu-devel@patchwork.kernel.org; Wed, 09 May 2018 14:11:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48170) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGTJD-0004xg-Hc for qemu-devel@nongnu.org; Wed, 09 May 2018 13:55:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGTJ9-0005Wx-8V for qemu-devel@nongnu.org; Wed, 09 May 2018 13:55:23 -0400 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:45813) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGTJ8-0005Uk-Th for qemu-devel@nongnu.org; Wed, 09 May 2018 13:55:19 -0400 Received: by mail-pg0-x244.google.com with SMTP id w3-v6so2473432pgv.12 for ; Wed, 09 May 2018 10:55:18 -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=S/2JGGydUpeF2M5E3pq1XD2DFxk3JsLAsIrsUVrcu1E=; b=DzwQoQdHgXYDTu8EPEgY37Ii0/fGlmbiRVuHuH/kSt8KLyjZ080/YhQ8m/SzJ25Khy G0onN7A/Xp2wUcQV+p89pfQEkBUwuGxIwlcMgSmbt5YVBigIbQx88cTw2MqglJZ0YZTe RH3KET/yx4PpceB2F230ftNxCQ5WV46aPCbCQ= 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=S/2JGGydUpeF2M5E3pq1XD2DFxk3JsLAsIrsUVrcu1E=; b=T0VcTq+yw/W/zGYcdOuxTwXaA9V99+jJu9jTE9lpOtIQyukOxrIa4FPpxKw+lWPhIO u+e+aDrswbmy1UyKzfZu9sUOQXv+5164Cm6PNJfGhzzS19RWTDGtqAxlEDFbdQ0S3syo KifaJistJJo66mT8twVp3GAGjV4e81vKd/avPc/tBt8uLf4MJ8zJbnDozpBofK7FHRi+ bYSwe7Q4xAWoiT3cSs/6MyRxV1mR1SL+08Yi8JUvVDS0VvSdsHpkorMMD1JtFTFsWnyl 3DjlKq4zgB2tqXDIGj9nDktIMA/2/l2tQ88c9gi6K3sPJtwJCPIL/b/uTZNQspJAGlXV QrlA== X-Gm-Message-State: ALQs6tA3sboMnYnUW19kVJAHzOItFri/N4XrvHFFNDzonHHat+QZiilJ NocqyOeYYNoJlX02VvWYlVPIcuGyIZk= X-Google-Smtp-Source: AB8JxZrZ3SZDeSTan2Th9PhH0zi+ZQQSwXXyaNXLxS0tDGWxvvcnJ4yf/2rXqF3RAwRjnyLQi0bpdA== X-Received: by 10.98.157.137 with SMTP id a9mr44574172pfk.206.1525888517560; Wed, 09 May 2018 10:55:17 -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.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 09 May 2018 10:55:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 9 May 2018 10:54:40 -0700 Message-Id: <20180509175458.15642-11-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:c05::244 Subject: [Qemu-devel] [PULL 10/28] target/mips: 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Emilio G. Cota" If the PC is in the last page of the address space, next_page_start overflows to 0. Fix it. Reviewed-by: Richard Henderson Cc: Aurelien Jarno Cc: Yongbok Kim Signed-off-by: Emilio G. Cota Signed-off-by: Richard Henderson --- target/mips/translate.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/target/mips/translate.c b/target/mips/translate.c index d05ee67e63..d8e717dacf 100644 --- a/target/mips/translate.c +++ b/target/mips/translate.c @@ -20202,14 +20202,14 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) CPUMIPSState *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; int insn_bytes; int is_slot; 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; ctx.saved_pc = -1; ctx.singlestep_enabled = cs->singlestep_enabled; @@ -20320,7 +20320,7 @@ void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) break; } - if (ctx.pc >= next_page_start) { + if (ctx.pc - page_start >= TARGET_PAGE_SIZE) { break; }