Skip to content

Commit 6a71398

Browse files
committed
Merge tag 'trace-v5.2-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull tracing fixes from Steven Rostedt: - Out of range read of stack trace output - Fix for NULL pointer dereference in trace_uprobe_create() - Fix to a livepatching / ftrace permission race in the module code - Fix for NULL pointer dereference in free_ftrace_func_mapper() - A couple of build warning clean ups * tag 'trace-v5.2-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: ftrace: Fix NULL pointer dereference in free_ftrace_func_mapper() module: Fix livepatch/ftrace module text permissions race tracing/uprobe: Fix obsolete comment on trace_uprobe_create() tracing/uprobe: Fix NULL pointer dereference in trace_uprobe_create() tracing: Make two symbols static tracing: avoid build warning with HAVE_NOP_MCOUNT tracing: Fix out-of-range read in trace_stack_print()
2 parents 0011572 + 04e03d9 commit 6a71398

5 files changed

Lines changed: 35 additions & 14 deletions

File tree

‎kernel/livepatch/core.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/elf.h>
1919
#include <linux/moduleloader.h>
2020
#include <linux/completion.h>
21+
#include <linux/memory.h>
2122
#include <asm/cacheflush.h>
2223
#include "core.h"
2324
#include "patch.h"
@@ -718,16 +719,21 @@ static int klp_init_object_loaded(struct klp_patch *patch,
718719
struct klp_func *func;
719720
int ret;
720721

722+
mutex_lock(&text_mutex);
723+
721724
module_disable_ro(patch->mod);
722725
ret = klp_write_object_relocations(patch->mod, obj);
723726
if (ret) {
724727
module_enable_ro(patch->mod, true);
728+
mutex_unlock(&text_mutex);
725729
return ret;
726730
}
727731

728732
arch_klp_init_object_loaded(patch, obj);
729733
module_enable_ro(patch->mod, true);
730734

735+
mutex_unlock(&text_mutex);
736+
731737
klp_for_each_func(obj, func) {
732738
ret = klp_find_object_symbol(obj->name, func->old_name,
733739
func->old_sympos,

‎kernel/trace/ftrace.c‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <linux/hash.h>
3535
#include <linux/rcupdate.h>
3636
#include <linux/kprobes.h>
37+
#include <linux/memory.h>
3738

3839
#include <trace/events/sched.h>
3940

@@ -2610,10 +2611,12 @@ static void ftrace_run_update_code(int command)
26102611
{
26112612
int ret;
26122613

2614+
mutex_lock(&text_mutex);
2615+
26132616
ret = ftrace_arch_code_modify_prepare();
26142617
FTRACE_WARN_ON(ret);
26152618
if (ret)
2616-
return;
2619+
goto out_unlock;
26172620

26182621
/*
26192622
* By default we use stop_machine() to modify the code.
@@ -2625,6 +2628,9 @@ static void ftrace_run_update_code(int command)
26252628

26262629
ret = ftrace_arch_code_modify_post_process();
26272630
FTRACE_WARN_ON(ret);
2631+
2632+
out_unlock:
2633+
mutex_unlock(&text_mutex);
26282634
}
26292635

26302636
static void ftrace_run_modify_code(struct ftrace_ops *ops, int command,
@@ -2935,14 +2941,13 @@ static int ftrace_update_code(struct module *mod, struct ftrace_page *new_pgs)
29352941
p = &pg->records[i];
29362942
p->flags = rec_flags;
29372943

2938-
#ifndef CC_USING_NOP_MCOUNT
29392944
/*
29402945
* Do the initial record conversion from mcount jump
29412946
* to the NOP instructions.
29422947
*/
2943-
if (!ftrace_code_disable(mod, p))
2948+
if (!__is_defined(CC_USING_NOP_MCOUNT) &&
2949+
!ftrace_code_disable(mod, p))
29442950
break;
2945-
#endif
29462951

29472952
update_cnt++;
29482953
}
@@ -4221,10 +4226,13 @@ void free_ftrace_func_mapper(struct ftrace_func_mapper *mapper,
42214226
struct ftrace_func_entry *entry;
42224227
struct ftrace_func_map *map;
42234228
struct hlist_head *hhd;
4224-
int size = 1 << mapper->hash.size_bits;
4225-
int i;
4229+
int size, i;
4230+
4231+
if (!mapper)
4232+
return;
42264233

42274234
if (free_func && mapper->hash.count) {
4235+
size = 1 << mapper->hash.size_bits;
42284236
for (i = 0; i < size; i++) {
42294237
hhd = &mapper->hash.buckets[i];
42304238
hlist_for_each_entry(entry, hhd, hlist) {
@@ -5776,6 +5784,7 @@ void ftrace_module_enable(struct module *mod)
57765784
struct ftrace_page *pg;
57775785

57785786
mutex_lock(&ftrace_lock);
5787+
mutex_lock(&text_mutex);
57795788

57805789
if (ftrace_disabled)
57815790
goto out_unlock;
@@ -5837,6 +5846,7 @@ void ftrace_module_enable(struct module *mod)
58375846
ftrace_arch_code_modify_post_process();
58385847

58395848
out_unlock:
5849+
mutex_unlock(&text_mutex);
58405850
mutex_unlock(&ftrace_lock);
58415851

58425852
process_cached_mods(mod->name);

‎kernel/trace/trace.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6923,7 +6923,7 @@ struct tracing_log_err {
69236923

69246924
static DEFINE_MUTEX(tracing_err_log_lock);
69256925

6926-
struct tracing_log_err *get_tracing_log_err(struct trace_array *tr)
6926+
static struct tracing_log_err *get_tracing_log_err(struct trace_array *tr)
69276927
{
69286928
struct tracing_log_err *err;
69296929

@@ -8192,7 +8192,7 @@ static const struct file_operations buffer_percent_fops = {
81928192
.llseek = default_llseek,
81938193
};
81948194

8195-
struct dentry *trace_instance_dir;
8195+
static struct dentry *trace_instance_dir;
81968196

81978197
static void
81988198
init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer);

‎kernel/trace/trace_output.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ static enum print_line_t trace_stack_print(struct trace_iterator *iter,
10571057

10581058
trace_seq_puts(s, "<stack trace>\n");
10591059

1060-
for (p = field->caller; p && *p != ULONG_MAX && p < end; p++) {
1060+
for (p = field->caller; p && p < end && *p != ULONG_MAX; p++) {
10611061

10621062
if (trace_seq_has_overflowed(s))
10631063
break;

‎kernel/trace/trace_uprobe.c‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,6 @@ static int register_trace_uprobe(struct trace_uprobe *tu)
426426
/*
427427
* Argument syntax:
428428
* - Add uprobe: p|r[:[GRP/]EVENT] PATH:OFFSET [FETCHARGS]
429-
*
430-
* - Remove uprobe: -:[GRP/]EVENT
431429
*/
432430
static int trace_uprobe_create(int argc, const char **argv)
433431
{
@@ -443,10 +441,17 @@ static int trace_uprobe_create(int argc, const char **argv)
443441
ret = 0;
444442
ref_ctr_offset = 0;
445443

446-
/* argc must be >= 1 */
447-
if (argv[0][0] == 'r')
444+
switch (argv[0][0]) {
445+
case 'r':
448446
is_return = true;
449-
else if (argv[0][0] != 'p' || argc < 2)
447+
break;
448+
case 'p':
449+
break;
450+
default:
451+
return -ECANCELED;
452+
}
453+
454+
if (argc < 2)
450455
return -ECANCELED;
451456

452457
if (argv[0][1] == ':')

0 commit comments

Comments
 (0)