This patch replaces preempt_{disable, enable} with its corresponding
notrace version in rethook_trampoline_handler so no worries about stack
recursion or overflow introduced by preempt_count_{add, sub} under
fprobe + rethook context.
Fixes: 54ecbe6f1ed5 ("rethook: Add a generic return hook")
Signed-off-by: Ze Gao <[email protected]>
Acked-by: Masami Hiramatsu (Google) <[email protected]>
Cc: <[email protected]>
Link: https://lore.kernel.org/linux-trace-kernel/[email protected]
---
kernel/trace/rethook.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/trace/rethook.c b/kernel/trace/rethook.c
index 32c3dfdb4d6a..60f6cb2b486b 100644
--- a/kernel/trace/rethook.c
+++ b/kernel/trace/rethook.c
@@ -288,7 +288,7 @@ unsigned long rethook_trampoline_handler(struct pt_regs *regs,
* These loops must be protected from rethook_free_rcu() because those
* are accessing 'rhn->rethook'.
*/
- preempt_disable();
+ preempt_disable_notrace();
/*
* Run the handler on the shadow stack. Do not unlink the list here because
@@ -321,7 +321,7 @@ unsigned long rethook_trampoline_handler(struct pt_regs *regs,
first = first->next;
rethook_recycle(rhn);
}
- preempt_enable();
+ preempt_enable_notrace();
return correct_ret_addr;
}
--
2.40.1
Hi Ze Gao,
On Wed, 17 May 2023 11:45:06 +0800
Ze Gao <[email protected]> wrote:
> This patch replaces preempt_{disable, enable} with its corresponding
> notrace version in rethook_trampoline_handler so no worries about stack
> recursion or overflow introduced by preempt_count_{add, sub} under
> fprobe + rethook context.
>
> Fixes: 54ecbe6f1ed5 ("rethook: Add a generic return hook")
> Signed-off-by: Ze Gao <[email protected]>
> Acked-by: Masami Hiramatsu (Google) <[email protected]>
> Cc: <[email protected]>
> Link: https://lore.kernel.org/linux-trace-kernel/[email protected]
Note that you don't need to add Link tag of the previous version for each patch.
I'll add it when I pick it :)
Thank you,
> ---
> kernel/trace/rethook.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/trace/rethook.c b/kernel/trace/rethook.c
> index 32c3dfdb4d6a..60f6cb2b486b 100644
> --- a/kernel/trace/rethook.c
> +++ b/kernel/trace/rethook.c
> @@ -288,7 +288,7 @@ unsigned long rethook_trampoline_handler(struct pt_regs *regs,
> * These loops must be protected from rethook_free_rcu() because those
> * are accessing 'rhn->rethook'.
> */
> - preempt_disable();
> + preempt_disable_notrace();
>
> /*
> * Run the handler on the shadow stack. Do not unlink the list here because
> @@ -321,7 +321,7 @@ unsigned long rethook_trampoline_handler(struct pt_regs *regs,
> first = first->next;
> rethook_recycle(rhn);
> }
> - preempt_enable();
> + preempt_enable_notrace();
>
> return correct_ret_addr;
> }
> --
> 2.40.1
>
--
Masami Hiramatsu (Google) <[email protected]>
Great, thanks!
Regards,
Ze
On Wed, May 17, 2023 at 7:59 PM Masami Hiramatsu <[email protected]> wrote:
>
> Hi Ze Gao,
>
> On Wed, 17 May 2023 11:45:06 +0800
> Ze Gao <[email protected]> wrote:
>
> > This patch replaces preempt_{disable, enable} with its corresponding
> > notrace version in rethook_trampoline_handler so no worries about stack
> > recursion or overflow introduced by preempt_count_{add, sub} under
> > fprobe + rethook context.
> >
> > Fixes: 54ecbe6f1ed5 ("rethook: Add a generic return hook")
> > Signed-off-by: Ze Gao <[email protected]>
> > Acked-by: Masami Hiramatsu (Google) <[email protected]>
> > Cc: <[email protected]>
> > Link: https://lore.kernel.org/linux-trace-kernel/[email protected]
>
> Note that you don't need to add Link tag of the previous version for each patch.
> I'll add it when I pick it :)
>
> Thank you,
>
> > ---
> > kernel/trace/rethook.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/kernel/trace/rethook.c b/kernel/trace/rethook.c
> > index 32c3dfdb4d6a..60f6cb2b486b 100644
> > --- a/kernel/trace/rethook.c
> > +++ b/kernel/trace/rethook.c
> > @@ -288,7 +288,7 @@ unsigned long rethook_trampoline_handler(struct pt_regs *regs,
> > * These loops must be protected from rethook_free_rcu() because those
> > * are accessing 'rhn->rethook'.
> > */
> > - preempt_disable();
> > + preempt_disable_notrace();
> >
> > /*
> > * Run the handler on the shadow stack. Do not unlink the list here because
> > @@ -321,7 +321,7 @@ unsigned long rethook_trampoline_handler(struct pt_regs *regs,
> > first = first->next;
> > rethook_recycle(rhn);
> > }
> > - preempt_enable();
> > + preempt_enable_notrace();
> >
> > return correct_ret_addr;
> > }
> > --
> > 2.40.1
> >
>
>
> --
> Masami Hiramatsu (Google) <[email protected]>