Skip to content

Commit aa2e3ac

Browse files
committed
Merge tag 'trace-v5.1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull tracing fixes and cleanups from Steven Rostedt: "This contains a series of last minute clean ups, small fixes and error checks" * tag 'trace-v5.1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: tracing/probe: Verify alloc_trace_*probe() result tracing/probe: Check event/group naming rule at parsing tracing/probe: Check the size of argument name and body tracing/probe: Check event name length correctly tracing/probe: Check maxactive error cases tracing: kdb: Fix ftdump to not sleep trace/probes: Remove kernel doc style from non kernel doc comment tracing/probes: Make reserved_field_names static
2 parents 323ea40 + a039480 commit aa2e3ac

File tree

8 files changed

+45
-26
lines changed

8 files changed

+45
-26
lines changed

include/linux/ring_buffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts,
128128
unsigned long *lost_events);
129129

130130
struct ring_buffer_iter *
131-
ring_buffer_read_prepare(struct ring_buffer *buffer, int cpu);
131+
ring_buffer_read_prepare(struct ring_buffer *buffer, int cpu, gfp_t flags);
132132
void ring_buffer_read_prepare_sync(void);
133133
void ring_buffer_read_start(struct ring_buffer_iter *iter);
134134
void ring_buffer_read_finish(struct ring_buffer_iter *iter);

