From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Yang Jihong <yangjihong1@huawei.com>
Cc: <tglx@linutronix.de>, <mingo@redhat.com>, <bp@alien8.de>,
<dave.hansen@linux.intel.com>, <x86@kernel.org>, <hpa@zytor.com>,
<naveen.n.rao@linux.ibm.com>, <anil.s.keshavamurthy@intel.com>,
<davem@davemloft.net>, <ast@kernel.org>, <peterz@infradead.org>,
<linux-kernel@vger.kernel.org>,
<linux-trace-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/3] kprobes: Fixed probe nodes not correctly removed when forcibly unoptimized
Date: Wed, 15 Feb 2023 23:55:17 +0900 [thread overview]
Message-ID: <20230215235517.800c5089318b5353e7304b67@kernel.org> (raw)
In-Reply-To: <20230215115430.236046-2-yangjihong1@huawei.com>
Hi Yang,
Thanks for reporting, but maybe this is a part of following fix.
https://lore.kernel.org/all/167448024501.3253718.13037333683110512967.stgit@devnote3/
Can you confirm that fixes the same issue?
Thank you,
On Wed, 15 Feb 2023 19:54:28 +0800
Yang Jihong <yangjihong1@huawei.com> wrote:
> When unoptimize_kprobe forcibly unoptimize the kprobe, simply queue it in
> the freeing_list, and do_free_cleaned_kprobes directly reclaims the kprobe
> if unoptimizing_list is empty (see do_unoptimize_kprobes), which may cause
> WARN or UAF problems.
>
> The specific scenarios are as follows:
>
> Thread1
> arm_kprobe(p)
> mutex_lock(&kprobe_mutex)
> __arm_kprobe(kp)
> p = get_optimized_kprobe(p->addr)
> if (unlikely(_p))
> unoptimize_kprobe(_p, true) // now _p is queued in freeing_list
> mutex_unlock(&kprobe_mutex)
>
> Thread2
> kprobe_optimizer
> mutex_lock(&kprobe_mutex)
> do_unoptimize_kprobes
> if (list_empty(&unoptimizing_list))
> return; // here directly returned and does not process freeing_list.
> ...
> do_free_cleaned_kprobes
> foreach op in freeing_list:
> WARN_ON_ONCE(!kprobe_unused(&op->kp)) // WANR will be triggered here.
> free_aggr_kprobe((&op->kp) // Delete op->kp directly, if access hash
> // list later, UAF problem will be triggered.
> mutex_unlock(&kprobe_mutex)
>
> The freeing_list needs to be processed in do_unoptimize_kprobes regardless
> of whether unoptimizing_list is empty.
>
> Signed-off-by: Yang Jihong <yangjihong1@huawei.com>
> ---
> kernel/kprobes.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 1c18ecf9f98b..0730e595f4c1 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -556,10 +556,9 @@ static void do_unoptimize_kprobes(void)
> lockdep_assert_cpus_held();
>
> /* Unoptimization must be done anytime */
> - if (list_empty(&unoptimizing_list))
> - return;
> + if (!list_empty(&unoptimizing_list))
> + arch_unoptimize_kprobes(&unoptimizing_list, &freeing_list);
>
> - arch_unoptimize_kprobes(&unoptimizing_list, &freeing_list);
> /* Loop on 'freeing_list' for disarming */
> list_for_each_entry_safe(op, tmp, &freeing_list, list) {
> /* Switching from detour code to origin */
> --
> 2.30.GIT
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
next prev parent reply other threads:[~2023-02-15 14:56 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-15 11:54 [PATCH 0/3] kprobes: Fix issues related to optkprobe Yang Jihong
2023-02-15 11:54 ` [PATCH 1/3] kprobes: Fixed probe nodes not correctly removed when forcibly unoptimized Yang Jihong
2023-02-15 14:55 ` Masami Hiramatsu [this message]
2023-02-16 2:52 ` Yang Jihong
2023-02-15 11:54 ` [PATCH 2/3] x86/kprobes: Fix __recover_optprobed_insn check optimizing logic Yang Jihong
2023-02-15 15:08 ` Masami Hiramatsu
2023-02-16 2:53 ` Yang Jihong
2023-02-15 11:54 ` [PATCH 3/3] x86/kprobes: Fix arch_check_optimized_kprobe check within optimized_kprobe range Yang Jihong
2023-02-15 15:48 ` Masami Hiramatsu
2023-02-16 2:56 ` Yang Jihong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230215235517.800c5089318b5353e7304b67@kernel.org \
--to=mhiramat@kernel.org \
--cc=anil.s.keshavamurthy@intel.com \
--cc=ast@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=davem@davemloft.net \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=naveen.n.rao@linux.ibm.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
--cc=yangjihong1@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox