lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAAYs2=jZ=uR61QXB-m4+7ocuydn1diGv0yV6KWmm4jfZYvam8Q@mail.gmail.com>
Date:   Wed, 23 Nov 2022 01:58:18 +0000
From:   Song Shuai <suagrfillet@...il.com>
To:     Steven Rostedt <rostedt@...dmis.org>
Cc:     mingo@...hat.com, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] ftrace: avoid replacing the list func with itself

Steven Rostedt <rostedt@...dmis.org> 于2022年11月22日周二 21:32写道:
>
> On Tue, 22 Nov 2022 02:28:25 +0000
> Song Shuai <suagrfillet@...il.com> wrote:
>
> > Song Shuai <suagrfillet@...il.com> 于2022年10月26日周三 13:20写道:
> > >
> > > The list func (ftrace_ops_list_func) will be patched first
> > > before the transition between old and new calls are set,
> > > which fixed the race described in this commit `59338f75`.
> > >
> > > While ftrace_trace_function changes from the list func to a
> > > ftrace_ops func, like unregistering the klp_ops to leave the only
> > > global_ops in ftrace_ops_list, the ftrace_[regs]_call will be
> > > replaced with the list func although it already exists. So there
> > > should be a condition to avoid this.
> > >
> > > This patch backups saved_ftrace_func by saved_ftrace_func_old
> > > which will be compared with the list func before trying to patch it.
> > >
> > Ping...
>
> Wouldn't something like this be simpler and easier to manage (without
> adding another variable to keep track of)?
>
> -- Steve
>
Thanks for the corrections, this looks great to me.
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 65a5d36463e0..d04552c0c275 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -2763,6 +2763,19 @@ void __weak ftrace_arch_code_modify_post_process(void)
>  {
>  }
>
> +static int update_ftrace_func(ftrace_func_t func)
> +{
> +       static ftrace_func_t save_func;
> +
> +       /* Avoid updating if it hasn't changed */
> +       if (func == save_func)
> +               return 0;
> +
> +       save_func = func;
> +
> +       return ftrace_update_ftrace_func(func);
> +}
> +
>  void ftrace_modify_all_code(int command)
>  {
>         int update = command & FTRACE_UPDATE_TRACE_FUNC;
> @@ -2783,7 +2796,7 @@ void ftrace_modify_all_code(int command)
>          * traced.
>          */
>         if (update) {
> -               err = ftrace_update_ftrace_func(ftrace_ops_list_func);
> +               err = update_ftrace_func(ftrace_ops_list_func);
>                 if (FTRACE_WARN_ON(err))
>                         return;
>         }
> @@ -2799,7 +2812,7 @@ void ftrace_modify_all_code(int command)
>                 /* If irqs are disabled, we are in stop machine */
>                 if (!irqs_disabled())
>                         smp_call_function(ftrace_sync_ipi, NULL, 1);
> -               err = ftrace_update_ftrace_func(ftrace_trace_function);
> +               err = update_ftrace_func(ftrace_trace_function);
>                 if (FTRACE_WARN_ON(err))
>                         return;
>         }
Thanks,
Song

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