kernel/trace/ring_buffer.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4191,6 +4191,7 @@ EXPORT_SYMBOL_GPL(ring_buffer_consume);
41914191
* ring_buffer_read_prepare - Prepare for a non consuming read of the buffer
41924192
* @buffer: The ring buffer to read from
41934193
* @cpu: The cpu buffer to iterate over
4194+
* @flags: gfp flags to use for memory allocation
41944195
*
41954196
* This performs the initial preparations necessary to iterate
41964197
* through the buffer. Memory is allocated, buffer recording
@@ -4208,15 +4209,15 @@ EXPORT_SYMBOL_GPL(ring_buffer_consume);
42084209
* This overall must be paired with ring_buffer_read_finish.
42094210
*/
42104211
struct ring_buffer_iter *
4211-
ring_buffer_read_prepare(struct ring_buffer *buffer, int cpu)
4212+
ring_buffer_read_prepare(struct ring_buffer *buffer, int cpu, gfp_t flags)
42124213
{
42134214
struct ring_buffer_per_cpu *cpu_buffer;
42144215
struct ring_buffer_iter *iter;
42154216

42164217
if (!cpumask_test_cpu(cpu, buffer->cpumask))
42174218
return NULL;
42184219

4219-
iter = kmalloc(sizeof(*iter), GFP_KERNEL);
4220+
iter = kmalloc(sizeof(*iter), flags);
42204221
if (!iter)
42214222
return NULL;
42224223

kernel/trace/trace.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4079,7 +4079,8 @@ __tracing_open(struct inode *inode, struct file *file, bool snapshot)
40794079
if (iter->cpu_file == RING_BUFFER_ALL_CPUS) {
40804080
for_each_tracing_cpu(cpu) {
40814081
iter->buffer_iter[cpu] =
4082-
ring_buffer_read_prepare(iter->trace_buffer->buffer, cpu);
4082+
ring_buffer_read_prepare(iter->trace_buffer->buffer,
4083+
cpu, GFP_KERNEL);
40834084
}
40844085
ring_buffer_read_prepare_sync();
40854086
for_each_tracing_cpu(cpu) {
@@ -4089,7 +4090,8 @@ __tracing_open(struct inode *inode, struct file *file, bool snapshot)
40894090
} else {
40904091
cpu = iter->cpu_file;
40914092
iter->buffer_iter[cpu] =
4092-
ring_buffer_read_prepare(iter->trace_buffer->buffer, cpu);
4093+
ring_buffer_read_prepare(iter->trace_buffer->buffer,
4094+
cpu, GFP_KERNEL);
40934095
ring_buffer_read_prepare_sync();
40944096
ring_buffer_read_start(iter->buffer_iter[cpu]);
40954097
tracing_iter_reset(iter, cpu);

kernel/trace/trace_kdb.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,16 @@ static void ftrace_dump_buf(int skip_lines, long cpu_file)
5151
if (cpu_file == RING_BUFFER_ALL_CPUS) {
5252
for_each_tracing_cpu(cpu) {
5353
iter.buffer_iter[cpu] =
54-
ring_buffer_read_prepare(iter.trace_buffer->buffer, cpu);
54+
ring_buffer_read_prepare(iter.trace_buffer->buffer,
55+
cpu, GFP_ATOMIC);
5556
ring_buffer_read_start(iter.buffer_iter[cpu]);
5657
tracing_iter_reset(&iter, cpu);
5758
}
5859
} else {
5960
iter.cpu_file = cpu_file;
6061
iter.buffer_iter[cpu_file] =
61-
ring_buffer_read_prepare(iter.trace_buffer->buffer, cpu_file);
62+
ring_buffer_read_prepare(iter.trace_buffer->buffer,
63+
cpu_file, GFP_ATOMIC);
6264
ring_buffer_read_start(iter.buffer_iter[cpu_file]);
6365
tracing_iter_reset(&iter, cpu_file);
6466
}

kernel/trace/trace_kprobe.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static struct dyn_event_operations trace_kprobe_ops = {
3535
.match = trace_kprobe_match,
3636
};
3737

38-
/**
38+
/*
3939
* Kprobe event core functions
4040
*/
4141
struct trace_kprobe {
@@ -221,7 +221,7 @@ static struct trace_kprobe *alloc_trace_kprobe(const char *group,
221221

222222
tk->rp.maxactive = maxactive;
223223

224-
if (!event || !is_good_name(event)) {
224+
if (!event || !group) {
225225
ret = -EINVAL;
226226
goto error;
227227
}
@@ -231,11 +231,6 @@ static struct trace_kprobe *alloc_trace_kprobe(const char *group,
231231
if (!tk->tp.call.name)
232232
goto error;
233233

234-
if (!group || !is_good_name(group)) {
235-
ret = -EINVAL;
236-
goto error;
237-
}
238-
239234
tk->tp.class.system = kstrdup(group, GFP_KERNEL);
240235
if (!tk->tp.class.system)
241236
goto error;
@@ -624,7 +619,11 @@ static int trace_kprobe_create(int argc, const char *argv[])
624619
if (event)
625620
event++;
626621

627-
if (is_return && isdigit(argv[0][1])) {
622+
if (isdigit(argv[0][1])) {
623+
if (!is_return) {
624+
pr_info("Maxactive is not for kprobe");
625+
return -EINVAL;
626+
}
628627
if (event)
629628
len = event - &argv[0][1] - 1;
630629
else
@@ -634,8 +633,8 @@ static int trace_kprobe_create(int argc, const char *argv[])
634633
memcpy(buf, &argv[0][1], len);
635634
buf[len] = '\0';
636635
ret = kstrtouint(buf, 0, &maxactive);
637-
if (ret) {
638-
pr_info("Failed to parse maxactive.\n");
636+
if (ret || !maxactive) {
637+
pr_info("Invalid maxactive number\n");
639638
return ret;
640639
}
641640
/* kretprobes instances are iterated over via a list. The
@@ -694,9 +693,9 @@ static int trace_kprobe_create(int argc, const char *argv[])
694693
tk = alloc_trace_kprobe(group, event, addr, symbol, offset, maxactive,
695694
argc, is_return);
696695
if (IS_ERR(tk)) {
697-
pr_info("Failed to allocate trace_probe.(%d)\n",
698-
(int)PTR_ERR(tk));
699696
ret = PTR_ERR(tk);
697+
/* This must return -ENOMEM otherwise there is a bug */
698+
WARN_ON_ONCE(ret != -ENOMEM);
700699
goto out;
701700
}
702701

kernel/trace/trace_probe.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#include "trace_probe.h"
1515

16-
const char *reserved_field_names[] = {
16+
static const char *reserved_field_names[] = {
1717
"common_type",
1818
"common_flags",
1919
"common_preempt_count",
@@ -159,6 +159,7 @@ int traceprobe_parse_event_name(const char **pevent, const char **pgroup,
159159
char *buf)
160160
{
161161
const char *slash, *event = *pevent;
162+
int len;
162163

163164
slash = strchr(event, '/');
164165
if (slash) {
@@ -171,12 +172,25 @@ int traceprobe_parse_event_name(const char **pevent, const char **pgroup,
171172
return -E2BIG;
172173
}
173174
strlcpy(buf, event, slash - event + 1);
175+
if (!is_good_name(buf)) {
176+
pr_info("Group name must follow the same rules as C identifiers\n");
177+
return -EINVAL;
178+
}
174179
*pgroup = buf;
175180
*pevent = slash + 1;
181+
event = *pevent;
176182
}
177-
if (strlen(event) == 0) {
183+
len = strlen(event);
184+
if (len == 0) {
178185
pr_info("Event name is not specified\n");
179186
return -EINVAL;
187+
} else if (len > MAX_EVENT_NAME_LEN) {
188+
pr_info("Event name is too long\n");
189+
return -E2BIG;
190+
}
191+
if (!is_good_name(event)) {
192+
pr_info("Event name must follow the same rules as C identifiers\n");
193+
return -EINVAL;
180194
}
181195
return 0;
182196
}
@@ -548,6 +562,8 @@ int traceprobe_parse_probe_arg(struct trace_probe *tp, int i, char *arg,
548562

549563
body = strchr(arg, '=');
550564
if (body) {
565+
if (body - arg > MAX_ARG_NAME_LEN || body == arg)
566+
return -EINVAL;
551567
parg->name = kmemdup_nul(arg, body - arg, GFP_KERNEL);
552568
body++;
553569
} else {

kernel/trace/trace_probe.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#define MAX_TRACE_ARGS 128
3333
#define MAX_ARGSTR_LEN 63
3434
#define MAX_ARRAY_LEN 64
35+
#define MAX_ARG_NAME_LEN 32
3536
#define MAX_STRING_SIZE PATH_MAX
3637

3738
/* Reserved field names */

kernel/trace/trace_uprobe.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,7 @@ alloc_trace_uprobe(const char *group, const char *event, int nargs, bool is_ret)
273273
{
274274
struct trace_uprobe *tu;
275275

276-
if (!event || !is_good_name(event))
277-
return ERR_PTR(-EINVAL);
278-
279-
if (!group || !is_good_name(group))
276+
if (!event || !group)
280277
return ERR_PTR(-EINVAL);
281278

282279
tu = kzalloc(SIZEOF_TRACE_UPROBE(nargs), GFP_KERNEL);
@@ -524,8 +521,9 @@ static int trace_uprobe_create(int argc, const char **argv)
524521

525522
tu = alloc_trace_uprobe(group, event, argc, is_return);
526523
if (IS_ERR(tu)) {
527-
pr_info("Failed to allocate trace_uprobe.(%d)\n", (int)PTR_ERR(tu));
528524
ret = PTR_ERR(tu);
525+
/* This must return -ENOMEM otherwise there is a bug */
526+
WARN_ON_ONCE(ret != -ENOMEM);
529527
goto fail_address_parse;
530528
}
531529
tu->offset = offset;

0 commit comments

Comments
 (0)