Received: by 2002:a05:6520:4211:b029:f4:110d:56bc with SMTP id o17csp2115182lkv; Thu, 20 May 2021 03:46:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxNjfG+Sh9raDZWz5KzkIzezMj+f2P3ykG/AP5bf1eDaruOpOtIMcyQkbtBF3a5BWR+Vg5 X-Received: by 2002:a5e:a604:: with SMTP id q4mr5094713ioi.178.1621507572187; Thu, 20 May 2021 03:46:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621507572; cv=none; d=google.com; s=arc-20160816; b=JQhOdKxp/EaLjQaM4jiis26kh/V5AY3xwm5vl8iEogn3PPKNWujUkHW7jjZDdovXp5 UbNvv3X55Q/5NIBcd+BAVDsduDdlZt5W77ng7BtO1/VjH7sgbacKCYmDlWw8X5hvbgBg T9SM5rXJC7XMa24z5x5h6NqYkwaE15aNp2onp1XSMWBSz+s5iQ6zIjUX4GIQNdfhvRUf XpWCgHKWnNpUIlRsQV/AekQ93teZSdjiHMJ8FtDPrFdvXltp0F6v8NutrnwH8wCPIbuI X48P3OPLBgiZ2wVQCpNrafUp6AME7snfz74Iu1+lvzzSRL0qPTzkWwta8l/SxhJdqiKu V/0A== 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:dkim-signature; bh=aPKJTZyiq9+eH7l5nssk3nZEkDWxAPcoV065MxOq9hM=; b=FDJzfi+j9CDXH5gGuMHk5ZP2L2N0k4zmSvcMe5vhfwsMY4XY1pETwwgV6dkV2N4AA+ rgSr8w3UpD1EeTQIXu35+yOaUc9LWeOYPhXpFhMI7d88xk+6JbruiCEv74XM7X8wNTwX glGTpZwj+4UhcD9Uu3p0v6PWpo95Nyu9YW0UbazR6uFJERuQJL6wdJXjv3b79U/jOg9S yVcDaCspjBZg/krxisKJOD4YDDM/aNLJgs/Bm8Bk+2be822R63hUcmzM/OarTW7oG6PJ csQHf5QXHpzMGON3InUBiAGZRoSmGclRV4znW0cRd9eQz885NFhPAWqzS0tEu8ZOMAFb vTnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ByxmkMtS; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q3si2781365ilu.88.2021.05.20.03.45.58; Thu, 20 May 2021 03:46:12 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=ByxmkMtS; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237497AbhETKqD (ORCPT + 99 others); Thu, 20 May 2021 06:46:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:60482 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237161AbhETK3l (ORCPT ); Thu, 20 May 2021 06:29:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7633661186; Thu, 20 May 2021 09:51:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504296; bh=n63INNdp53CnWN4/M9FUKUeIT4BVwDIF/5cVVFzUU1g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ByxmkMtSW9IZZW1qgYLYJM9hWX83aD++P798uAJ9Z0vmq33iFsfufr1dDVMU9NhWn k4ZP/Q9cZQdpsnnT8ZL8xxwbc+RnVBr4MAsQv2wE8/TBjw2H9vFpzTpq64x2QFQY58 PZsbHPGEuIJ2H5gumVkH0h8TeyenoUxdTLmedr5Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Masami Hiramatsu , Ingo Molnar , Sasha Levin Subject: [PATCH 4.14 182/323] x86/kprobes: Fix to check non boostable prefixes correctly Date: Thu, 20 May 2021 11:21:14 +0200 Message-Id: <20210520092126.351299026@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Masami Hiramatsu [ Upstream commit 6dd3b8c9f58816a1354be39559f630cd1bd12159 ] There are 2 bugs in the can_boost() function because of using x86 insn decoder. Since the insn->opcode never has a prefix byte, it can not find CS override prefix in it. And the insn->attr is the attribute of the opcode, thus inat_is_address_size_prefix( insn->attr) always returns false. Fix those by checking each prefix bytes with for_each_insn_prefix loop and getting the correct attribute for each prefix byte. Also, this removes unlikely, because this is a slow path. Fixes: a8d11cd0714f ("kprobes/x86: Consolidate insn decoder users for copying code") Signed-off-by: Masami Hiramatsu Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/161666691162.1120877.2808435205294352583.stgit@devnote2 Signed-off-by: Sasha Levin --- arch/x86/kernel/kprobes/core.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c index 700d434f5bda..cfd8269ab4cd 100644 --- a/arch/x86/kernel/kprobes/core.c +++ b/arch/x86/kernel/kprobes/core.c @@ -173,6 +173,8 @@ NOKPROBE_SYMBOL(skip_prefixes); int can_boost(struct insn *insn, void *addr) { kprobe_opcode_t opcode; + insn_byte_t prefix; + int i; if (search_exception_tables((unsigned long)addr)) return 0; /* Page fault may occur on this address. */ @@ -185,9 +187,14 @@ int can_boost(struct insn *insn, void *addr) if (insn->opcode.nbytes != 1) return 0; - /* Can't boost Address-size override prefix */ - if (unlikely(inat_is_address_size_prefix(insn->attr))) - return 0; + for_each_insn_prefix(insn, i, prefix) { + insn_attr_t attr; + + attr = inat_get_opcode_attribute(prefix); + /* Can't boost Address-size override prefix and CS override prefix */ + if (prefix == 0x2e || inat_is_address_size_prefix(attr)) + return 0; + } opcode = insn->opcode.bytes[0]; @@ -212,8 +219,8 @@ int can_boost(struct insn *insn, void *addr) /* clear and set flags are boostable */ return (opcode == 0xf5 || (0xf7 < opcode && opcode < 0xfe)); default: - /* CS override prefix and call are not boostable */ - return (opcode != 0x2e && opcode != 0x9a); + /* call is not boostable */ + return opcode != 0x9a; } } -- 2.30.2