History

Merge tag 'trace-v7.3-2' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace

Pull tracing fixes from Steven Rostedt: - Fix error output of boot instance creation failure Currently if a boot instance creation fails, instead of printing out the name of the instance that failed, it prints "(null)". That is because it prints "cur_str" that had already been processed by strsep(). Print the saved name instead. While at it, print the error code of the failure. - Fix use-after-free for same named historgrams Histograms can be named so that they can be used in multiple events. But if the named histogram has a variable attached, the second event that uses the named histogram which duplicates it and needs to free the original after duplication leaves the old variable in place and still visible. If another histogram uses than variable, it will use the stale one which will try to reference the freed duplicate histogram and crash the kernel. Free the duplicate variables along with the duplicated histogram data. - Check return value of kthread_run() in event self test The events self tests uses a kthread for testing but does not check if it succeeded in creating a kthread. If the kthread creation were to fail, the code will still try to call kthread_stop() on the error returned. - Fix race between reading trace_pipe and updating subbuffer size If a user is reading the trace_pipe file at the same time they update the ring buffer sub-buffer size, can cause the trace_pipe read to read stale data. Add trace_access_lock() around updating the ring buffer sub-buffer size. - Fix eventfs_inode on failure path in creation of the events directory In the creation of the "events" directory, if after allocating the eventfs_inode a failure is detected, it calls cleanup_ei() which calls free_ei(). The free_ei() will test if eventfs_inode being freed has no children. It is a bug if it does. But on the failure case of the creation of the "events" directory, the children lists have not yet been initialized and the free will trigger a warning because list_empty() on an uninitialized list returns false. Move the initialization into init_ei() where it makes more sense and makes sure that a created eventfs_inode has its lists initialized upon creation. - Check return value of kthread_run() in ftrace direct sample code The sample code that shows how to use the ftrace direct calls does not test the return of kthread_run() to see if it succeeds. Return a failure if the kthread_run() doesn't succeed. - Clear user events state on fork in case of alloc failure On fork, the child gets a pointer to the parent's user events state. It makes a copy of it then updates the child's pointer to it. But if the allocation fails, the duplication function leaves the child with a pointer to its parent's descriptor. When the child cleans up its data, it will free the parent's descriptor while the parent is still using it. In the duplication function, set the child's user_event_mm to NULL before testing if the allocation succeeded, and when it exits it will not free the parent's descriptor. - Fix retry exhaustion in simple ring buffer reader swap simple_ring_buffer_swap_reader_page() starts with retry set to 8 and post-decrements it only after a failed link replacement. On the final attempt, a successful replacement leaves retry at zero, while a failed replacement leaves it at -1. But the check for success expects the retry value to be non-zero and exits with an error on zero. This is the opposite result. Fix it. - Fail nicely when the remote swap_reader_page() returns an error Currently, if the swap_reader_page() of a remote buffer fails, it triggers a WARN_ON_ONCE() and continues normally. Instead, have it exit with an error and a pr_warn() print instead of a full WARNING. * tag 'trace-v7.3-2' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: ring-buffer: Stop remote reader update when page swap fails tracing: Fix retry exhaustion in simple ring buffer reader swap tracing/user_events: Clear copied tracing state before fork duplication samples/ftrace: Fix kthread_stop() on ERR_PTR in ftrace-direct-multi-modify samples/ftrace: Fix kthread_stop() on ERR_PTR in ftrace-direct-modify eventfs: Initialize ei->children and ei->list in init_ei() tracing: Fix use-after-free in trace_pipe read on sub-buffer order change tracing: Fix crash passing ERR_PTR to kthread_stop() tracing: Fix use-after-free with same-name named triggers tracing: Fix logged instance name on creation failure

Linus Torvalds committed 2 months ago

Commit 034dd342 parents 08dbfad 5eab7489 files · +40 −17Browse files

Unified · Split

9 files
  1. fs/tracefs/event_inode.c +2 −5
  2. kernel/trace/ring_buffer.c +5 −2
  3. kernel/trace/simple_ring_buffer.c +2 −2
  4. kernel/trace/trace.c +5 −1
  5. kernel/trace/trace_events.c +2 −0
  6. kernel/trace/trace_events_hist.c +3 −1
  7. kernel/trace/trace_events_user.c +3 −0
  8. samples/ftrace/ftrace-direct-modify.c +9 −3
  9. samples/ftrace/ftrace-direct-multi-modify.c +9 −3
