Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1606311pxu; Sun, 6 Dec 2020 01:15:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJw9h6IlymzNKu9xwgY9y2muYBk1KiuxOFEQLXQCJZuT1wfI30442GskFkTvxm4m5F+9muon X-Received: by 2002:a05:6402:1714:: with SMTP id y20mr13394423edu.2.1607246146642; Sun, 06 Dec 2020 01:15:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607246146; cv=none; d=google.com; s=arc-20160816; b=c4Ob4n3ppDAKzu8sMEdeCu78CCfD59boYinegH5iNVkci4m3XJUIe88y6HiA8Lt5yA Tz6+fyEgnvGgfCJJ29/MiYrYb+/9YB739DwKhLXoQtVgvsfQRCWQlJytEKIdOQffA4y9 69FZo6oYroyKVUrhSnYHPfwUPmlXn3DG8eV1SK9uooCKS7VOj/g26JExjSbFYo/NpYTS WfEVeGb+BeyoOgbt4ejEJv5m6XfRzB0YghatXA6KolM8ap2luwL3MM1a35XiFFIL/ewQ Cw7pVqDZyq4nxrxUgeZTmjXjeg3Ip5On5NNT1kzZxXUupv0UxzBjAKrMtyXBRqCQk9sA XPxA== 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=7NZzFHvvG3Z44Zmp07YaDC+CpeUesGmzpFQ7cGNXwMA=; b=s0uFjlCr6AbnC6eriuww44U5HOZNflS+F5d1id7MY1EJnHHSdfRF0KGsiHBqFogn45 1/f+H5ij5sH83MRquVajFGp2O/lm/uxILsFyWBOR7jnpv4EIRSJ5FVC+WI3wnZR+5Pxa jun9aL5lI2PP+sO4xMg4ytqBKzifaVNKBm5LOgRiBfxZ+2YtEwxi84jOam/CgY3fZMwe NuKVz7jQPenNefS6od61g4LlcN8u8hFlXqC80MC6k4dZP5U/thdkxU+THbOKEyEHMR9p F+ZJ8jLVXmHd8vk+prqi2ocREI30Iu7dP7MBvVjEuQRSL88YcDb00aWKk25uxT4WVqCh 2qHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Jzqj1AL0; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=3r++y7Wk; 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 h24si5171670ejt.583.2020.12.06.01.15.23; Sun, 06 Dec 2020 01:15:46 -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=Jzqj1AL0; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=3r++y7Wk; 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 S1727535AbgLFJKS (ORCPT + 99 others); Sun, 6 Dec 2020 04:10:18 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:57322 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725980AbgLFJKO (ORCPT ); Sun, 6 Dec 2020 04:10:14 -0500 Date: Sun, 06 Dec 2020 09:09:30 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1607245771; 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=7NZzFHvvG3Z44Zmp07YaDC+CpeUesGmzpFQ7cGNXwMA=; b=Jzqj1AL0I3o5DAgai/EFxT+42mU3dNHtLqDzOfetedseeEr7VEdixGWPxCjCDAlVK5WtoO NHO9RIqBld9XAgF2vwy1mNp7XPmN4ZZwyVWa2la1RthG461v3JSYzHCW28LEpNi3toGGPx atwcIf160Ki5w0eWJcvGY9tT7emUDF283+v44gYGlEGlgER1oMq987nbdnazeP0yuY09nY KZL8xhsJyIM/hhNNtPu6bDMhjUR/5QTHwlr/6/c+OkMXeEA6UK9bbvCOqEEjkLdiG3yVpx i96NvEJ7ZbJ9d1UGtk5F8hv09d2ioYVVG7ghmPiYPng9c6gf0ThGM+VGe5DBBA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1607245771; 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=7NZzFHvvG3Z44Zmp07YaDC+CpeUesGmzpFQ7cGNXwMA=; b=3r++y7WkEsHYKdLsY8zkmZCiD0MXAnHijoPCbAcj1O0Awl1ca97fquFj/KNY6u1hA3yb/r roIgVueEiCVpFzCw== 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: <160724577056.3364.12183431793717178640.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: 12cb908a11b2544b5f53e9af856e6b6a90ed5533 Gitweb: https://git.kernel.org/tip/12cb908a11b2544b5f53e9af856e6b6a90ed5533 Author: Masami Hiramatsu AuthorDate: Thu, 03 Dec 2020 13:50:50 +09:00 Committer: Borislav Petkov CommitterDate: Sun, 06 Dec 2020 10:03:08 +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;