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
438438 if (!ei->name)
439439 return NULL;
440440 kref_init(&ei->kref);
441+ INIT_LIST_HEAD(&ei->children);
442+ INIT_LIST_HEAD(&ei->list);
441443 return ei;
442444 }
443445
@@ -729,8 +731,6 @@ struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode · 285 unmodified lines
729731 ei->entries = entries;
730732 ei->nr_entries = size;
731733 ei->data = data;
732− INIT_LIST_HEAD(&ei->children);
733− INIT_LIST_HEAD(&ei->list);
734734
735735 scoped_guard(mutex, &eventfs_mutex) {
736736 if (!parent->is_freed)
@@ -802,9 +802,6 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry · 65 unmodified lines
802802 ei->attr.uid = uid;
803803 ei->attr.gid = gid;
804804
805− INIT_LIST_HEAD(&ei->children);
806− INIT_LIST_HEAD(&ei->list);
807−
808805 ti = get_tracefs(inode);
809806 ti->flags |= TRACEFS_EVENT_INODE;
810807 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
58055805
58065806 prev_reader = cpu_buffer->subbuf_ids[cpu_buffer->meta_page->reader.id];
58075807
5808− WARN_ON_ONCE(cpu_buffer->remote->swap_reader_page(cpu_buffer->cpu,
5809− cpu_buffer->remote->priv));
5808+ if (cpu_buffer->remote->swap_reader_page(cpu_buffer->cpu,
5809+ cpu_buffer->remote->priv)) {
5810+ pr_warn_ratelimited("Remote reader page swap failed\n");
5811+ return NULL;
5812+ }
58105813 /* nr_pages doesn't include the reader page */
58115814 if (WARN_ON_ONCE(cpu_buffer->meta_page->reader.id > cpu_buffer->nr_pages))
58125815 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
160160 overrun = cpu_buffer->meta->overrun;
161161 } while (!simple_bpage_unset_head_link(last, reader, SIMPLE_RB_LINK_NORMAL) && retry--);
162162
163− if (!retry)
164− return -EINVAL;
163+ if (retry < 0)
164+ return -EBUSY;
165165
166166 cpu_buffer->head_page = simple_bpage_from_link(reader->link.next);
167167 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
82168216 /* Do not allow tracing while changing the order of the ring buffer */
82178217 tracing_stop_tr(tr);
82188218
8219+ trace_access_lock(RING_BUFFER_ALL_CPUS);
8220+
82198221 old_order = ring_buffer_subbuf_order_get(tr->array_buffer.buffer);
82208222 if (old_order == order)
82218223 goto out;
@@ -8255,6 +8257,7 @@ buffer_subbuf_size_write(struct file *filp, const char __user *ubuf, · 33 unmodified lines
82558257 #endif
82568258 (*ppos)++;
82578259 out:
8260+ trace_access_unlock(RING_BUFFER_ALL_CPUS);
82588261 if (ret)
82598262 cnt = ret;
82608263 tracing_start_tr(tr);
@@ -9728,7 +9731,8 @@ __init static void enable_instances(void) · 1467 unmodified lines
97289731
97299732 tr = trace_array_create_systems(name, NULL, addr, size);
97309733 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));
97329736 continue;
97339737 }
97349738
kernel/trace/trace_events.c+2−0
@@ -5019,6 +5019,8 @@ static __init void event_test_stuff(void) · 5018 unmodified lines
50195019 struct task_struct *test_thread;
50205020
50215021 test_thread = kthread_run(event_test_thread, NULL, "test-events");
5022+ if (WARN_ON(IS_ERR(test_thread)))
5023+ return;
50225024 msleep(1);
50235025 kthread_stop(test_thread);
50245026 }
kernel/trace/trace_events_hist.c+3−1
@@ -6661,8 +6661,10 @@ static int hist_register_trigger(char *glob, · 6660 unmodified lines
66616661 tracing_set_filter_buffering(file->tr, true);
66626662 }
66636663
6664− if (named_data)
6664+ if (named_data) {
6665+ remove_hist_vars(hist_data);
66656666 destroy_hist_data(hist_data);
6667+ }
66666668 out:
66676669 return ret;
66686670 }
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
868868 struct user_event_mm *mm = user_event_mm_alloc(t);
869869 struct user_event_enabler *enabler;
870870
871+ /* On failure, do not free parent's copy */
872+ t->user_event_mm = NULL;
873+
871874 if (!mm)
872875 return;
873876
samples/ftrace/ftrace-direct-modify.c+9−3
@@ -320,9 +320,15 @@ static int __init ftrace_direct_init(void) · 319 unmodified lines
320320 ftrace_set_filter_ip(&direct, (unsigned long) my_ip, 0, 0);
321321 ret = register_ftrace_direct(&direct, my_tramp);
322322
323− if (!ret)
324− simple_tsk = kthread_run(simple_thread, NULL, "event-sample-fn");
325− return ret;
323+ if (ret)
324+ 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;
326332 }
327333
328334 static 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
364364
365365 ret = register_ftrace_direct(&direct, my_tramp);
366366
367− if (!ret)
368− simple_tsk = kthread_run(simple_thread, NULL, "event-sample-fn");
369− return ret;
367+ if (ret)
368+ 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;
370376 }
371377
372378 static 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