tracing: Some more fixes before pushing to 6.6
Subsystems (2)
Steven Rostedt
maintainercover tracing: Some more fixes before pushing to 6.6
Tracing updates for 6.6:
- Fix NULL pointer dereference with eventfs_remove_rec() If an allocation fails in one of the eventfs_add_*() functions, the caller of it in event_subsystem_dir() or event_create_dir() assigns the result to the structure. But it's assigning the ERR_PTR and not NULL. This was passed to eventfs_remove_rec() which expects either a good pointer or a NULL, not ERR_PTR. The fix is to not assign the ERR_PTR to the structure, but to keep it NULL on error.
- Fix list_for_each_rcu() to use list_for_each_srcu() in dcache_dir_open_wrapper(). One iteration of the code used RCU but because it had to call sleepable code, it had to be changed to use SRCU, but one of the iterations was missed.
- Fix synthetic event print function to use "as_u64" instead of passing in a pointer to the union. To fix big/little endian issues, the u64 that represented several types was turned into a union to define the types properly.
git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
trace/urgent
Head SHA1: c8414dab164a74bd3bb859a2d836cb537d6b9298
Jinjie Ruan (1):
eventfs: Fix the NULL pointer dereference bug in eventfs_remove_rec()
Steven Rostedt (Google) (1):
tracefs/eventfs: Use list_for_each_srcu() in dcache_dir_open_wrapper()
Tero Kristo (1):
tracing/synthetic: Print out u64 values properly
----
fs/tracefs/event_inode.c | 3 ++- kernel/trace/trace_events.c | 13 +++++++++---- kernel/trace/trace_events_synth.c | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-)
Steven Rostedt
maintainerPATCH 1/3 tracing/synthetic: Print out u64 values properly
From: Tero Kristo <[email protected]>
The synth traces incorrectly print pointer to the synthetic event values instead of the actual value when using u64 type. Fix by addressing the contents of the union properly.
--- kernel/trace/trace_events_synth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_events_synth.c +1 -1
@@ -337,7 +337,7 @@ static void print_synth_event_num_val(struct trace_seq *s,break ;default : -trace_seq_printf (s, print_fmt, name, val, space); +trace_seq_printf (s, print_fmt, name, val->as_u64, space);break ; } }
Signature · 1 line
2.40.1
Steven Rostedt
maintainerPATCH 2/3 tracefs/eventfs: Use list_for_each_srcu() in dcache_dir_open_wrapper()
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
The eventfs files list is protected by SRCU. In earlier iterations it was protected with just RCU, but because it needed to also call sleepable code, it had to be switch to SRCU. The dcache_dir_open_wrapper() list_for_each_rcu() was missed and did not get converted over to list_for_each_srcu(). That needs to be fixed.
--- fs/tracefs/event_inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/tracefs/event_inode.c +2 -1
@@ -452,7 +452,8 @@ static int dcache_dir_open_wrapper(struct inode *inode, struct file *file) ei = ti->private; idx =srcu_read_lock (&eventfs_srcu); -list_for_each_entry_rcu (ef, &ei->e_top_files, list) { +list_for_each_entry_srcu (ef, &ei->e_top_files, list, +srcu_read_lock_held (&eventfs_srcu)) {create_dentry (ef, dentry, false); }srcu_read_unlock (&eventfs_srcu, idx);
Signature · 1 line
2.40.1
Steven Rostedt
maintainerPATCH 3/3 eventfs: Fix the NULL pointer dereference bug in eventfs_remove_rec()
In reply to Steven RostedtFrom: Jinjie Ruan <[email protected]>
Inject fault while probing btrfs.ko, if kstrdup() fails in eventfs_prepare_ef() in eventfs_add_dir(), it will return ERR_PTR to assign file->ef. But the eventfs_remove() check NULL in trace_module_remove_events(), which causes the below NULL pointer dereference.
As both Masami and Steven suggest, allocater side should handle the error carefully and remove it, so fix the places where it failed.
Could not create tracefs 'raid56_write' directory Btrfs loaded, zoned=no, fsverity=no
Unable to handle kernel NULL pointer dereference at virtual address 000000000000001c
Mem abort info:
ESR = 0x0000000096000004
EC = 0x25: DABT (current EL), IL = 32 bits
SET = 0, FnV = 0
EA = 0, S1PTW = 0
FSC = 0x04: level 0 translation fault
Data abort info:
ISV = 0, ISS = 0x00000004, ISS2 = 0x00000000
CM = 0, WnR = 0, TnD = 0, TagAccess = 0
GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0
user pgtable: 4k pages, 48-bit VAs, pgdp=0000000102544000
[000000000000001c] pgd=0000000000000000, p4d=0000000000000000
Internal error: Oops: 0000000096000004 [#1] PREEMPT SMP
Dumping ftrace buffer:
(ftrace buffer empty)
Modules linked in: btrfs(-) libcrc32c xor xor_neon raid6_pq cfg80211 rfkill 8021q garp mrp stp llc ipv6 [last unloaded: btrfs]
CPU: 15 PID: 1343 Comm: rmmod Tainted: G N 6.5.0+ #40
Hardware name: linux,dummy-virt (DT)
pstate: 80000005 (Nzcv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
pc : eventfs_remove_rec+0x24/0xc0
lr : eventfs_remove+0x68/0x1d8
sp : ffff800082d63b60
x29: ffff800082d63b60 x28: ffffb84b80ddd00c x27: ffffb84b3054ba40
x26: 0000000000000002 x25: ffff800082d63bf8 x24: ffffb84b8398e440
x23: ffffb84b82af3000 x22: dead000000000100 x21: dead000000000122
x20: ffff800082d63bf8 x19: fffffffffffffff4 x18: ffffb84b82508820
x17: 0000000000000000 x16: 0000000000000000 x15: 000083bc876a3166
x14: 000000000000006d x13: 000000000000006d x12: 0000000000000000
x11: 0000000000000001 x10: 00000000000017e0 x9 : 0000000000000001
x8 : 0000000000000000 x7 : 0000000000000000 x6 : ffffb84b84289804
x5 : 0000000000000000 x4 : 9696969696969697 x3 : ffff33a5b7601f38
x2 : 0000000000000000 x1 : ffff800082d63bf8 x0 : fffffffffffffff4
Call trace:
eventfs_remove_rec+0x24/0xc0
eventfs_remove+0x68/0x1d8
remove_event_file_dir+0x88/0x100
event_remove+0x140/0x15c
trace_module_notify+0x1fc/0x230
notifier_call_chain+0x98/0x17c
blocking_notifier_call_chain+0x4c/0x74
__arm64_sys_delete_module+0x1a4/0x298
invoke_syscall+0x44/0x100
el0_svc_common.constprop.1+0x68/0xe0
do_el0_svc+0x1c/0x28
el0_svc+0x3c/0xc4
el0t_64_sync_handler+0xa0/0xc4
el0t_64_sync+0x174/0x178
Code: 5400052c a90153b3 aa0003f3 aa0103f4 (f9401400)
---[ end trace 0000000000000000 ]---
Kernel panic - not syncing: Oops: Fatal exception
SMP: stopping secondary CPUs
Dumping ftrace buffer:
(ftrace buffer empty)
Kernel Offset: 0x384b00c00000 from 0xffff800080000000
PHYS_OFFSET: 0xffffcc5b80000000
CPU features: 0x88000203,3c020000,1000421b
Memory Limit: none
Rebooting in 1 seconds..--- kernel/trace/trace_events.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
kernel/trace/trace_events.c +9 -4
@@ -2286,6 +2286,7 @@ event_subsystem_dir(struct trace_array *tr, const char *name, {struct event_subsystem *system, *iter;struct trace_subsystem_dir *dir; +struct eventfs_file *ef;int res;/* First see if we did not already create this dir */
@@ -2318,13 +2319,14 @@ event_subsystem_dir(struct trace_array *tr, const char *name, }else __get_system (system); - dir->ef =eventfs_add_subsystem_dir (name, parent); -if (IS_ERR (dir->ef)) { + ef =eventfs_add_subsystem_dir (name, parent); +if (IS_ERR (ef)) {pr_warn ("Failed to create system directory %s\n" , name);__put_system (system); goto out_free; } + dir->ef = ef; dir->tr = tr; dir->ref_count =1 ; dir->nr_events =1 ;
@@ -2404,6 +2406,7 @@ event_create_dir(struct dentry *parent, struct trace_event_file *file)struct trace_event_call *call = file->event_call;struct eventfs_file *ef_subsystem =NULL ;struct trace_array *tr = file->tr; +struct eventfs_file *ef;const char *name;int ret;
@@ -2420,12 +2423,14 @@ event_create_dir(struct dentry *parent, struct trace_event_file *file)return -ENOMEM ; name =trace_event_name (call); - file->ef =eventfs_add_dir (name, ef_subsystem); -if (IS_ERR (file->ef)) { + ef =eventfs_add_dir (name, ef_subsystem); +if (IS_ERR (ef)) {pr_warn ("Could not create tracefs '%s' directory\n" , name);return -1 ; } + file->ef = ef; +if (call->class->reg && !(call->flags &TRACE_EVENT_FL_IGNORE_ENABLE ))eventfs_add_file ("enable" ,TRACE_MODE_WRITE , file->ef, file, &ftrace_enable_fops);
Signature · 1 line
2.40.1