* [PATCH 5.4] ftrace: use preempt_enable/disable notrace macros to avoid double fault
@ 2025-01-08 3:17 Koichiro Den
2025-01-08 3:18 ` kernel test robot
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Koichiro Den @ 2025-01-08 3:17 UTC (permalink / raw)
To: gregkh, stable
Cc: rostedt, mhiramat, mark.rutland, mathieu.desnoyers, zhengyejian1,
hagarhem, linux-kernel
Since the backport commit eea46baf1451 ("ftrace: Fix possible
use-after-free issue in ftrace_location()") on linux-5.4.y branch, the
old ftrace_int3_handler()->ftrace_location() path has included
rcu_read_lock(), which has mcount location inside and leads to potential
double fault.
Replace rcu_read_lock/unlock with preempt_enable/disable notrace macros
so that the mcount location does not appear on the int3 handler path.
This fix is specific to linux-5.4.y branch, the only branch still using
ftrace_int3_handler with commit e60b613df8b6 ("ftrace: Fix possible
use-after-free issue in ftrace_location()") backported. It also avoids
the need to backport the code conversion to text_poke() on this branch.
Reported-by: Koichiro Den <koichiro.den@canonical.com>
Closes: https://lore.kernel.org/all/74gjhwxupvozwop7ndhrh7t5qeckomt7yqvkkbm5j2tlx6dkfk@rgv7sijvry2k
Fixes: eea46baf1451 ("ftrace: Fix possible use-after-free issue in ftrace_location()") # linux-5.4.y
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Koichiro Den <koichiro.den@canonical.com>
---
kernel/trace/ftrace.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 380032a27f98..2eb1a8ec5755 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -1554,7 +1554,7 @@ unsigned long ftrace_location_range(unsigned long start, unsigned long end)
struct dyn_ftrace key;
unsigned long ip = 0;
- rcu_read_lock();
+ preempt_disable_notrace();
key.ip = start;
key.flags = end; /* overload flags, as it is unsigned long */
@@ -1572,7 +1572,7 @@ unsigned long ftrace_location_range(unsigned long start, unsigned long end)
break;
}
}
- rcu_read_unlock();
+ preempt_enable_notrace();
return ip;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 5.4] ftrace: use preempt_enable/disable notrace macros to avoid double fault
2025-01-08 3:17 [PATCH 5.4] ftrace: use preempt_enable/disable notrace macros to avoid double fault Koichiro Den
@ 2025-01-08 3:18 ` kernel test robot
2025-01-08 19:49 ` Sasha Levin
2025-01-09 10:04 ` Greg KH
2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2025-01-08 3:18 UTC (permalink / raw)
To: Koichiro Den; +Cc: stable, oe-kbuild-all
Hi,
Thanks for your patch.
FYI: kernel test robot notices the stable kernel rule is not satisfied.
The check is based on https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html#option-3
Rule: The upstream commit ID must be specified with a separate line above the commit text.
Subject: [PATCH 5.4] ftrace: use preempt_enable/disable notrace macros to avoid double fault
Link: https://lore.kernel.org/stable/20250108031736.3318120-1-koichiro.den%40canonical.com
Please ignore this mail if the patch is not relevant for upstream.
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 5.4] ftrace: use preempt_enable/disable notrace macros to avoid double fault
2025-01-08 3:17 [PATCH 5.4] ftrace: use preempt_enable/disable notrace macros to avoid double fault Koichiro Den
2025-01-08 3:18 ` kernel test robot
@ 2025-01-08 19:49 ` Sasha Levin
2025-01-09 10:04 ` Greg KH
2 siblings, 0 replies; 4+ messages in thread
From: Sasha Levin @ 2025-01-08 19:49 UTC (permalink / raw)
To: stable; +Cc: Koichiro Den, Sasha Levin
[ Sasha's backport helper bot ]
Hi,
No upstream commit was identified. Using temporary commit for testing.
Results of testing on various branches:
| Branch | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-5.4.y | Success | Success |
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 5.4] ftrace: use preempt_enable/disable notrace macros to avoid double fault
2025-01-08 3:17 [PATCH 5.4] ftrace: use preempt_enable/disable notrace macros to avoid double fault Koichiro Den
2025-01-08 3:18 ` kernel test robot
2025-01-08 19:49 ` Sasha Levin
@ 2025-01-09 10:04 ` Greg KH
2 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2025-01-09 10:04 UTC (permalink / raw)
To: Koichiro Den
Cc: stable, rostedt, mhiramat, mark.rutland, mathieu.desnoyers,
zhengyejian1, hagarhem, linux-kernel
On Wed, Jan 08, 2025 at 12:17:36PM +0900, Koichiro Den wrote:
> Since the backport commit eea46baf1451 ("ftrace: Fix possible
> use-after-free issue in ftrace_location()") on linux-5.4.y branch, the
> old ftrace_int3_handler()->ftrace_location() path has included
> rcu_read_lock(), which has mcount location inside and leads to potential
> double fault.
>
> Replace rcu_read_lock/unlock with preempt_enable/disable notrace macros
> so that the mcount location does not appear on the int3 handler path.
>
> This fix is specific to linux-5.4.y branch, the only branch still using
> ftrace_int3_handler with commit e60b613df8b6 ("ftrace: Fix possible
> use-after-free issue in ftrace_location()") backported. It also avoids
> the need to backport the code conversion to text_poke() on this branch.
>
> Reported-by: Koichiro Den <koichiro.den@canonical.com>
> Closes: https://lore.kernel.org/all/74gjhwxupvozwop7ndhrh7t5qeckomt7yqvkkbm5j2tlx6dkfk@rgv7sijvry2k
> Fixes: eea46baf1451 ("ftrace: Fix possible use-after-free issue in ftrace_location()") # linux-5.4.y
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> Signed-off-by: Koichiro Den <koichiro.den@canonical.com>
> ---
> kernel/trace/ftrace.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Thanks, now queued up.
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-01-09 10:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-08 3:17 [PATCH 5.4] ftrace: use preempt_enable/disable notrace macros to avoid double fault Koichiro Den
2025-01-08 3:18 ` kernel test robot
2025-01-08 19:49 ` Sasha Levin
2025-01-09 10:04 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).