Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31E95C636D4 for ; Thu, 16 Feb 2023 02:53:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229678AbjBPCxz (ORCPT ); Wed, 15 Feb 2023 21:53:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229666AbjBPCxw (ORCPT ); Wed, 15 Feb 2023 21:53:52 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B11F846097; Wed, 15 Feb 2023 18:53:51 -0800 (PST) Received: from kwepemm600003.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4PHKG81pxwz16Nc9; Thu, 16 Feb 2023 10:51:28 +0800 (CST) Received: from [10.67.111.205] (10.67.111.205) by kwepemm600003.china.huawei.com (7.193.23.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.17; Thu, 16 Feb 2023 10:53:48 +0800 Subject: Re: [PATCH 2/3] x86/kprobes: Fix __recover_optprobed_insn check optimizing logic To: "Masami Hiramatsu (Google)" CC: , , , , , , , , , , , , References: <20230215115430.236046-1-yangjihong1@huawei.com> <20230215115430.236046-3-yangjihong1@huawei.com> <20230216000849.f0e332ebf35150cb5d5c4a29@kernel.org> From: Yang Jihong Message-ID: <403950ec-b4d1-e0e1-2c30-742e2bd905f8@huawei.com> Date: Thu, 16 Feb 2023 10:53:48 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <20230216000849.f0e332ebf35150cb5d5c4a29@kernel.org> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.111.205] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600003.china.huawei.com (7.193.23.202) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Masami, On 2023/2/15 23:08, Masami Hiramatsu (Google) wrote: > On Wed, 15 Feb 2023 19:54:29 +0800 > Yang Jihong wrote: > >> Since the following commit: >> >> commit f66c0447cca1 ("kprobes: Set unoptimized flag after unoptimizing code") >> >> modified the update timing of the KPROBE_FLAG_OPTIMIZED, a optimized_kprobe >> may be in the optimizing or unoptimizing state when op.kp->flags >> has KPROBE_FLAG_OPTIMIZED and op->list is not empty. >> >> The __recover_optprobed_insn check logic is incorrect, a kprobe in the >> unoptimizing state may be incorrectly determined as unoptimizing. >> As a result, incorrect instructions are copied. > > Ah, good catch! > >> >> The optprobe_queued_unopt function needs to be exported for invoking in >> arch directory. >> >> Fixes: f66c0447cca1 ("kprobes: Set unoptimized flag after unoptimizing code") > > Cc: stable@vger.kernel.org OK, will add in next version. > >> Signed-off-by: Yang Jihong >> --- >> arch/x86/kernel/kprobes/opt.c | 4 ++-- >> include/linux/kprobes.h | 1 + >> kernel/kprobes.c | 2 +- >> 3 files changed, 4 insertions(+), 3 deletions(-) >> >> diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c >> index e57e07b0edb6..3718d6863555 100644 >> --- a/arch/x86/kernel/kprobes/opt.c >> +++ b/arch/x86/kernel/kprobes/opt.c >> @@ -46,8 +46,8 @@ unsigned long __recover_optprobed_insn(kprobe_opcode_t *buf, unsigned long addr) >> /* This function only handles jump-optimized kprobe */ >> if (kp && kprobe_optimized(kp)) { >> op = container_of(kp, struct optimized_kprobe, kp); >> - /* If op->list is not empty, op is under optimizing */ >> - if (list_empty(&op->list)) >> + /* If op is [un]optimized or under unoptimizing */ > > Hmm, this is a bit confusing comment. If it is unoptimized, the kprobe_optimized() returns false. > Thus the comment should be /* If op is optimized or under unoptimizing */. > OK, will fix in next version. Thanks, Yang.