History

tracing: Fix WARN_ON in tracing_buffers_mmap_close

When a process forks, the child process copies the parent's VMAs but the user_mapped reference count is not incremented. As a result, when both the parent and child processes exit, tracing_buffers_mmap_close() is called twice. On the second call, user_mapped is already 0, causing the function to return -ENODEV and triggering a WARN_ON. Normally, this isn't an issue as the memory is mapped with VM_DONTCOPY set. But this is only a hint, and the application can call madvise(MADVISE_DOFORK) which resets the VM_DONTCOPY flag. When the application does that, it can trigger this issue on fork. Fix it by incrementing the user_mapped reference count without re-mapping the pages in the VMA's open callback.

Qing Wang committed 8 months ago

Commit e39bb9e1 parent a5dd6f53 files · +35 −0Browse files

Showing the changes to include (1 of 3 files). Show all

Unified · Split

include/linux/ring_buffer.h+1−0
@@ -248,6 +248,7 @@ int trace_rb_cpu_prepare(unsigned int cpu, struct hlist_node *node); · 247 unmodified lines
248248
249249 int ring_buffer_map(struct trace_buffer *buffer, int cpu,
250250 struct vm_area_struct *vma);
251+void ring_buffer_map_dup(struct trace_buffer *buffer, int cpu);
251252 int ring_buffer_unmap(struct trace_buffer *buffer, int cpu);
252253 int ring_buffer_map_get_reader(struct trace_buffer *buffer, int cpu);
253254 #endif /* _LINUX_RING_BUFFER_H */

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