Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp443533pxu; Fri, 4 Dec 2020 07:07:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJx0hZWadiqQcMiYB3eiGFF5jv9cfENcT5TMEjr36wM31eSrGIzcLieW/K+bosoh5wgFHSby X-Received: by 2002:a17:906:8693:: with SMTP id g19mr7866999ejx.111.1607094421596; Fri, 04 Dec 2020 07:07:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607094421; cv=none; d=google.com; s=arc-20160816; b=Of7MuEXrdezHJih+oI8KelzWoJjU89RmnX+tW3L7P9f8NuUNSu6zyWp/aaaXeCZSF6 FV2yW8qt7ATcsbDlr3o+VXWUo0UULyKPjyR0TrFxMRISKfQSFZjyoB4nQ2Ny2melWI7C qqcmUCwxpGWB+/uhkQ1Sk4tITHfS7t16K9HF+9ho7Ng1GpoNV4RcFzFmK1pyl2Oy++bb rZ355+zlMeHl0MMM4qZYES4KItfJ34rWvnq8VIECfcCKt73AF2cfjm+wq7Jc1vuogNP9 r+kPwz9XCO3HSgk5cVh8a6c6u/jhY643CD5KOlEFJ8kkPyWLTCWeAJw3lQqHYwrro0w8 ce3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=xBCaxiL0BwpvsGon+Ubo0huVSEMgSuM9AICffUzHoL4=; b=sFoBU75FKEdlou3RhgKQfwB48goF1uy+LTTecBJUoqLmWJjHLEtTXtJIB9H0xjEMa/ rSwjuBIVrCIsG8S+keAmOH8V5rA13skuQ9uJOwkG7NfMiSxts5ENIHnAV3zH+nPtLg2e DhS54IjK6wMN6g51dan7pZ9HHFLfw8c8d7bvomsWfw0wRxl3tHXxuOwIdIVhmD6pp/WQ /6qPKyvP5QQGZ7MSopphKuVWiwZxTHDgKJ/Aq1JerGocuq0Ln8BZki2VAS7Au1gojiVw VsnYFlMZCKWZcSiElgc5bluq2pvBGKgcTA9mIq6sxsG4T6T9OkCM4iCKkJ4v7c9xBqTd XNuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=WeYZmWFT; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p11si1510676eja.213.2020.12.04.07.06.38; Fri, 04 Dec 2020 07:07:01 -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; dkim=pass header.i=@linutronix.de header.s=2020 header.b=WeYZmWFT; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730481AbgLDPEv (ORCPT + 99 others); Fri, 4 Dec 2020 10:04:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726715AbgLDPEr (ORCPT ); Fri, 4 Dec 2020 10:04:47 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55127C061A4F; Fri, 4 Dec 2020 07:04:07 -0800 (PST) Date: Fri, 04 Dec 2020 15:04:02 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1607094243; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xBCaxiL0BwpvsGon+Ubo0huVSEMgSuM9AICffUzHoL4=; b=WeYZmWFT6oXOS2joyIN9ktybhrGMDFSF+dTmN1EXmj0ADklm2Sbw1/82FGaNPRDF2bhUiZ ChyYBB/5cgldda85CbEfz/Br8NcU8V9A9uPP6eMu5wkKcIfBNJ1i0E0OjgAxi2qMOotqOo jFdlkcCWLFacLFR5kj2T3XlZUVn8GCZmrEd7WQeW6056X+YetyMIp5UgT2WWiNsHiX3dYI 2vfMJf01O973wyLgsoxzvZBc03RlHfDrXT0iw8CmELiBanSa3UM1MzthbXEVNzpIw6Acyr gR3To21QlNMEgjfmigja0PrWvAdOc4gufVQKlHdn9tN3hXwJKzJ1rPQdTFUZQg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1607094243; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xBCaxiL0BwpvsGon+Ubo0huVSEMgSuM9AICffUzHoL4=; b=Nv305dDBeHp7Yn0y+iSByf6vZP8WQz6lbzt0F0H+orNJMCia1EniqbMkguqeEVs33Wpv7F o0tMkGT/lOZe0LCw== From: "tip-bot2 for Masami Hiramatsu" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] x86/insn-eval: Use new for_each_insn_prefix() macro to loop over prefixes bytes Cc: syzbot+9b64b619f10f19d19a7c@syzkaller.appspotmail.com, Masami Hiramatsu , Borislav Petkov , stable@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <160697104969.3146288.16329307586428270032.stgit@devnote2> References: <160697104969.3146288.16329307586428270032.stgit@devnote2> MIME-Version: 1.0 Message-ID: <160709424284.3364.1019606320631046834.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/urgent branch of tip: Commit-ID: 2d7896c24ec977e91af1ff93c823032a27212700 Gitweb: https://git.kernel.org/tip/2d7896c24ec977e91af1ff93c823032a27212700 Author: Masami Hiramatsu AuthorDate: Thu, 03 Dec 2020 13:50:50 +09:00 Committer: Borislav Petkov CommitterDate: Fri, 04 Dec 2020 14:33:51 +01:00 x86/insn-eval: Use new for_each_insn_prefix() macro to loop over prefixes bytes Since insn.prefixes.nbytes can be bigger than the size of insn.prefixes.bytes[] when a prefix is repeated, the proper check must be insn.prefixes.bytes[i] != 0 and i < 4 instead of using insn.prefixes.nbytes. Use the new for_each_insn_prefix() macro which does it correctly. Debugged by Kees Cook . [ bp: Massage commit message. ] Fixes: 32d0b95300db ("x86/insn-eval: Add utility functions to get segment selector") Reported-by: syzbot+9b64b619f10f19d19a7c@syzkaller.appspotmail.com Signed-off-by: Masami Hiramatsu Signed-off-by: Borislav Petkov Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/160697104969.3146288.16329307586428270032.stgit@devnote2 --- arch/x86/lib/insn-eval.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/x86/lib/insn-eval.c b/arch/x86/lib/insn-eval.c index 58f7fb9..4229950 100644 --- a/arch/x86/lib/insn-eval.c +++ b/arch/x86/lib/insn-eval.c @@ -63,13 +63,12 @@ static bool is_string_insn(struct insn *insn) */ 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; } @@ -95,14 +94,15 @@ static int get_seg_reg_override_idx(struct insn *insn) { int idx = INAT_SEG_REG_DEFAULT; int num_overrides = 0, i; + insn_byte_t p; insn_get_prefixes(insn); /* Look for any segment override prefixes. */ - for (i = 0; i < insn->prefixes.nbytes; i++) { + for_each_insn_prefix(insn, i, p) { insn_attr_t attr; - attr = inat_get_opcode_attribute(insn->prefixes.bytes[i]); + attr = inat_get_opcode_attribute(p); switch (attr) { case INAT_MAKE_PREFIX(INAT_PFX_CS): idx = INAT_SEG_REG_CS;