fs/tracefs/event_inode.c+2−5
@@ -438,6 +438,8 @@ static inline struct eventfs_inode *init_ei(struct eventfs_inode *ei, const char · 437 unmodified lines
438 if (!ei->name)438 if (!ei->name)
439 return NULL;439 return NULL;
440 kref_init(&ei->kref);440 kref_init(&ei->kref);
441 INIT_LIST_HEAD(&ei->children);
442 INIT_LIST_HEAD(&ei->list);
441 return ei;443 return ei;
442}444}
443 445
@@ -729,8 +731,6 @@ struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode · 285 unmodified lines
729 ei->entries = entries;731 ei->entries = entries;
730 ei->nr_entries = size;732 ei->nr_entries = size;
731 ei->data = data;733 ei->data = data;
732 INIT_LIST_HEAD(&ei->children);
733 INIT_LIST_HEAD(&ei->list);
734 734
735 scoped_guard(mutex, &eventfs_mutex) {735 scoped_guard(mutex, &eventfs_mutex) {
736 if (!parent->is_freed)736 if (!parent->is_freed)
@@ -802,9 +802,6 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry · 65 unmodified lines
802 ei->attr.uid = uid;802 ei->attr.uid = uid;
803 ei->attr.gid = gid;803 ei->attr.gid = gid;
804 804
805 INIT_LIST_HEAD(&ei->children);
806 INIT_LIST_HEAD(&ei->list);
807
808 ti = get_tracefs(inode);805 ti = get_tracefs(inode);
809 ti->flags |= TRACEFS_EVENT_INODE;806 ti->flags |= TRACEFS_EVENT_INODE;
810 ti->private = ei;807 ti->private = ei;
kernel/trace/ring_buffer.c+5−2
@@ -5805,8 +5805,11 @@ __rb_get_reader_page_from_remote(struct ring_buffer_per_cpu *cpu_buffer) · 5804 unmodified lines
5805 5805
5806 prev_reader = cpu_buffer->subbuf_ids[cpu_buffer->meta_page->reader.id];5806 prev_reader = cpu_buffer->subbuf_ids[cpu_buffer->meta_page->reader.id];
5807 5807
5808 WARN_ON_ONCE(cpu_buffer->remote->swap_reader_page(cpu_buffer->cpu,5808 if (cpu_buffer->remote->swap_reader_page(cpu_buffer->cpu,
5809 cpu_buffer->remote->priv));5809 cpu_buffer->remote->priv)) {
5810 pr_warn_ratelimited("Remote reader page swap failed\n");
5811 return NULL;
5812 }
5810 /* nr_pages doesn't include the reader page */5813 /* nr_pages doesn't include the reader page */
5811 if (WARN_ON_ONCE(cpu_buffer->meta_page->reader.id > cpu_buffer->nr_pages))5814 if (WARN_ON_ONCE(cpu_buffer->meta_page->reader.id > cpu_buffer->nr_pages))
5812 return NULL;5815 return NULL;
kernel/trace/simple_ring_buffer.c+2−2
@@ -160,8 +160,8 @@ int simple_ring_buffer_swap_reader_page(struct simple_rb_per_cpu *cpu_buffer) · 159 unmodified lines
160 overrun = cpu_buffer->meta->overrun;160 overrun = cpu_buffer->meta->overrun;
161 } while (!simple_bpage_unset_head_link(last, reader, SIMPLE_RB_LINK_NORMAL) && retry--);161 } while (!simple_bpage_unset_head_link(last, reader, SIMPLE_RB_LINK_NORMAL) && retry--);
162 162
163 if (!retry)163 if (retry < 0)
164 return -EINVAL;164 return -EBUSY;
165 165
166 cpu_buffer->head_page = simple_bpage_from_link(reader->link.next);166 cpu_buffer->head_page = simple_bpage_from_link(reader->link.next);
167 cpu_buffer->head_page->link.prev = &reader->link;167 cpu_buffer->head_page->link.prev = &reader->link;
kernel/trace/trace.c+5−1
@@ -8216,6 +8216,8 @@ buffer_subbuf_size_write(struct file *filp, const char __user *ubuf, · 8215 unmodified lines
8216 /* Do not allow tracing while changing the order of the ring buffer */8216 /* Do not allow tracing while changing the order of the ring buffer */
8217 tracing_stop_tr(tr);8217 tracing_stop_tr(tr);
8218 8218
8219 trace_access_lock(RING_BUFFER_ALL_CPUS);
8220
8219 old_order = ring_buffer_subbuf_order_get(tr->array_buffer.buffer);8221 old_order = ring_buffer_subbuf_order_get(tr->array_buffer.buffer);
8220 if (old_order == order)8222 if (old_order == order)
8221 goto out;8223 goto out;
@@ -8255,6 +8257,7 @@ buffer_subbuf_size_write(struct file *filp, const char __user *ubuf, · 33 unmodified lines
8255#endif8257#endif
8256 (*ppos)++;8258 (*ppos)++;
8257 out:8259 out:
8260 trace_access_unlock(RING_BUFFER_ALL_CPUS);
8258 if (ret)8261 if (ret)
8259 cnt = ret;8262 cnt = ret;
8260 tracing_start_tr(tr);8263 tracing_start_tr(tr);
@@ -9728,7 +9731,8 @@ __init static void enable_instances(void) · 1467 unmodified lines
9728 9731
9729 tr = trace_array_create_systems(name, NULL, addr, size);9732 tr = trace_array_create_systems(name, NULL, addr, size);
9730 if (IS_ERR(tr)) {9733 if (IS_ERR(tr)) {
9731 pr_warn("Tracing: Failed to create instance buffer %s\n", curr_str);9734 pr_warn("Tracing: Failed to create instance buffer '%s' (%ld)\n", name,
9735 PTR_ERR(tr));
9732 continue;9736 continue;
9733 }9737 }
9734 9738
kernel/trace/trace_events.c+2−0
@@ -5019,6 +5019,8 @@ static __init void event_test_stuff(void) · 5018 unmodified lines
5019 struct task_struct *test_thread;5019 struct task_struct *test_thread;
5020 5020
5021 test_thread = kthread_run(event_test_thread, NULL, "test-events");5021 test_thread = kthread_run(event_test_thread, NULL, "test-events");
5022 if (WARN_ON(IS_ERR(test_thread)))
5023 return;
5022 msleep(1);5024 msleep(1);
5023 kthread_stop(test_thread);5025 kthread_stop(test_thread);
5024}5026}
kernel/trace/trace_events_hist.c+3−1
@@ -6661,8 +6661,10 @@ static int hist_register_trigger(char *glob, · 6660 unmodified lines
6661 tracing_set_filter_buffering(file->tr, true);6661 tracing_set_filter_buffering(file->tr, true);
6662 }6662 }
6663 6663
6664 if (named_data)6664 if (named_data) {
6665 remove_hist_vars(hist_data);
6665 destroy_hist_data(hist_data);6666 destroy_hist_data(hist_data);
6667 }
6666 out:6668 out:
6667 return ret;6669 return ret;
6668}6670}
kernel/trace/trace_events_user.c+3−0
@@ -868,6 +868,9 @@ void user_event_mm_dup(struct task_struct *t, struct user_event_mm *old_mm) · 867 unmodified lines
868 struct user_event_mm *mm = user_event_mm_alloc(t);868 struct user_event_mm *mm = user_event_mm_alloc(t);
869 struct user_event_enabler *enabler;869 struct user_event_enabler *enabler;
870 870
871 /* On failure, do not free parent's copy */
872 t->user_event_mm = NULL;
873
871 if (!mm)874 if (!mm)
872 return;875 return;
873 876
samples/ftrace/ftrace-direct-modify.c+9−3
@@ -320,9 +320,15 @@ static int __init ftrace_direct_init(void) · 319 unmodified lines
320 ftrace_set_filter_ip(&direct, (unsigned long) my_ip, 0, 0);320 ftrace_set_filter_ip(&direct, (unsigned long) my_ip, 0, 0);
321 ret = register_ftrace_direct(&direct, my_tramp);321 ret = register_ftrace_direct(&direct, my_tramp);
322 322
323 if (!ret)323 if (ret)
324 simple_tsk = kthread_run(simple_thread, NULL, "event-sample-fn");324 return ret;
325 return ret;325 simple_tsk = kthread_run(simple_thread, NULL, "event-sample-fn");
326 if (IS_ERR(simple_tsk)) {
327 unregister_ftrace_direct(&direct, my_tramp, true);
328 return PTR_ERR(simple_tsk);
329 }
330
331 return 0;
326}332}
327 333
328static void __exit ftrace_direct_exit(void)334static void __exit ftrace_direct_exit(void)
samples/ftrace/ftrace-direct-multi-modify.c+9−3
@@ -364,9 +364,15 @@ static int __init ftrace_direct_multi_init(void) · 363 unmodified lines
364 364
365 ret = register_ftrace_direct(&direct, my_tramp);365 ret = register_ftrace_direct(&direct, my_tramp);
366 366
367 if (!ret)367 if (ret)
368 simple_tsk = kthread_run(simple_thread, NULL, "event-sample-fn");368 return ret;
369 return ret;369 simple_tsk = kthread_run(simple_thread, NULL, "event-sample-fn");
370 if (IS_ERR(simple_tsk)) {
371 unregister_ftrace_direct(&direct, my_tramp, true);
372 return PTR_ERR(simple_tsk);
373 }
374
375 return 0;
370}376}
371 377
372static void __exit ftrace_direct_multi_exit(void)378static void __exit ftrace_direct_multi_exit(void)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t