Re: [PATCH v3 5/6] x86/ftrace: Use text_poke()

From: Steven Rostedt
Date: Wed Oct 09 2019 - 22:41:40 EST


On Tue, 8 Oct 2019 10:43:35 -0400
Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:


> BTW, I'd really like to take this patch series through my tree. That
> way I can really hammer it, as well as I have code that will be built
> on top of it.

I did a bit of hammering and found two bugs. One I sent a patch to fix
(adding a module when tracing is enabled), but the other bug I
triggered, I'm too tired to debug right now. But figured I'd mention it
anyway.

If you add on the kernel command line:

ftrace=function ftrace_filter=schedule

You will get this (note, I had KASAN enabled, so it showed more info):



[ 1.274356] ftrace: allocating 34274 entries in 134 pages
[ 1.320059] Starting tracer 'function'
[ 1.323724] ==================================================================
[ 1.330798] BUG: KASAN: null-ptr-deref in __get_locked_pte+0x21/0x210
[ 1.337186] Read of size 8 at addr 0000000000000050 by task swapper/0
[ 1.343579]
[ 1.345049] CPU: 0 PID: 0 Comm: swapper Not tainted 5.4.0-rc2-test+ #50
[ 1.351613] Hardware name: Hewlett-Packard HP Compaq Pro 6300 SFF/339A, BIOS K01 v03.03 07/14/2016
[ 1.360510] Call Trace:
[ 1.362932] dump_stack+0x7c/0xc0
[ 1.366213] ? __get_locked_pte+0x21/0x210
[ 1.370272] ? __get_locked_pte+0x21/0x210
[ 1.374331] __kasan_report.cold.10+0x5/0x3e
[ 1.378566] ? __get_locked_pte+0x21/0x210
[ 1.382625] kasan_report+0xe/0x20
[ 1.385993] __get_locked_pte+0x21/0x210
[ 1.389880] ? 0xffffffffa000005c
[ 1.393162] __text_poke+0x1ca/0x5b0
[ 1.396705] ? optimize_nops.isra.8+0xd0/0xd0
[ 1.401023] ? insn_get_length+0x4f/0x70
[ 1.404910] ? text_poke_loc_init+0x186/0x220
[ 1.409229] ? text_poke_kgdb+0x10/0x10
[ 1.413031] ? 0xffffffffa0000000
[ 1.416312] text_poke_bp_batch+0xb4/0x1e0
[ 1.420372] ? __text_poke+0x5b0/0x5b0
[ 1.424088] ? do_raw_spin_lock+0x113/0x1d0
[ 1.428233] ? 0xffffffffa000005c
[ 1.431515] ? 0xffffffffa0000000
[ 1.434797] text_poke_bp+0x7a/0xa0
[ 1.438253] ? text_poke_queue+0xb0/0xb0
[ 1.442139] ? 0xffffffffa0000000
[ 1.445421] ? 0xffffffffa000005c
[ 1.448706] ? find_vmap_area+0x56/0x80
[ 1.452505] arch_ftrace_update_trampoline+0x114/0x380
[ 1.457603] ? ftrace_caller+0x4e/0x4e
[ 1.461316] ? 0xffffffffa0000091
[ 1.464599] ? arch_ftrace_update_code+0x10/0x10
[ 1.469179] ? mutex_lock+0x86/0xd0
[ 1.472634] ? __mutex_lock_slowpath+0x10/0x10
[ 1.477039] ? mutex_unlock+0x1d/0x40
[ 1.480668] ? arch_jump_label_transform_queue+0x7a/0x90
[ 1.485937] ? __jump_label_update+0x91/0x140
[ 1.490256] ? mutex_unlock+0x1d/0x40
[ 1.493885] ? tracing_start_sched_switch.cold.0+0x60/0x60
[ 1.499327] __register_ftrace_function+0xaf/0xf0
[ 1.503991] ftrace_startup+0x24/0x130
[ 1.507706] register_ftrace_function+0x2d/0x80
[ 1.512198] function_trace_init+0xc1/0x100
[ 1.516346] tracing_set_tracer+0x1fb/0x3c0
[ 1.520492] ? free_snapshot+0x50/0x50
[ 1.524205] ? __kasan_kmalloc.constprop.6+0xc1/0xd0
[ 1.529131] ? __list_add_valid+0x29/0xa0
[ 1.533106] register_tracer+0x235/0x26c
[ 1.536993] early_trace_init+0x29b/0x3a0
[ 1.540967] start_kernel+0x2a3/0x5f7
[ 1.544595] ? mem_encrypt_init+0x6/0x6
[ 1.548396] ? load_ucode_intel_bsp+0x5e/0xa3
[ 1.552715] ? init_intel_microcode+0xc3/0xc3
[ 1.557036] ? load_ucode_bsp+0xcc/0x154
[ 1.560923] secondary_startup_64+0xa4/0xb0
[ 1.565070] ==================================================================


-- Steve