Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4678782pxj; Wed, 12 May 2021 10:42:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyu1ll2wDQ0mqloa388x+ev0XXyyiftg26rxqPDgDwbIj4dMwc6a3QaGsnzxbvK3rQnxCHv X-Received: by 2002:aa7:cc98:: with SMTP id p24mr19981887edt.353.1620841330384; Wed, 12 May 2021 10:42:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620841330; cv=none; d=google.com; s=arc-20160816; b=EqSQNhD68BDUIU4OpTl0EMj89jrRbO0IjlNBldR99Vb5XpyrIBJwgcEe7A+qG/w3nc DTItGwWDnW1NZn7PjWwcsMRwUv8+/5asfS+J/DjEG+uSJESO0/phNlVm/vm1oz7A0K3o xay/nTZMbzSL43Tsb8Qah7uaTjJ1FZtngDuQbUSqVFahHS4+PKsUBGkqe8tDTlIuWpeI U0XSAy4tmOAf25d/O+qO62aXhpSvjb3auE+pQuA7PcBHOtASTiPQCeIgYCmoEeE0gNy0 4SXckk+5etqXiXr7yw+DEwlRmQtNr8dr1lireO34bYLRZ25w+umP6WhQN/LdRfDRTC8k YA4Q== 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=smvOhLZ+/BV5zobK93g4IKNDO+2dMvqF+VN9fkKMjvA=; b=rh9RZwsNyt3vd8MbMNfLsSkX1kgWAsRCIcsEVMVWFp8X0DvbxjrEEPfsGxhGsHXfD+ CZnehN2eEhYcYZwF/CB4T358qk9Q9GVfhKWl0+fcIlAcZs5r2rxyYuud88W1dQngrFza dT/jTmXA38U/w7JT8i8D4bPpmeV02x3aDBiV3G1e5qfWWYemz5yeEga0gYmv38DtIQCr RDe8SU+tLcfe2qIlxi6SlpC8Bzev67r+73VOu4mE1jABk3Jwv//crmxw0PLJ0nGHLV5e o1w4fqvPd2Ml44qmzM/1RWp8teC65JoE+1gcFkczKKoyDInKzdKgGr2tLP1xx605m/0D pijQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HGoLLZc1; 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 g2si532675ejk.687.2021.05.12.10.41.46; Wed, 12 May 2021 10:42:10 -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=HGoLLZc1; 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 S1348278AbhELRfu (ORCPT + 99 others); Wed, 12 May 2021 13:35:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:38986 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236062AbhELQJY (ORCPT ); Wed, 12 May 2021 12:09:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F185961C6F; Wed, 12 May 2021 15:39:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620833993; bh=o1aMEdLcMIIi2aCuOZs0LiyKFH4hJ8Bwlyw02kyAz04=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HGoLLZc1LIjq5uZ+I1Qi29lQ2fTZmUM4LhMhfU7Gdnr6znYjITxUeAkHXoGHvagON rs8hHys1V97WBb/Ee+nLpjP+MR60Cg+TY78FOF96H8PVsMER/ELzZrw6SEYCwQFKdR EATKEAfGMDgP41hErYdXoGhiyuvvP23az5Df/IxU= 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 5.11 333/601] x86/kprobes: Fix to check non boostable prefixes correctly Date: Wed, 12 May 2021 16:46:50 +0200 Message-Id: <20210512144838.763892527@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144827.811958675@linuxfoundation.org> References: <20210512144827.811958675@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 a65e9e97857f..4e81d86a1470 100644 --- a/arch/x86/kernel/kprobes/core.c +++ b/arch/x86/kernel/kprobes/core.c @@ -159,6 +159,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. */ @@ -171,9 +173,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]; @@ -198,8 +205,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