From patchwork Thu Mar 23 17:57:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pranith Kumar X-Patchwork-Id: 9641747 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 8D1AE601E9 for ; Thu, 23 Mar 2017 17:58:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A47725404 for ; Thu, 23 Mar 2017 17:58:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E0FB2841E; Thu, 23 Mar 2017 17:58:05 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 4A2A925404 for ; Thu, 23 Mar 2017 17:58:04 +0000 (UTC) Received: from localhost ([::1]:57771 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cr6zq-0007GT-RM for patchwork-qemu-devel@patchwork.kernel.org; Thu, 23 Mar 2017 13:58:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59291) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cr6zA-0007GC-3v for qemu-devel@nongnu.org; Thu, 23 Mar 2017 13:57:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cr6z7-0001S5-0C for qemu-devel@nongnu.org; Thu, 23 Mar 2017 13:57:20 -0400 Received: from mail-yw0-x244.google.com ([2607:f8b0:4002:c05::244]:33730) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cr6z6-0001Rv-RI for qemu-devel@nongnu.org; Thu, 23 Mar 2017 13:57:16 -0400 Received: by mail-yw0-x244.google.com with SMTP id p77so24404221ywg.0 for ; Thu, 23 Mar 2017 10:57:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=iOKSJ+Cl//R+bhbRtkQfeRn0IBBU0g0JzOikbXt5xkc=; b=g5Sm5XkYEYuZzqO2OL/nIwuEfsI1v6d2C6I+nKXpT+gUzi3tIA7ATOaumT7xzPNEv+ pLDtiCX6K/oKLoO8HeoqjI5HiprI5U8roscAp8MALAK0F6ydtuBa5/67vInawpKBegSc 94xA5+Rch8P2UN4rfwUNlu6QApipKBXataWPuXA1BclfHGbYbpKxVhrzbPt2+ptmd0WP 7zKJCnhO4kIaotz7zXyU17egFDVsE+2EudgNyifXM4DrhyOyq+UiaH/eC9Uh7me/34VS bs8EI7lXGhmOiKM2DnBXEJqtSzOyuKtuv9SLsnnP2SKyq0IMPPybv7mw8kqOt3RyfOgJ DxHQ== 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; bh=iOKSJ+Cl//R+bhbRtkQfeRn0IBBU0g0JzOikbXt5xkc=; b=l2uAAVBAJXH48xoGIJQMVOb9aZbQGqiyTtPd0ZSqMk0Atzcg1fJsbOFAYJqkrAkESC +Xw+H/Ai8vUe+PjpzJhFpFuQFKIPf7xvPqUD7kYy11lDrFxAlC6C30MgVIhK5nKK3fpi 1L0QlkeXBPjx/EZVpgLzG5RhT+bRMal5FZ2ItioBZ1NHNuUOUw4JstYTZpRG4adacMXw LK/W3iqi6yYaYomIUk0DNVU5G+xAW47ujt/UxLhc8cnAkef1AO6SdO0gKMqIG9HcK65b YWYnIw48SyYrfXRBQy9rzcpMB+eYEn5iuVmFd+PAEyphR63LkvCtZB87BpizSEXSqeLK +Viw== X-Gm-Message-State: AFeK/H3QFEqMV/knlAEsnBP2DfJerjceyrdpofsOpR08YMUm3YI/lrNGES2o9kzKCLbdlw== X-Received: by 10.13.204.206 with SMTP id o197mr2873596ywd.87.1490291835914; Thu, 23 Mar 2017 10:57:15 -0700 (PDT) Received: from localhost.localdomain (c-73-207-178-95.hsd1.ga.comcast.net. [73.207.178.95]) by smtp.gmail.com with ESMTPSA id o8sm1920890ywo.65.2017.03.23.10.57.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Mar 2017 10:57:15 -0700 (PDT) From: Pranith Kumar To: Paolo Bonzini , Richard Henderson , Eduardo Habkost , qemu-devel@nongnu.org (open list:All patches CC here) Date: Thu, 23 Mar 2017 13:57:13 -0400 Message-Id: <20170323175713.12984-1-bobby.prani@gmail.com> X-Mailer: git-send-email 2.11.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4002:c05::244 Subject: [Qemu-devel] [PATCH] tcg/i386: Check the size of instruction being translated 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 , Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This fixes the bug: 'user-to-root privesc inside VM via bad translation caching' reported by Jann Horn here: https://bugs.chromium.org/p/project-zero/issues/detail?id=1122 CC: Richard Henderson CC: Peter Maydell CC: Paolo Bonzini Reported-by: Jann Horn Signed-off-by: Pranith Kumar --- target/i386/translate.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/target/i386/translate.c b/target/i386/translate.c index 72c1b03a2a..1d1372fb43 100644 --- a/target/i386/translate.c +++ b/target/i386/translate.c @@ -4418,6 +4418,13 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s, s->vex_l = 0; s->vex_v = 0; next_byte: + /* x86 has an upper limit of 15 bytes for an instruction. Since we + * do not want to decode and generate IR for an illegal + * instruction, the following check limits the instruction size to + * 25 bytes: 14 prefix + 1 opc + 6 (modrm+sib+ofs) + 4 imm */ + if (s->pc - pc_start > 14) { + goto illegal_op; + } b = cpu_ldub_code(env, s->pc); s->pc++; /* Collect prefixes. */