mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-09-04 20:19:47 +08:00
tracing updates for v6.15
- Fix read out of bounds bug in tracing_splice_read_pipe() The size of the sub page being read can now be greater than a page. But the buffer used in tracing_splice_read_pipe() only allocates a page size. The data copied to the buffer is the amount in sub buffer which can overflow the buffer. Use min((size_t)trace_seq_used(&iter->seq), PAGE_SIZE) to limit the amount copied to the buffer to a max of PAGE_SIZE. - Fix the test for NULL from "!filter_hash" to "!*filter_hash" The add_next_hash() function checked for NULL at the wrong pointer level. - Do not use the array in trace_adjust_address() if there are no elements The trace_adjust_address() finds the offset of a module that was stored in the persistent buffer when reading the previous boot buffer to see if the address belongs to a module that was loaded in the previous boot. An array is created that matches currently loaded modules with previously loaded modules. The trace_adjust_address() uses that array to find the new offset of the address that's in the previous buffer. But if no module was loaded, it ends up reading the last element in an array that was never allocated. Check if nr_entries is zero and exit out early if it is. - Remove nested lock of trace_event_sem in print_event_fields() The print_event_fields() function iterates over the ftrace_events list and requires the trace_event_sem semaphore held for read. But this function is always called with that semaphore held for read. Remove the taking of the semaphore and replace it with lockdep_assert_held_read(&trace_event_sem); -----BEGIN PGP SIGNATURE----- iIoEABYKADIWIQRRSw7ePDh/lE+zeZMp5XQQmuv6qgUCaBeXEBQccm9zdGVkdEBn b29kbWlzLm9yZwAKCRAp5XQQmuv6qvXFAP9JNgi0+ainOppsEP6u9KH+sttxKl76 14EslzuPqbzgOwD/Sm00a8n7m858iv6UN3AAW9AsX2QK5yG0Wbvterm8FgI= =s9qk -----END PGP SIGNATURE----- Merge tag 'trace-v6.15-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace Pull tracing fixes from Steven Rostedt: - Fix read out of bounds bug in tracing_splice_read_pipe() The size of the sub page being read can now be greater than a page. But the buffer used in tracing_splice_read_pipe() only allocates a page size. The data copied to the buffer is the amount in sub buffer which can overflow the buffer. Use min((size_t)trace_seq_used(&iter->seq), PAGE_SIZE) to limit the amount copied to the buffer to a max of PAGE_SIZE. - Fix the test for NULL from "!filter_hash" to "!*filter_hash" The add_next_hash() function checked for NULL at the wrong pointer level. - Do not use the array in trace_adjust_address() if there are no elements The trace_adjust_address() finds the offset of a module that was stored in the persistent buffer when reading the previous boot buffer to see if the address belongs to a module that was loaded in the previous boot. An array is created that matches currently loaded modules with previously loaded modules. The trace_adjust_address() uses that array to find the new offset of the address that's in the previous buffer. But if no module was loaded, it ends up reading the last element in an array that was never allocated. Check if nr_entries is zero and exit out early if it is. - Remove nested lock of trace_event_sem in print_event_fields() The print_event_fields() function iterates over the ftrace_events list and requires the trace_event_sem semaphore held for read. But this function is always called with that semaphore held for read. Remove the taking of the semaphore and replace it with lockdep_assert_held_read(&trace_event_sem) * tag 'trace-v6.15-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: tracing: Do not take trace_event_sem in print_event_fields() tracing: Fix trace_adjust_address() when there is no modules in scratch area ftrace: Fix NULL memory allocation check tracing: Fix oob write in trace_seq_to_buffer()
This commit is contained in:
commit
59c9ab3e8c
@ -3436,7 +3436,7 @@ static int add_next_hash(struct ftrace_hash **filter_hash, struct ftrace_hash **
|
|||||||
|
|
||||||
/* Copy the subops hash */
|
/* Copy the subops hash */
|
||||||
*filter_hash = alloc_and_copy_ftrace_hash(size_bits, subops_hash->filter_hash);
|
*filter_hash = alloc_and_copy_ftrace_hash(size_bits, subops_hash->filter_hash);
|
||||||
if (!filter_hash)
|
if (!*filter_hash)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
/* Remove any notrace functions from the copy */
|
/* Remove any notrace functions from the copy */
|
||||||
remove_hash(*filter_hash, subops_hash->notrace_hash);
|
remove_hash(*filter_hash, subops_hash->notrace_hash);
|
||||||
|
@ -6043,8 +6043,10 @@ unsigned long trace_adjust_address(struct trace_array *tr, unsigned long addr)
|
|||||||
tscratch = tr->scratch;
|
tscratch = tr->scratch;
|
||||||
/* if there is no tscrach, module_delta must be NULL. */
|
/* if there is no tscrach, module_delta must be NULL. */
|
||||||
module_delta = READ_ONCE(tr->module_delta);
|
module_delta = READ_ONCE(tr->module_delta);
|
||||||
if (!module_delta || tscratch->entries[0].mod_addr > addr)
|
if (!module_delta || !tscratch->nr_entries ||
|
||||||
|
tscratch->entries[0].mod_addr > addr) {
|
||||||
return addr + tr->text_delta;
|
return addr + tr->text_delta;
|
||||||
|
}
|
||||||
|
|
||||||
/* Note that entries must be sorted. */
|
/* Note that entries must be sorted. */
|
||||||
nr_entries = tscratch->nr_entries;
|
nr_entries = tscratch->nr_entries;
|
||||||
@ -6821,13 +6823,14 @@ static ssize_t tracing_splice_read_pipe(struct file *filp,
|
|||||||
/* Copy the data into the page, so we can start over. */
|
/* Copy the data into the page, so we can start over. */
|
||||||
ret = trace_seq_to_buffer(&iter->seq,
|
ret = trace_seq_to_buffer(&iter->seq,
|
||||||
page_address(spd.pages[i]),
|
page_address(spd.pages[i]),
|
||||||
trace_seq_used(&iter->seq));
|
min((size_t)trace_seq_used(&iter->seq),
|
||||||
|
PAGE_SIZE));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
__free_page(spd.pages[i]);
|
__free_page(spd.pages[i]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
spd.partial[i].offset = 0;
|
spd.partial[i].offset = 0;
|
||||||
spd.partial[i].len = trace_seq_used(&iter->seq);
|
spd.partial[i].len = ret;
|
||||||
|
|
||||||
trace_seq_init(&iter->seq);
|
trace_seq_init(&iter->seq);
|
||||||
}
|
}
|
||||||
|
@ -1042,11 +1042,12 @@ enum print_line_t print_event_fields(struct trace_iterator *iter,
|
|||||||
struct trace_event_call *call;
|
struct trace_event_call *call;
|
||||||
struct list_head *head;
|
struct list_head *head;
|
||||||
|
|
||||||
|
lockdep_assert_held_read(&trace_event_sem);
|
||||||
|
|
||||||
/* ftrace defined events have separate call structures */
|
/* ftrace defined events have separate call structures */
|
||||||
if (event->type <= __TRACE_LAST_TYPE) {
|
if (event->type <= __TRACE_LAST_TYPE) {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
down_read(&trace_event_sem);
|
|
||||||
list_for_each_entry(call, &ftrace_events, list) {
|
list_for_each_entry(call, &ftrace_events, list) {
|
||||||
if (call->event.type == event->type) {
|
if (call->event.type == event->type) {
|
||||||
found = true;
|
found = true;
|
||||||
@ -1056,7 +1057,6 @@ enum print_line_t print_event_fields(struct trace_iterator *iter,
|
|||||||
if (call->event.type > __TRACE_LAST_TYPE)
|
if (call->event.type > __TRACE_LAST_TYPE)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
up_read(&trace_event_sem);
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
trace_seq_printf(&iter->seq, "UNKNOWN TYPE %d\n", event->type);
|
trace_seq_printf(&iter->seq, "UNKNOWN TYPE %d\n", event->type);
|
||||||
goto out;
|
goto out;
|
||||||
|
Loading…
Reference in New Issue
Block a user