Skip to content

Commit 8f97366

Browse files
committed
Merge tag 'trace-v6.17-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace
Pull tracing fixes from Steven Rostedt: - Fix buffer overflow in osnoise_cpu_write() The allocated buffer to read user space did not add a nul terminating byte after copying from user the string. It then reads the string, and if user space did not add a nul byte, the read will continue beyond the string. Add a nul terminating byte after reading the string. - Fix missing check for lockdown on tracing There's a path from kprobe events or uprobe events that can update the tracing system even if lockdown on tracing is activate. Add a check in the dynamic event path. - Add a recursion check for the function graph return path Now that fprobes can hook to the function graph tracer and call different code between the entry and the exit, the exit code may now call functions that are not called in entry. This means that the exit handler can possibly trigger recursion that is not caught and cause the system to crash. Add the same recursion checks in the function exit handler as exists in the entry handler path. * tag 'trace-v6.17-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: tracing: fgraph: Protect return handler from recursion loop tracing: dynevent: Add a missing lockdown check on dynevent tracing/osnoise: Fix slab-out-of-bounds in _parse_integer_limit()
2 parents a5b2a9f + 0db0934 commit 8f97366

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

kernel/trace/fgraph.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ __ftrace_return_to_handler(struct ftrace_regs *fregs, unsigned long frame_pointe
815815
unsigned long bitmap;
816816
unsigned long ret;
817817
int offset;
818+
int bit;
818819
int i;
819820

820821
ret_stack = ftrace_pop_return_trace(&trace, &ret, frame_pointer, &offset);
@@ -829,6 +830,15 @@ __ftrace_return_to_handler(struct ftrace_regs *fregs, unsigned long frame_pointe
829830
if (fregs)
830831
ftrace_regs_set_instruction_pointer(fregs, ret);
831832

833+
bit = ftrace_test_recursion_trylock(trace.func, ret);
834+
/*
835+
* This can fail because ftrace_test_recursion_trylock() allows one nest
836+
* call. If we are already in a nested call, then we don't probe this and
837+
* just return the original return address.
838+
*/
839+
if (unlikely(bit < 0))
840+
goto out;
841+
832842
#ifdef CONFIG_FUNCTION_GRAPH_RETVAL
833843
trace.retval = ftrace_regs_get_return_value(fregs);
834844
#endif
@@ -852,6 +862,8 @@ __ftrace_return_to_handler(struct ftrace_regs *fregs, unsigned long frame_pointe
852862
}
853863
}
854864

865+
ftrace_test_recursion_unlock(bit);
866+
out:
855867
/*
856868
* The ftrace_graph_return() may still access the current
857869
* ret_stack structure, we need to make sure the update of

kernel/trace/trace_osnoise.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2325,12 +2325,13 @@ osnoise_cpus_write(struct file *filp, const char __user *ubuf, size_t count,
23252325
if (count < 1)
23262326
return 0;
23272327

2328-
buf = kmalloc(count, GFP_KERNEL);
2328+
buf = kmalloc(count + 1, GFP_KERNEL);
23292329
if (!buf)
23302330
return -ENOMEM;
23312331

23322332
if (copy_from_user(buf, ubuf, count))
23332333
return -EFAULT;
2334+
buf[count] = '\0';
23342335

23352336
if (!zalloc_cpumask_var(&osnoise_cpumask_new, GFP_KERNEL))
23362337
return -ENOMEM;

0 commit comments

Comments
 (0)