Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp226233pxu; Wed, 2 Dec 2020 20:55:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJy68u3PVny9rzUhNPYM/GpxGD/3hvcANLjLlSxDJNRGaxXGkTsp7XyN+WcnYtKmAw0k7zTi X-Received: by 2002:a17:906:259a:: with SMTP id m26mr968574ejb.399.1606971348709; Wed, 02 Dec 2020 20:55:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606971348; cv=none; d=google.com; s=arc-20160816; b=VOOyI1qJgc8Ylzv1Rgff2oGWoWNnAR+MznoV0LQfcThk+WcCueHfOL1WreGs3teQUU rN8R5Z9onHSEJ+YkICxYYpWfLnitQ16EA2EsLfCgSyst43Qu/D0LTxE4EW83qM1vIvan CRrF9rqywt+kay9qUZNFt0CWLmG5ZfmH7y8aWeqjqDyP2S6IGpgCG7ywj52MKoE49zD4 EZnH3O1JU+Ak//tezPDBPOG6BIsWpDXeZ6cij0hbWoIo289/vdyat3zEqSyye3G1BQ1t eKGQVqi0LSTt4bwrmVmhfYHSesEDzFo4hsMKbuTCOCqN0UsQbXajsyn7AqRASwd4Ht1R S4gw== 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=V+q5J0HE8Mo5i8MrTbTDpL3mIAWiXuW4fNbbtirgKyM=; b=KZPgg6xZv++v80MXzffN5rSeQLhRzxHgGghzFwXbhoTaBObRww3Uoe1T6eqGdMSydy hqkNijIQV83wIVrol2LoxR1OVTDg+6k2Qj8qCHH2KF4Ie4VSjprqNjIwY95tkpoxiqkk t0iBeyDdYOF6YzxRNbJQp/ayk8yv8UF3Q0f6ZEn4Q3m3riMVqj9ZVxNg1Lkar/ZRfN0U 6K/6Ra6awiyMcs8nleWLCpJZDtvcWG3mL94/WgHVtu/PI1ddcenPNvZD7FvaHD7F746Z edrWBmQuksqCLr7MtcHdzmpGC3G9yVGaaAmK2BZrQb5iYgIA4mhyqDjioMNWg2gOI7K4 WjKw== 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 a21si435157ejd.281.2020.12.02.20.55.26; Wed, 02 Dec 2020 20:55:48 -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 S1727794AbgLCEvr (ORCPT + 99 others); Wed, 2 Dec 2020 23:51:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:47998 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725933AbgLCEvr (ORCPT ); Wed, 2 Dec 2020 23:51:47 -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 v2 3/3] x86/sev-es: Fix not using prefixes.nbytes for loop over prefixes.bytes Date: Thu, 3 Dec 2020 13:51:01 +0900 Message-Id: <160697106089.3146288.2052422845039649176.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <160697102582.3146288.10127018634865687932.stgit@devnote2> References: <160697102582.3146288.10127018634865687932.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 i < 4 and insn.prefixes.bytes[i] != 0 instead of insn.prefixes.nbytes. Fixes: 25189d08e516 ("x86/sev-es: Add support for handling IOIO exceptions") Reported-by: syzbot+9b64b619f10f19d19a7c@syzkaller.appspotmail.com Debugged-by: Kees Cook Signed-off-by: Masami Hiramatsu --- arch/x86/boot/compressed/sev-es.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/x86/boot/compressed/sev-es.c b/arch/x86/boot/compressed/sev-es.c index 954cb2702e23..27826c265aab 100644 --- a/arch/x86/boot/compressed/sev-es.c +++ b/arch/x86/boot/compressed/sev-es.c @@ -32,13 +32,12 @@ struct ghcb *boot_ghcb; */ static bool insn_has_rep_prefix(struct insn *insn) { + insn_byte_t p; int i; insn_get_prefixes(insn); - for (i = 0; i < insn->prefixes.nbytes; i++) { - insn_byte_t p = insn->prefixes.bytes[i]; - + for_each_insn_prefix(insn, i, p) { if (p == 0xf2 || p == 0xf3) return true; }