Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4618432pxj; Wed, 12 May 2021 09:21:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTt0EzMqeVxJrLYhntC/PfYme8mZgfJIomnxJnMo9Mv0LnMC8hHw3yZ53PCOoUNvgQMO5a X-Received: by 2002:aa7:c903:: with SMTP id b3mr44795416edt.296.1620836466558; Wed, 12 May 2021 09:21:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620836466; cv=none; d=google.com; s=arc-20160816; b=zQw7L60M11yb6fJ4e5u5t7CEBNnzmEKskRPl0MhpXLk9RvjzCDNcELURbyZ6JagTEA Tr3Q40BfrFkuF8CJxB7NbBdE4o+lIYpkYyuPNQ8bMuuu6NSl+hQr/+yBnwGCORbxJq3N gPKYHveV7qZ1xpYlvlSLU2hU5nfbh53/um72AzlyjToHq9HowOUrkHXgAouMVkDnMAb+ Y4mVYd/ffnaTNCrFfbyvQfReSdL4NxBM+gGSYaFZIuVhh+tMfxN42p/gocbMJ62uRgPP SCQ8VzVWSktMlCCuDGf7woyys2bTBSG2CsaJ5G3oK/K0I1TBSFDTdbhnug675HuYzMft Ybdw== 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=hzH9ukAcjNqRmDDb6Reokj/eMFYWOStkcyeZBAREsP4=; b=vapjgT0y1qO9MRPK7f0tuypcQOXojZgYCvKfYI7wop9bJwRLdEACbHRz4mhIVUcfoH EGtX0AAqiJSSa8ZFFyOTLXYwMBlga65QRUp+OLEgbbgclUym6iVfFu8z/dL+SVNoLTAq XHpP27TWbVRP7LbC5zM4pm+Qb8U7bhWhuWpVrOQUSqFSXwGwx87QvaBoQNe2iCMyjuD+ wIWzFi8hdlBwnoGUTmfBdGvNS3TcMh4Hh/TPEb1CHP/JHs5ayz2ksQ0E8wMPvjGQlk4E DDcN0e0kdntofSFGbpXETv9ZENBPlg7soyAzXVWsd7JXuy+cv4poXTemf85Aa4kWbK0x 2D/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lCUAxeAw; 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 s24si387673ejd.357.2021.05.12.09.20.41; Wed, 12 May 2021 09:21:06 -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=lCUAxeAw; 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 S234679AbhELQOH (ORCPT + 99 others); Wed, 12 May 2021 12:14:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:49132 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233501AbhELPbN (ORCPT ); Wed, 12 May 2021 11:31:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5F9A261979; Wed, 12 May 2021 15:16:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832571; bh=3SM62GvkMFZGnJLjb/hj4gbkYcd99YoCE/nieeEMq2I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lCUAxeAw8VlROkm3niA3Jsgnt1yf5RlHiRyJNP5slr8yzPRlvhfheCHxr3ddEXT2w mA6EaSs7rWJVvxjkruTPl8XzLiFunJrBc6/PAC4T0c7PIRvUzLTAmbz907nG4i3ju2 JFoy21bc9R9yjgvsPb2u2g7TjJ1zbNVivHQPNO/4= 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.10 301/530] x86/kprobes: Fix to check non boostable prefixes correctly Date: Wed, 12 May 2021 16:46:51 +0200 Message-Id: <20210512144829.694715643@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@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 39f7d8c3c064..535da74c124e 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