Skip to content

Commit 2391f20

Browse files
ArnaudLcmKernel Patches Daemon
authored andcommitted
bpf: clean-up bounds checking in __bpf_get_stack
Clean-up bounds checking for trace->nr in __bpf_get_stack by limiting it only to max_depth. Signed-off-by: Arnaud Lecomte <[email protected]> Acked-by: Song Liu <[email protected]> Cc: Song Liu <[email protected]>
1 parent 448eb55 commit 2391f20

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

kernel/bpf/stackmap.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,13 +462,15 @@ static long __bpf_get_stack(struct pt_regs *regs, struct task_struct *task,
462462
if (may_fault)
463463
rcu_read_lock(); /* need RCU for perf's callchain below */
464464

465-
if (trace_in)
465+
if (trace_in) {
466466
trace = trace_in;
467-
else if (kernel && task)
467+
trace->nr = min_t(u32, trace->nr, max_depth);
468+
} else if (kernel && task) {
468469
trace = get_callchain_entry_for_task(task, max_depth);
469-
else
470+
} else {
470471
trace = get_perf_callchain(regs, 0, kernel, user, max_depth,
471472
crosstask, false);
473+
}
472474

473475
if (unlikely(!trace) || trace->nr < skip) {
474476
if (may_fault)
@@ -477,7 +479,6 @@ static long __bpf_get_stack(struct pt_regs *regs, struct task_struct *task,
477479
}
478480

479481
trace_nr = trace->nr - skip;
480-
trace_nr = (trace_nr <= num_elem) ? trace_nr : num_elem;
481482
copy_len = trace_nr * elem_size;
482483

483484
ips = trace->ip + skip;

0 commit comments

Comments
 (0)