Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp705237pxu; Wed, 2 Dec 2020 00:53:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJy8yjZV4ua+m0Q/LZsEjggn4o1y6AQ7ZfE4DwCCTElOeNHdfXkpo/QH2cPKtgnYSTwnaiMy X-Received: by 2002:a50:eb05:: with SMTP id y5mr1642175edp.250.1606899221042; Wed, 02 Dec 2020 00:53:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606899221; cv=none; d=google.com; s=arc-20160816; b=heNbGwgGtiS/xq7TFI0Kmm2GPuCvtRe3T4VTcVWyTUYYKP1+kWG1JVJ+JNn/6UfN/Y P0OR99JQE8nn6ekleg0v97IlxQIMl9vPALOXl4U82RWTEP9Bwfiw+tjvw5zx2FpYA3Jz GWWhI9gyEIWZElcejfesMiLM++XSedyt8MIuYvad6svqKFWvARvJs8WIIdmQNVHeWh7E clPaPD3QZgwMcneHsXhknA/kZvbnrsnJCKXCjnNA3Tvh2D6/Orgs62wdvyXKErapqPDO op+NR/e5N75Ywcq6GIZ4bsSQ1k3AIOHt4lIUhBxKzYQNU8kxwK+3xeC6QLL6UofqWN5U nMgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=gK9wUNkUrnWd6SHZlQ3hHpk/wRmgc/xVAZUhKsE+TaI=; b=SRHqS60u8bn290I/Thdl8jMhk3PXQ1KNUw7Y1BuwQM2sI2u+nBo5wgURi4PYgL1sGV IJpmLnjRBbVGhTtFhX3/ykIVVpWy9liH2OdKpmwKOtLq/DdxKvtJW/7wcCRhMdZrbx4c 09dO8HLfR2vwnyJkmkS+76BlaKgkl40XcHV6aSkBiYFBxgys9/Mr4FPS0rCq9Ql8T4I1 3dHJeW+u8fK+3a30hKTyF4CqenDvWeR5g2xzsJ2d55SeNBMSJtsWkJHitPtrBewLMBmv kyA7hIG/kDutnxwbe+ZXD2zef17nLWSqYVtOQfPBs8+YXdp4uQW5EQ7YDDWB3KX3hR6J RWag== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z21si617480edx.510.2020.12.02.00.53.17; Wed, 02 Dec 2020 00:53:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387970AbgLBIvv (ORCPT + 99 others); Wed, 2 Dec 2020 03:51:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:36632 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387721AbgLBIvv (ORCPT ); Wed, 2 Dec 2020 03:51:51 -0500 From: Masami Hiramatsu Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: x86@kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov Cc: Kees Cook , Masami Hiramatsu , "H . Peter Anvin" , Joerg Roedel , Tom Lendacky , "Gustavo A . R . Silva" , Jann Horn , Srikar Dronamraju , Ricardo Neri , linux-kernel@vger.kernel.org Subject: [PATCH 1/3] x86/sev-es: Fix not using prefixes.nbytes for loop over prefixes.bytes Date: Wed, 2 Dec 2020 17:51:04 +0900 Message-Id: <160689906460.3084105.3134729514028168934.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <160689905099.3084105.7880450206184269465.stgit@devnote2> References: <160689905099.3084105.7880450206184269465.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since the insn.prefixes.nbytes can be bigger than the size of insn.prefixes.bytes[] when a same prefix is repeated, we have to check whether the insn.prefixes.bytes[i] != 0 and i < 4 instead of insn.prefixes.nbytes. Fixes: 25189d08e516 ("x86/sev-es: Add support for handling IOIO exceptions") Reported-by: Kees Cook Signed-off-by: Masami Hiramatsu --- arch/x86/boot/compressed/sev-es.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/boot/compressed/sev-es.c b/arch/x86/boot/compressed/sev-es.c index 954cb2702e23..6a7a3027c9ac 100644 --- a/arch/x86/boot/compressed/sev-es.c +++ b/arch/x86/boot/compressed/sev-es.c @@ -36,7 +36,7 @@ static bool insn_has_rep_prefix(struct insn *insn) insn_get_prefixes(insn); - for (i = 0; i < insn->prefixes.nbytes; i++) { + for (i = 0; insn->prefixes.bytes[i] && i < 4; i++) { insn_byte_t p = insn->prefixes.bytes[i]; if (p == 0xf2 || p == 0xf3)